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