diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt | 14 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt | 24 |
2 files changed, 27 insertions, 11 deletions
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 c8b54e7a..19d16e87 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt @@ -16,31 +16,35 @@ */ package com.pitchedapps.frost.web +import android.content.Context import android.webkit.JavascriptInterface import com.pitchedapps.frost.activities.MainActivity import com.pitchedapps.frost.contracts.MainActivityContract import com.pitchedapps.frost.contracts.VideoViewHolder +import com.pitchedapps.frost.dbflow.CookieModel import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs import com.pitchedapps.frost.utils.WebContext import com.pitchedapps.frost.utils.cookies +import com.pitchedapps.frost.utils.ctxCoroutine import com.pitchedapps.frost.utils.isIndependent import com.pitchedapps.frost.utils.launchImageActivity import com.pitchedapps.frost.utils.showWebContextMenu import com.pitchedapps.frost.views.FrostWebView import kotlinx.coroutines.channels.SendChannel +import kotlinx.coroutines.launch /** * Created by Allan Wang on 2017-06-01. */ class FrostJSI(val web: FrostWebView) { - private val context = web.context - private val activity = context as? MainActivity + private val context: Context = web.context + private val activity: MainActivity? = context as? MainActivity private val header: SendChannel<String>? = activity?.headerBadgeChannel private val refresh: SendChannel<Boolean> = web.parent.refreshChannel - private val cookies = activity?.cookies() ?: arrayListOf() + private val cookies: List<CookieModel> = activity?.cookies() ?: arrayListOf() /** * Attempts to load the url in an overlay @@ -103,7 +107,9 @@ class FrostJSI(val web: FrostWebView) { @JavascriptInterface fun loadLogin() { L.d { "Sign up button found; load login" } - FbCookie.logout(context) + context.ctxCoroutine.launch { + FbCookie.logout(context) + } } /** 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 2fe78f02..8132382a 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt @@ -28,6 +28,7 @@ import android.webkit.WebResourceRequest import android.webkit.WebView import ca.allanwang.kau.utils.fadeIn import ca.allanwang.kau.utils.isVisible +import ca.allanwang.kau.utils.withMainContext import com.pitchedapps.frost.dbflow.CookieModel import com.pitchedapps.frost.facebook.FB_LOGIN_URL import com.pitchedapps.frost.facebook.FB_USER_MATCHER @@ -39,6 +40,10 @@ import com.pitchedapps.frost.injectors.jsInject import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs import com.pitchedapps.frost.utils.isFacebookUrl +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.launch +import kotlinx.coroutines.suspendCancellableCoroutine +import kotlin.coroutines.resume /** * Created by Allan Wang on 2017-05-29. @@ -60,13 +65,18 @@ class LoginWebView @JvmOverloads constructor( webChromeClient = LoginChromeClient() } - fun loadLogin(progressCallback: (Int) -> Unit, loginCallback: (CookieModel) -> Unit) { - this.progressCallback = progressCallback - this.loginCallback = loginCallback - L.d { "Begin loading login" } - FbCookie.reset { - setupWebview() - loadUrl(FB_LOGIN_URL) + suspend fun loadLogin(progressCallback: (Int) -> Unit): CookieModel = withMainContext { + coroutineScope { + suspendCancellableCoroutine<CookieModel> { cont -> + this@LoginWebView.progressCallback = progressCallback + this@LoginWebView.loginCallback = { cont.resume(it) } + L.d { "Begin loading login" } + launch { + FbCookie.reset() + setupWebview() + loadUrl(FB_LOGIN_URL) + } + } } } |