diff options
author | Allan Wang <me@allanwang.ca> | 2017-06-06 19:29:25 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-06-06 19:29:25 -0700 |
commit | 067ea15188f20fa268255153e35c2df732fdffee (patch) | |
tree | 87a0fcd84f37ad569ec2743ffc702a69cd59e252 /app/src/main/kotlin/com/pitchedapps/frost/web | |
parent | c4e22f5512570d05178711ba90c28eb6dc288253 (diff) | |
download | frost-067ea15188f20fa268255153e35c2df732fdffee.tar.gz frost-067ea15188f20fa268255153e35c2df732fdffee.tar.bz2 frost-067ea15188f20fa268255153e35c2df732fdffee.zip |
Clean up injectors and events
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web')
5 files changed, 52 insertions, 34 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 ff8637b1..7ad12c3a 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt @@ -12,16 +12,14 @@ import io.reactivex.subjects.Subject */ class FrostChromeClient(val progressObservable: Subject<Int>, val titleObservable: BehaviorSubject<String>) : WebChromeClient() { - override fun onConsoleMessage(consoleMessage: ConsoleMessage): Boolean { - L.d("Chrome Console ${consoleMessage.lineNumber()}: ${consoleMessage.message()}") + L.v("Chrome Console ${consoleMessage.lineNumber()}: ${consoleMessage.message()}") return super.onConsoleMessage(consoleMessage) } override fun onReceivedTitle(view: WebView, title: String) { super.onReceivedTitle(view, title) if (title.contains("http") || titleObservable.value == title) return -// L.v("Title $title") titleObservable.onNext(title) } @@ -30,5 +28,4 @@ class FrostChromeClient(val progressObservable: Subject<Int>, val titleObservabl progressObservable.onNext(newProgress) } - }
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt index a3233c4c..045c180f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt @@ -1,13 +1,26 @@ package com.pitchedapps.frost.web +import android.content.Context import android.webkit.JavascriptInterface +import com.pitchedapps.frost.LoginActivity +import com.pitchedapps.frost.SelectorActivity +import com.pitchedapps.frost.dbflow.CookieModel +import com.pitchedapps.frost.utils.launchNewTask +import com.pitchedapps.frost.utils.launchWebOverlay /** * Created by Allan Wang on 2017-06-01. */ -class FrostJSI { +class FrostJSI(val context: Context, val cookies: ArrayList<CookieModel>) { @JavascriptInterface - fun loadUrl(url: String){ + fun loadUrl(url: String) = context.launchWebOverlay(url) + @JavascriptInterface + fun loadLogin() { + if (cookies.isNotEmpty()) + context.launchNewTask(SelectorActivity::class.java, cookies) + else + context.launchNewTask(LoginActivity::class.java, clearStack = false) } + }
\ No newline at end of file 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 fb5fd0e7..37d10015 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt @@ -1,17 +1,19 @@ package com.pitchedapps.frost.web +import android.content.Context import android.graphics.Bitmap import android.view.KeyEvent -import android.webkit.WebResourceRequest -import android.webkit.WebResourceResponse -import android.webkit.WebView -import android.webkit.WebViewClient +import android.webkit.* import com.pitchedapps.frost.LoginActivity +import com.pitchedapps.frost.MainActivity +import com.pitchedapps.frost.SelectorActivity import com.pitchedapps.frost.facebook.FACEBOOK_COM import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.injectors.CssAssets +import com.pitchedapps.frost.injectors.JsActions import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs +import com.pitchedapps.frost.utils.cookies import com.pitchedapps.frost.utils.launchNewTask import com.pitchedapps.frost.views.circularReveal import com.pitchedapps.frost.views.fadeOut @@ -34,22 +36,26 @@ class FrostWebViewClient(val refreshObservable: Subject<Boolean>) : WebViewClien override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) { super.onPageStarted(view, url, favicon) L.i("FWV Loading $url") + L.i("Cookies ${CookieManager.getInstance().getCookie(url)}") refreshObservable.onNext(true) if (!url.contains(FACEBOOK_COM)) return - if (url.contains("logout.php")) { - FbCookie.logout(Prefs.userId) - view.context.launchNewTask(LoginActivity::class.java) - } else if (url.contains("login.php")) { - FbCookie.reset() - view.context.launchNewTask(LoginActivity::class.java) - } + if (url.contains("logout.php")) FbCookie.logout(Prefs.userId, { launchLogin(view.context) }) + else if (url.contains("login.php")) FbCookie.reset({ launchLogin(view.context) }) view.fadeOut(duration = 200L) } + fun launchLogin(c: Context) { + if (c is MainActivity && c.cookies().isNotEmpty()) + c.launchNewTask(SelectorActivity::class.java, c.cookies()) + else + c.launchNewTask(LoginActivity::class.java, clearStack = false) + } + override fun onPageFinished(view: WebView, url: String) { super.onPageFinished(view, url) refreshObservable.onNext(false) if (!url.contains(FACEBOOK_COM)) return + 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 7e121b83..6477deda 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt @@ -11,6 +11,7 @@ import android.util.AttributeSet import android.view.MotionEvent import android.view.View import android.view.animation.DecelerateInterpolator +import android.webkit.CookieManager import android.webkit.WebView import com.pitchedapps.frost.utils.L import io.reactivex.Scheduler @@ -113,7 +114,7 @@ class FrostWebViewCore @JvmOverloads constructor( */ fun scrollOrRefresh() { L.d("Scroll or Refresh") - if (scrollY < 5) reload() + if (scrollY < 5) loadBaseUrl() else scrollToTop() } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt index ede07710..191d9350 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt @@ -39,24 +39,25 @@ class LoginWebView @JvmOverloads constructor( lateinit var progressObservable: Subject<Int> init { - FbCookie.reset() - cookieObservable.filter { (_, cookie) -> cookie?.contains(userMatcher) ?: false } - .subscribe { - (url, cookie) -> - L.d("Checking cookie for $url\n\t$cookie") - val id = userMatcher.find(cookie!!)?.groups?.get(1)?.value - if (id != null) { - try { - FbCookie.save(id.toLong()) - //TODO proceed to next view - cookieObservable.onComplete() - loginObservable.onSuccess(CookieModel(id.toLong(), "", cookie)) - } catch (e: NumberFormatException) { - //todo send report that id has changed + FbCookie.reset({ + cookieObservable.filter { (_, cookie) -> cookie?.contains(userMatcher) ?: false } + .subscribe { + (url, cookie) -> + L.d("Checking cookie for $url\n\t$cookie") + val id = userMatcher.find(cookie!!)?.groups?.get(1)?.value + if (id != null) { + try { + FbCookie.save(id.toLong()) + //TODO proceed to next view + cookieObservable.onComplete() + loginObservable.onSuccess(CookieModel(id.toLong(), "", cookie)) + } catch (e: NumberFormatException) { + //todo send report that id has changed + } } } - } - setupWebview() + setupWebview() + }) } @SuppressLint("SetJavaScriptEnabled") |