aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/web
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-15 20:41:55 -0700
committerAllan Wang <me@allanwang.ca>2017-06-15 20:41:55 -0700
commitf84a05f8aeb73ce63f77b7cc779845c31427b2b2 (patch)
treeb11309b4649c5e7e1f4666e9a07e60da56b1c307 /app/src/main/kotlin/com/pitchedapps/frost/web
parentc8f76b5aa406f84f49789a50871c68a1a95a232d (diff)
downloadfrost-f84a05f8aeb73ce63f77b7cc779845c31427b2b2.tar.gz
frost-f84a05f8aeb73ce63f77b7cc779845c31427b2b2.tar.bz2
frost-f84a05f8aeb73ce63f77b7cc779845c31427b2b2.zip
Reorganize observables and clean up
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt5
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt16
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClientMenu.kt28
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt15
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