diff options
author | Allan Wang <me@allanwang.ca> | 2019-03-05 21:06:24 -0500 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2019-03-05 21:06:24 -0500 |
commit | 65bb9233b2a0d8734c1d13e8f3a01bee0f6c3b17 (patch) | |
tree | abe5c5db1b05757375d63c32ec8afae9893a9dee /app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt | |
parent | 5c4400975450c9739f0986561075983e08afae89 (diff) | |
download | frost-65bb9233b2a0d8734c1d13e8f3a01bee0f6c3b17.tar.gz frost-65bb9233b2a0d8734c1d13e8f3a01bee0f6c3b17.tar.bz2 frost-65bb9233b2a0d8734c1d13e8f3a01bee0f6c3b17.zip |
Convert fbcookies to room entities
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 | 16 |
1 files changed, 9 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 11a53c36..07aafaf0 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt @@ -29,6 +29,7 @@ import android.webkit.WebView import ca.allanwang.kau.utils.fadeIn import ca.allanwang.kau.utils.isVisible import ca.allanwang.kau.utils.launchMain +import com.pitchedapps.frost.db.CookieEntity import com.pitchedapps.frost.db.CookieModel import com.pitchedapps.frost.facebook.FB_LOGIN_URL import com.pitchedapps.frost.facebook.FB_USER_MATCHER @@ -52,7 +53,7 @@ class LoginWebView @JvmOverloads constructor( defStyleAttr: Int = 0 ) : WebView(context, attrs, defStyleAttr) { - private val completable: CompletableDeferred<CookieModel> = CompletableDeferred() + private val completable: CompletableDeferred<CookieEntity> = CompletableDeferred() private lateinit var progressCallback: (Int) -> Unit @SuppressLint("SetJavaScriptEnabled") @@ -63,7 +64,7 @@ class LoginWebView @JvmOverloads constructor( webChromeClient = LoginChromeClient() } - suspend fun loadLogin(progressCallback: (Int) -> Unit): CompletableDeferred<CookieModel> = coroutineScope { + suspend fun loadLogin(progressCallback: (Int) -> Unit): CompletableDeferred<CookieEntity> = coroutineScope { this@LoginWebView.progressCallback = progressCallback L.d { "Begin loading login" } launchMain { @@ -78,18 +79,19 @@ class LoginWebView @JvmOverloads constructor( override fun onPageFinished(view: WebView, url: String?) { super.onPageFinished(view, url) - val cookieModel = checkForLogin(url) - if (cookieModel != null) - completable.complete(cookieModel) + val cookie = checkForLogin(url) + if (cookie != null) + completable.complete(cookie) if (!view.isVisible) view.fadeIn() } - fun checkForLogin(url: String?): CookieModel? { + fun checkForLogin(url: String?): CookieEntity? { if (!url.isFacebookUrl) return null val cookie = CookieManager.getInstance().getCookie(url) ?: return null L.d { "Checking cookie for login" } val id = FB_USER_MATCHER.find(cookie)[1]?.toLong() ?: return null - return CookieModel(id, "", cookie) + // TODO set name to null? + return CookieEntity(id, "", cookie) } override fun onPageCommitVisible(view: WebView, url: String?) { |