diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web')
4 files changed, 35 insertions, 29 deletions
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 720026e6..74dafd41 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt @@ -10,7 +10,10 @@ import io.reactivex.subjects.Subject /** * Created by Allan Wang on 2017-05-31. */ -class FrostChromeClient(val progressObservable: Subject<Int>, val titleObservable: BehaviorSubject<String>) : WebChromeClient() { +class FrostChromeClient(webCore: FrostWebViewCore) : WebChromeClient() { + + val progressObservable: Subject<Int> = webCore.progressObservable + val titleObservable: BehaviorSubject<String> = webCore.titleObservable override fun onConsoleMessage(consoleMessage: ConsoleMessage): Boolean { L.i("Chrome Console ${consoleMessage.lineNumber()}: ${consoleMessage.message()}") 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 e4ff4e10..07b9a949 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt @@ -22,12 +22,14 @@ import io.reactivex.subjects.Subject /** * Created by Allan Wang on 2017-05-31. */ -open class FrostWebViewClient(val refreshObservable: Subject<Boolean>) : WebViewClient() { +open class FrostWebViewClient(val webCore: FrostWebViewCore) : WebViewClient() { + + val refreshObservable: Subject<Boolean> = webCore.refreshObservable override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) { super.onPageStarted(view, url, favicon) L.i("FWV Loading $url") - L.v("Cookies ${CookieManager.getInstance().getCookie(url)}") +// L.v("Cookies ${CookieManager.getInstance().getCookie(url)}") refreshObservable.onNext(true) if (!url.contains(FACEBOOK_COM)) return if (url.contains("logout.php")) FbCookie.logout(Prefs.userId, { launchLogin(view.context) }) @@ -49,16 +51,16 @@ open class FrostWebViewClient(val refreshObservable: Subject<Boolean>) : WebView } L.i("Page finished $url") JsActions.LOGIN_CHECK.inject(view) - onPageFinishedActions(view as FrostWebViewCore, url) + onPageFinishedActions(url) } - open internal fun onPageFinishedActions(view: FrostWebViewCore, url: String?) { - onPageFinishedActions(view) + open internal fun onPageFinishedActions(url: String?) { + injectAndFinish() } - internal fun onPageFinishedActions(view: FrostWebViewCore) { + internal fun injectAndFinish() { L.d("Page finished reveal") - view.jsInject(CssHider.HEADER, + webCore.jsInject(CssHider.HEADER, Prefs.themeInjector, JsAssets.CLICK_INTERCEPTOR, callback = { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClientMenu.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClientMenu.kt index f299b840..9a00c563 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClientMenu.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClientMenu.kt @@ -9,10 +9,10 @@ import io.reactivex.subjects.Subject /** * Created by Allan Wang on 2017-05-31. */ -class FrostWebViewClientMenu(refreshObservable: Subject<Boolean>) : FrostWebViewClient(refreshObservable) { +class FrostWebViewClientMenu(webCore: FrostWebViewCore) : FrostWebViewClient(webCore) { var content: String? = null - var view: FrostWebViewCore? = null + val progressObservable: Subject<Int> = webCore.progressObservable override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) { super.onPageStarted(view, url, favicon) @@ -31,32 +31,30 @@ class FrostWebViewClientMenu(refreshObservable: Subject<Boolean>) : FrostWebView override fun onPageFinished(view: WebView, url: String) { super.onPageFinished(view, url) - with(view as FrostWebViewCore) { - if (url == view.baseUrl) { - this@FrostWebViewClientMenu.view = view - inject(JsAssets.MENU, view, { - inject(JsAssets.MENU_CLICK, view) //menu injection must be after or we will have a loop from the click listener - }) - } else { - inject(JsAssets.MENU_CLICK, view) - } + if (url == webCore.baseUrl) { + progressObservable.onNext(99) + inject(JsAssets.MENU, webCore, { + inject(JsAssets.MENU_CLICK, webCore) //menu injection must be after or we will have a loop from the click listener + }) + } else { + inject(JsAssets.MENU_CLICK, webCore) } } override fun emit(flag: Int) { super.emit(flag) - if (view != null) super.onPageFinishedActions(view!!) - view = null + progressObservable.onNext(100) + super.injectAndFinish() } - override fun onPageFinishedActions(view: FrostWebViewCore, url: String?) { + override fun onPageFinishedActions(url: String?) { when (url) { "https://m.facebook.com/settings", "https://m.facebook.com/settings#", "https://m.facebook.com/settings#!/settings?soft=bookmarks" -> { //do nothing; we will further inject before revealing } - else -> super.onPageFinishedActions(view) + else -> injectAndFinish() } } 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 86d88e47..5ba312f4 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt @@ -18,7 +18,6 @@ import ca.allanwang.kau.utils.fadeOut import ca.allanwang.kau.utils.isVisible import com.pitchedapps.frost.facebook.FbTab import com.pitchedapps.frost.facebook.USER_AGENT_BASIC -import com.pitchedapps.frost.utils.L import io.reactivex.Scheduler import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable @@ -27,9 +26,6 @@ import io.reactivex.subjects.BehaviorSubject /** * Created by Allan Wang on 2017-05-29. * - * Courtesy of takahirom - * - * https://github.com/takahirom/webview-in-coordinatorlayout/blob/master/app/src/main/java/com/github/takahirom/webview_in_coodinator_layout/NestedWebView.java */ class FrostWebViewCore @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 @@ -63,9 +59,9 @@ class FrostWebViewCore @JvmOverloads constructor( settings.userAgentString = USER_AGENT_BASIC // settings.domStorageEnabled = true setLayerType(View.LAYER_TYPE_HARDWARE, null) - frostWebClient = baseEnum?.webClient?.invoke(refreshObservable) ?: FrostWebViewClient(refreshObservable) + frostWebClient = baseEnum?.webClient?.invoke(this) ?: FrostWebViewClient(this) webViewClient = frostWebClient - webChromeClient = FrostChromeClient(progressObservable, titleObservable) + webChromeClient = FrostChromeClient(this) addJavascriptInterface(FrostJSI(context, this), "Frost") setBackgroundColor(Color.TRANSPARENT) } @@ -84,6 +80,7 @@ class FrostWebViewCore @JvmOverloads constructor( /** * Hook onto the refresh observable for one cycle * Note that this is a behaviour subject so the first 'false' emission should be ignored + * Animate toggles between the fancy ripple and the basic fade */ fun registerTransition(animate: Boolean) { var dispose: Disposable? = null @@ -107,6 +104,12 @@ class FrostWebViewCore @JvmOverloads constructor( fun addTitleListener(subscriber: (title: String) -> Unit, scheduler: Scheduler = AndroidSchedulers.mainThread()): Disposable = titleObservable.observeOn(scheduler).subscribe(subscriber) + /** + * Handle nested scrolling against SwipeRecyclerView + * Courtesy of takahirom + * + * https://github.com/takahirom/webview-in-coordinatorlayout/blob/master/app/src/main/java/com/github/takahirom/webview_in_coodinator_layout/NestedWebView.java + */ override fun onTouchEvent(ev: MotionEvent): Boolean { val event = MotionEvent.obtain(ev) val action = event.action |