diff options
Diffstat (limited to 'app/src/main/kotlin')
17 files changed, 148 insertions, 47 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/BaseActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/BaseActivity.kt new file mode 100644 index 00000000..6c638618 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/BaseActivity.kt @@ -0,0 +1,24 @@ +package com.pitchedapps.frost + +import android.support.v7.app.AppCompatActivity +import com.pitchedapps.frost.utils.Prefs +import com.pitchedapps.frost.utils.materialDialog + +/** + * Created by Allan Wang on 2017-06-12. + */ +open class BaseActivity : AppCompatActivity() { + override fun onBackPressed() { + if (isTaskRoot && Prefs.exitConfirmation) { + materialDialog { + title(R.string.exit) + content(R.string.exit_confirmation) + positiveText(android.R.string.yes) + negativeText(android.R.string.no) + onPositive { _, _ -> super.onBackPressed() } + checkBoxPromptRes(R.string.do_not_show_again, false, { _, b -> Prefs.exitConfirmation = !b }) + show() + } + } else super.onBackPressed() + } +}
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt index b5f8c9cb..85d1c8b5 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt @@ -17,8 +17,6 @@ import com.pitchedapps.frost.utils.CrashReportingTree import com.pitchedapps.frost.utils.Prefs import com.raizlabs.android.dbflow.config.FlowConfig import com.raizlabs.android.dbflow.config.FlowManager -import com.squareup.leakcanary.LeakCanary -import com.squareup.leakcanary.RefWatcher import io.fabric.sdk.android.Fabric import timber.log.Timber import timber.log.Timber.DebugTree diff --git a/app/src/main/kotlin/com/pitchedapps/frost/LoginActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/LoginActivity.kt index a9746d6f..9ba83879 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/LoginActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/LoginActivity.kt @@ -4,11 +4,10 @@ import android.graphics.drawable.Drawable import android.os.Bundle import android.os.Handler import android.support.v4.widget.SwipeRefreshLayout -import android.support.v7.app.AppCompatActivity import android.support.v7.widget.AppCompatTextView import android.support.v7.widget.Toolbar import android.widget.ImageView -import butterknife.ButterKnife +import ca.allanwang.kau.utils.bindView import com.bumptech.glide.Glide import com.bumptech.glide.load.DataSource import com.bumptech.glide.load.engine.GlideException @@ -21,7 +20,6 @@ import com.pitchedapps.frost.facebook.FACEBOOK_COM import com.pitchedapps.frost.facebook.FbTab import com.pitchedapps.frost.facebook.PROFILE_PICTURE_URL import com.pitchedapps.frost.utils.L -import ca.allanwang.kau.utils.bindView import com.pitchedapps.frost.utils.launchNewTask import com.pitchedapps.frost.views.fadeIn import com.pitchedapps.frost.views.fadeOut @@ -40,7 +38,7 @@ import kotlin.concurrent.thread /** * Created by Allan Wang on 2017-06-01. */ -class LoginActivity : AppCompatActivity() { +class LoginActivity : BaseActivity() { val toolbar: Toolbar by bindView(R.id.toolbar) val web: LoginWebView by bindView(R.id.login_webview) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt index 05ee2e50..12b308d0 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt @@ -1,6 +1,7 @@ package com.pitchedapps.frost import android.content.Intent +import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.support.design.widget.FloatingActionButton import android.support.design.widget.Snackbar @@ -8,15 +9,11 @@ import android.support.design.widget.TabLayout import android.support.v4.app.FragmentManager import android.support.v4.app.FragmentPagerAdapter import android.support.v4.view.ViewPager -import android.support.v7.app.AppCompatActivity import android.support.v7.widget.Toolbar import android.view.Menu import android.view.MenuItem import android.view.ViewTreeObserver -import ca.allanwang.kau.utils.bindView -import ca.allanwang.kau.utils.restart -import ca.allanwang.kau.utils.showChangelog -import ca.allanwang.kau.utils.toDrawable +import ca.allanwang.kau.utils.* import co.zsmb.materialdrawerkt.builders.Builder import co.zsmb.materialdrawerkt.builders.accountHeader import co.zsmb.materialdrawerkt.builders.drawer @@ -40,7 +37,7 @@ import com.pitchedapps.frost.utils.launchWebOverlay import io.reactivex.disposables.Disposable import io.reactivex.subjects.PublishSubject -class MainActivity : AppCompatActivity() { +class MainActivity : BaseActivity() { lateinit var adapter: SectionsPagerAdapter val toolbar: Toolbar by bindView(R.id.toolbar) @@ -113,19 +110,27 @@ class MainActivity : AppCompatActivity() { toolbar = this@MainActivity.toolbar savedInstance = savedInstanceState translucentStatusBar = false + sliderBackgroundColor = Prefs.bgColor.withMinAlpha(200).toLong() drawerHeader = accountHeader { + textColor = Prefs.textColor.toLong() + backgroundDrawable = ColorDrawable(Prefs.headerColor) cookies().forEach { (id, name) -> profile(name = name ?: "") { iconUrl = PROFILE_PICTURE_URL(id) + textColor = Prefs.textColor.toLong() + selectedTextColor = Prefs.textColor.toLong() identifier = id } } - profileSetting(nameRes = R.string.add_account, descriptionRes = R.string.add_account_desc) { - iconDrawable = IconicsDrawable(this@MainActivity, GoogleMaterial.Icon.gmd_add).actionBar().paddingDp(5).colorRes(R.color.material_drawer_primary_text) + profileSetting(nameRes = R.string.add_account) { + iconDrawable = IconicsDrawable(this@MainActivity, GoogleMaterial.Icon.gmd_add).actionBar().paddingDp(5).color(Prefs.textColor) + textColor = Prefs.textColor.toLong() identifier = -2L } profileSetting(nameRes = R.string.manage_account) { iicon = GoogleMaterial.Icon.gmd_settings + iconColor = Prefs.textColor.toLong() + textColor = Prefs.textColor.toLong() identifier = -3L } onProfileChanged { _, profile, current -> @@ -147,6 +152,11 @@ class MainActivity : AppCompatActivity() { fun Builder.primaryItem(item: FbTab) = this.primaryItem(item.titleId) { iicon = item.icon + iconColor = Prefs.textColor.toLong() + textColor = Prefs.textColor.toLong() + selectedIconColor = Prefs.textColor.toLong() + selectedTextColor = Prefs.textColor.toLong() + selectedColor = 0x00000001.toLong() identifier = item.titleId.toLong() onClick { _ -> launchWebOverlay(item.url) @@ -187,7 +197,7 @@ class MainActivity : AppCompatActivity() { inner class SectionsPagerAdapter(fm: FragmentManager, val pages: List<FbTab>) : FragmentPagerAdapter(fm) { - override fun getItem(position: Int) = WebFragment(pages[position].url) + override fun getItem(position: Int) = WebFragment(pages[position]) override fun getCount() = pages.size diff --git a/app/src/main/kotlin/com/pitchedapps/frost/SelectorActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/SelectorActivity.kt index 57d0ff4d..082d7887 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/SelectorActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/SelectorActivity.kt @@ -1,15 +1,14 @@ package com.pitchedapps.frost import android.os.Bundle -import android.support.v7.app.AppCompatActivity import android.support.v7.widget.GridLayoutManager import android.support.v7.widget.RecyclerView import android.view.View +import ca.allanwang.kau.utils.bindView import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter import com.mikepenz.fastadapter.listeners.ClickEventHook import com.pitchedapps.frost.facebook.FbCookie -import ca.allanwang.kau.utils.bindView import com.pitchedapps.frost.utils.cookies import com.pitchedapps.frost.utils.launchNewTask import com.pitchedapps.frost.views.AccountItem @@ -17,7 +16,7 @@ import com.pitchedapps.frost.views.AccountItem /** * Created by Allan Wang on 2017-06-04. */ -class SelectorActivity : AppCompatActivity() { +class SelectorActivity : BaseActivity() { val recycler: RecyclerView by bindView(R.id.selector_recycler) val adapter = FastItemAdapter<AccountItem>() diff --git a/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt index 1968d07e..70e86239 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt @@ -3,10 +3,8 @@ package com.pitchedapps.frost import android.os.Bundle import android.support.v7.app.AppCompatActivity import android.support.v7.widget.Toolbar -import butterknife.ButterKnife import ca.allanwang.kau.utils.bindView import com.jude.swipbackhelper.SwipeBackHelper -import ca.allanwang.kau.utils.bindView import com.pitchedapps.frost.utils.url import com.pitchedapps.frost.web.FrostWebView @@ -26,7 +24,7 @@ class WebOverlayActivity : AppCompatActivity() { supportActionBar?.setDisplayShowHomeEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true) toolbar.setNavigationOnClickListener { onBackPressed() } - frostWeb.baseUrl = url() + frostWeb.web.baseUrl = url() frostWeb.web.loadBaseUrl() SwipeBackHelper.onCreate(this) SwipeBackHelper.getCurrentPage(this) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbTab.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbTab.kt index 17dd4862..c3bad56c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbTab.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbTab.kt @@ -6,8 +6,9 @@ import com.mikepenz.google_material_typeface_library.GoogleMaterial import com.mikepenz.iconics.typeface.IIcon import com.mikepenz.material_design_iconic_typeface_library.MaterialDesignIconic import com.pitchedapps.frost.R +import com.pitchedapps.frost.injectors.JsAssets -enum class FbTab(@StringRes val titleId: Int, val icon: IIcon, relativeUrl: String) { +enum class FbTab(@StringRes val titleId: Int, val icon: IIcon, relativeUrl: String, val javascript: JsAssets? = null) { FEED(R.string.feed, CommunityMaterial.Icon.cmd_newspaper, ""), FEED_MOST_RECENT(R.string.most_recent, GoogleMaterial.Icon.gmd_grade, "/?sk=h_chr"), FEED_TOP_STORIES(R.string.top_stories, GoogleMaterial.Icon.gmd_star, "/?sk=h_nor"), @@ -23,10 +24,12 @@ enum class FbTab(@StringRes val titleId: Int, val icon: IIcon, relativeUrl: Stri BIRTHDAYS(R.string.birthdays, GoogleMaterial.Icon.gmd_cake, "events/birthdays"), CHAT(R.string.chat, GoogleMaterial.Icon.gmd_chat, "buddylist"), PHOTOS(R.string.photos, GoogleMaterial.Icon.gmd_photo, "me/photos"), + SETTINGS(R.string.settings, GoogleMaterial.Icon.gmd_settings, "settings"), + MENU(R.string.menu, GoogleMaterial.Icon.gmd_menu, "settings", JsAssets.MENU) ; val url = "$FB_URL_BASE$relativeUrl" } -fun defaultTabs(): List<FbTab> = listOf(FbTab.FEED, FbTab.MESSAGES, FbTab.FRIENDS, FbTab.NOTIFICATIONS) +fun defaultTabs(): List<FbTab> = listOf(FbTab.FEED, FbTab.MESSAGES, FbTab.NOTIFICATIONS, FbTab.MENU) fun defaultDrawers(): List<FbTab> = listOf(FbTab.ACTIVITY_LOG, FbTab.PAGES, FbTab.GROUPS, FbTab.SAVED)
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt index 40f37189..0f56592c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragment.kt @@ -9,6 +9,8 @@ import android.view.View import android.view.ViewGroup import ca.allanwang.kau.utils.withBundle import com.pitchedapps.frost.MainActivity +import com.pitchedapps.frost.facebook.FbTab +import com.pitchedapps.frost.injectors.JsAssets import com.pitchedapps.frost.web.FrostWebView import com.pitchedapps.frost.web.FrostWebViewCore import io.reactivex.android.schedulers.AndroidSchedulers @@ -23,14 +25,21 @@ class WebFragment : Fragment() { companion object { private const val ARG_URL = "arg_url" + private const val ARG_ID = "arg_id" operator fun invoke(url: String) = WebFragment().withBundle { putString(ARG_URL, url) } + + operator fun invoke(data: FbTab) = WebFragment().withBundle { + putString(ARG_URL, data.url) + if (data.javascript != null) putSerializable(ARG_ID, data.javascript) + } } // val refresh: SwipeRefreshLayout by lazy { frostWebView.refresh } val web: FrostWebViewCore by lazy { frostWebView.web } lateinit var url: String + var baseJavascript: JsAssets? = null lateinit private var frostWebView: FrostWebView private var firstLoad = true private var refreshDisposable: Disposable? = null @@ -38,12 +47,14 @@ class WebFragment : Fragment() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) url = arguments.getString(ARG_URL) + baseJavascript = arguments.getSerializable(ARG_ID) as? JsAssets } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { super.onCreateView(inflater, container, savedInstanceState) frostWebView = FrostWebView(context) - frostWebView.baseUrl = url + frostWebView.web.baseUrl = url + frostWebView.web.baseJavascript = baseJavascript return frostWebView } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAssets.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAssets.kt index 336ffc71..ad257276 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAssets.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAssets.kt @@ -18,7 +18,7 @@ enum class CssAssets { fun inject(webView: WebView, callback: ((String) -> Unit)?) { if (injector == null) { - val content = webView.context.assets.open("core/$file").bufferedReader().use { it.readText() } + val content = webView.context.assets.open("css/core/$file").bufferedReader().use { it.readText() } injector = JsBuilder().css(content).build() } injector!!.inject(webView, callback) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt new file mode 100644 index 00000000..2bf53d2e --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt @@ -0,0 +1,32 @@ +package com.pitchedapps.frost.injectors + +import android.webkit.WebView +import com.pitchedapps.frost.utils.L + +/** + * Created by Allan Wang on 2017-05-31. + * Mapping of the available assets + * The enum name must match the css file name + * //TODO add folder mapping using Prefs + */ +enum class JsAssets { + MENU + ; + + var file = "${name.toLowerCase()}.min.js" + var injector: JsInjector? = null + + fun inject(webView: WebView, callback: ((String) -> Unit)?) { + if (injector == null) { + val content = webView.context.assets.open("js/$file").bufferedReader().use { it.readText() } + injector = JsBuilder().js(content).build() + } + injector!!.inject(webView, callback) + L.v("JS ${injector!!.function}") + } + + fun reset() { + injector = null + } + +}
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt index bda9ae16..14e0606b 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt @@ -3,13 +3,19 @@ package com.pitchedapps.frost.injectors import android.webkit.WebView class JsBuilder { - private val css: StringBuilder by lazy { StringBuilder() } + private val css = StringBuilder() + private val js = StringBuilder() fun css(css: String): JsBuilder { this.css.append(css) return this } + fun js(content: String): JsBuilder { + this.js.append(content) + return this + } + fun build() = JsInjector(toString()) override fun toString(): String { @@ -18,6 +24,8 @@ class JsBuilder { val cssMin = css.replace(Regex("\\s+"), "") builder.append("var a=document.createElement('style');a.innerHTML='$cssMin';document.head.appendChild(a);") } + if (js.isNotBlank()) + builder.append(js) return builder.append("}()").toString() } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/ContextUtils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/ContextUtils.kt index e601283c..1569532c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/ContextUtils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/ContextUtils.kt @@ -5,7 +5,10 @@ import android.content.Context import android.content.Intent import android.support.v4.app.ActivityOptionsCompat import android.support.v4.content.ContextCompat +import ca.allanwang.kau.utils.adjustAlpha +import ca.allanwang.kau.utils.lighten import ca.allanwang.kau.utils.startActivity +import com.afollestad.materialdialogs.MaterialDialog import com.pitchedapps.frost.LoginActivity import com.pitchedapps.frost.R import com.pitchedapps.frost.WebOverlayActivity @@ -38,4 +41,17 @@ fun Context.launchWebOverlay(url: String) { fun WebOverlayActivity.url(): String { return intent.extras?.getString(ARG_URL) ?: FbTab.FEED.url +} + +fun Activity.materialDialog(action: MaterialDialog.Builder.() -> Unit) { + val builder = MaterialDialog.Builder(this) + val dimmerTextColor = Prefs.textColor.adjustAlpha(0.8f) + builder.titleColor(Prefs.textColor) + .contentColor(dimmerTextColor) + .widgetColor(dimmerTextColor) + .backgroundColor(Prefs.bgColor.lighten(0.1f)) + .positiveColor(Prefs.textColor) + .negativeColor(Prefs.textColor) + .neutralColor(Prefs.textColor) + builder.action() }
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt index 89cccd40..6284a2f8 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt @@ -23,4 +23,5 @@ object Prefs : KPref() { var iconColor: Int by kpref("color_icons", Color.WHITE) + var exitConfirmation: Boolean by kpref("exit_confirmation", true) } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt index 7ad12c3a..720026e6 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt @@ -13,7 +13,7 @@ import io.reactivex.subjects.Subject class FrostChromeClient(val progressObservable: Subject<Int>, val titleObservable: BehaviorSubject<String>) : WebChromeClient() { override fun onConsoleMessage(consoleMessage: ConsoleMessage): Boolean { - L.v("Chrome Console ${consoleMessage.lineNumber()}: ${consoleMessage.message()}") + L.i("Chrome Console ${consoleMessage.lineNumber()}: ${consoleMessage.message()}") return super.onConsoleMessage(consoleMessage) } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt index d4bf8e07..4554e0a4 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt @@ -7,9 +7,9 @@ import android.util.AttributeSet import android.view.View import android.widget.FrameLayout import android.widget.ProgressBar -import butterknife.ButterKnife -import com.pitchedapps.frost.R import ca.allanwang.kau.utils.bindView +import com.pitchedapps.frost.R +import com.pitchedapps.frost.facebook.FbTab import io.reactivex.android.schedulers.AndroidSchedulers /** @@ -17,11 +17,6 @@ import io.reactivex.android.schedulers.AndroidSchedulers */ class FrostWebView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0) : FrameLayout(context, attrs, defStyleAttr, defStyleRes), SwipeRefreshLayout.OnRefreshListener { - var baseUrl: String? - get() = web.baseUrl - set(value) { - web.baseUrl = value - } val refresh: SwipeRefreshLayout by bindView(R.id.swipe_refresh) val web: FrostWebViewCore by bindView(R.id.frost_webview_core) val progress: ProgressBar by bindView(R.id.progressBar) @@ -46,8 +41,12 @@ class FrostWebView @JvmOverloads constructor(context: Context, attrs: AttributeS }) } + //Some urls have javascript injections so make sure we load the base url override fun onRefresh() { - web.reload() + when (web.baseUrl) { + FbTab.MENU.url -> web.loadBaseUrl() + else -> web.reload() + } } fun onBackPressed(): Boolean { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt index 922d527b..28048a1d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt @@ -24,15 +24,6 @@ import io.reactivex.subjects.Subject */ class FrostWebViewClient(val refreshObservable: Subject<Boolean>) : WebViewClient() { - companion object { - //Collections of jewels mapped with url match -> id - val jewelMap: Map<String, String> = mapOf("a" to "b") - - fun test() { - - } - } - override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) { super.onPageStarted(view, url, favicon) L.i("FWV Loading $url") @@ -55,6 +46,15 @@ class FrostWebViewClient(val refreshObservable: Subject<Boolean>) : WebViewClien super.onPageFinished(view, url) refreshObservable.onNext(false) if (!url.contains(FACEBOOK_COM)) return + L.i("Page finished $url") + with(view as FrostWebViewCore) { + if (url == view.baseUrl && view.baseJavascript != null) { + L.i("Base inject ${view.baseJavascript!!.name}") + view.baseJavascript!!.inject(view, { + L.i("Base injection done") + }) + } + } JsActions.LOGIN_CHECK.inject(view) CssAssets.HEADER.inject(view, { view.circularReveal(offset = 150L) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt index 1d3f348a..f0596f7c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt @@ -12,6 +12,7 @@ import android.view.View import android.view.animation.DecelerateInterpolator import android.webkit.WebView import com.pitchedapps.frost.facebook.USER_AGENT_BASIC +import com.pitchedapps.frost.injectors.JsAssets import io.reactivex.Scheduler import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable @@ -38,6 +39,7 @@ class FrostWebViewCore @JvmOverloads constructor( val titleObservable: BehaviorSubject<String> // Only emits on different non http titles var baseUrl: String? = null + var baseJavascript: JsAssets? = null init { isNestedScrollingEnabled = true @@ -53,8 +55,8 @@ class FrostWebViewCore @JvmOverloads constructor( settings.userAgentString = USER_AGENT_BASIC // settings.domStorageEnabled = true setLayerType(View.LAYER_TYPE_HARDWARE, null) - setWebViewClient(FrostWebViewClient(refreshObservable)) - setWebChromeClient(FrostChromeClient(progressObservable, titleObservable)) + webViewClient = FrostWebViewClient(refreshObservable) + webChromeClient = FrostChromeClient(progressObservable, titleObservable) addJavascriptInterface(FrostJSI(context), "Frost") } @@ -63,7 +65,9 @@ class FrostWebViewCore @JvmOverloads constructor( super.loadUrl(url) } - fun loadBaseUrl() = loadUrl(baseUrl) + fun loadBaseUrl() { + loadUrl(baseUrl) + } fun addTitleListener(subscriber: (title: String) -> Unit, scheduler: Scheduler = AndroidSchedulers.mainThread()): Disposable = titleObservable.observeOn(scheduler).subscribe(subscriber) |