diff options
author | Allan Wang <me@allanwang.ca> | 2018-12-31 18:57:28 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-31 18:57:28 -0500 |
commit | 149c6be1bfd4bd84381757940fece1be7b9801aa (patch) | |
tree | 85fe10e3ee3ea34ad717f0d61975ca0119dd36d5 /app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt | |
parent | 7661bbfc9b8f34bf9d92dc08a9fcd7cc6ec7cbb3 (diff) | |
download | frost-149c6be1bfd4bd84381757940fece1be7b9801aa.tar.gz frost-149c6be1bfd4bd84381757940fece1be7b9801aa.tar.bz2 frost-149c6be1bfd4bd84381757940fece1be7b9801aa.zip |
Enhancement/coroutines (#1273)
* Convert rest of fbcookie to suspended methods
* Replace active checks with yield
* Apply spotless
* Switch cookie domain to exact url
* Optimize imports and enable travis tests again
* Update proguard rules
* Remove unnecessary yield
* Remove unused flyweight
* Remove unused disposable and method
* Use contexthelper instead of dispatcher main
* Convert login activity to coroutines
* Use kau helper methods for coroutines
* Enhancement/offline site (#1288)
* Begin conversion of offline site logic
* Fix offline tests and add validation tests
* Ignore cookie in jsoup if it is blank
* Force load and zip to be in io
* Use different zip files to fix tests
* Log all test output
* Do not log stdout
* Allow test skip for fb offline
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt | 24 |
1 files changed, 17 insertions, 7 deletions
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) + } + } } } |