From cd859406d58e6095e49c6682a49877dff2dcc7f0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 1 Mar 2020 15:42:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/help/http/CookieStore.kt | 4 ++-- .../io/legado/app/ui/login/SourceLogin.kt | 20 +++++++------------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/http/CookieStore.kt b/app/src/main/java/io/legado/app/help/http/CookieStore.kt index d01eb465c..d82a4b175 100644 --- a/app/src/main/java/io/legado/app/help/http/CookieStore.kt +++ b/app/src/main/java/io/legado/app/help/http/CookieStore.kt @@ -3,15 +3,15 @@ package io.legado.app.help.http import android.text.TextUtils import io.legado.app.App import io.legado.app.data.entities.Cookie +import io.legado.app.help.coroutine.Coroutine object CookieStore { fun setCookie(url: String, cookie: String?) { - try { + Coroutine.async { val cookieBean = Cookie(url, cookie ?: "") App.db.cookieDao().insert(cookieBean) - } catch (ignore: Exception) { } } diff --git a/app/src/main/java/io/legado/app/ui/login/SourceLogin.kt b/app/src/main/java/io/legado/app/ui/login/SourceLogin.kt index a0703aef3..35a62200c 100644 --- a/app/src/main/java/io/legado/app/ui/login/SourceLogin.kt +++ b/app/src/main/java/io/legado/app/ui/login/SourceLogin.kt @@ -8,14 +8,11 @@ import android.view.MenuItem import android.webkit.CookieManager import android.webkit.WebView import android.webkit.WebViewClient -import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseActivity -import io.legado.app.data.entities.Cookie +import io.legado.app.help.http.CookieStore import io.legado.app.utils.snackbar import kotlinx.android.synthetic.main.activity_source_login.* -import kotlinx.coroutines.Dispatchers.IO -import kotlinx.coroutines.launch class SourceLogin : BaseActivity(R.layout.activity_source_login) { @@ -41,13 +38,17 @@ class SourceLogin : BaseActivity(R.layout.activity_source_login) { web_view.webViewClient = object : WebViewClient() { override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) { val cookie = cookieManager.getCookie(url) - saveCookie(cookie) + sourceUrl?.let { + CookieStore.setCookie(it, cookie) + } super.onPageStarted(view, url, favicon) } override fun onPageFinished(view: WebView?, url: String?) { val cookie = cookieManager.getCookie(url) - saveCookie(cookie) + sourceUrl?.let { + CookieStore.setCookie(it, cookie) + } if (checking) { finish() } @@ -75,11 +76,4 @@ class SourceLogin : BaseActivity(R.layout.activity_source_login) { return super.onCompatOptionsItemSelected(item) } - private fun saveCookie(cookie: String) { - launch(IO) { - sourceUrl?.let { - App.db.cookieDao().insert(Cookie(it, cookie)) - } - } - } } \ No newline at end of file