From 04149d2bf7c87aae0b18559fa3c50a71d1a35631 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 18 Nov 2020 19:00:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/http/AjaxWebView.kt | 8 ++++---- .../java/io/legado/app/help/http/CookieStore.kt | 13 +++++-------- .../io/legado/app/help/http/api/CookieManager.kt | 2 +- .../main/java/io/legado/app/ui/login/SourceLogin.kt | 4 ++-- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt b/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt index ddf64c895..db6dc165b 100644 --- a/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt +++ b/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt @@ -117,10 +117,10 @@ class AjaxWebView { val isSniff: Boolean get() = !TextUtils.isEmpty(sourceRegex) - fun putCookie(url: String) { + fun setCookie(url: String) { tag?.let { val cookie = CookieManager.getInstance().getCookie(url) - CookieStore.putCookie(it, cookie) + CookieStore.setCookie(it, cookie) } } @@ -140,7 +140,7 @@ class AjaxWebView { ) : WebViewClient() { override fun onPageFinished(view: WebView, url: String) { - params.putCookie(url) + params.setCookie(url) val runnable = EvalJsRunnable(view, url, params.getJs(), handler) handler.postDelayed(runnable, 1000) } @@ -193,7 +193,7 @@ class AjaxWebView { } override fun onPageFinished(view: WebView, url: String) { - params.putCookie(url) + params.setCookie(url) if (params.hasJavaScript()) { evaluateJavascript(view, params.javaScript) params.clearJavaScript() 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 71eff8cb5..17bcc7695 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 @@ -7,17 +7,14 @@ import com.franmontiel.persistentcookiejar.persistence.CookiePersistor import com.franmontiel.persistentcookiejar.persistence.SerializableCookie import io.legado.app.App import io.legado.app.data.entities.Cookie -import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.http.api.CookieManager import io.legado.app.utils.NetworkUtils object CookieStore : CookiePersistor, CookieManager { - override fun putCookie(url: String, cookie: String?) { - Coroutine.async { - val cookieBean = Cookie(NetworkUtils.getSubDomain(url), cookie ?: "") - App.db.cookieDao().insert(cookieBean) - } + override fun setCookie(url: String, cookie: String?) { + val cookieBean = Cookie(NetworkUtils.getSubDomain(url), cookie ?: "") + App.db.cookieDao().insert(cookieBean) } override fun replaceCookie(url: String, cookie: String) { @@ -26,12 +23,12 @@ object CookieStore : CookiePersistor, CookieManager { } val oldCookie = getCookie(url) if (TextUtils.isEmpty(oldCookie)) { - putCookie(url, cookie) + setCookie(url, cookie) } else { val cookieMap = cookieToMap(oldCookie) cookieMap.putAll(cookieToMap(cookie)) val newCookie = mapToCookie(cookieMap) - putCookie(url, newCookie) + setCookie(url, newCookie) } } diff --git a/app/src/main/java/io/legado/app/help/http/api/CookieManager.kt b/app/src/main/java/io/legado/app/help/http/api/CookieManager.kt index 66978d46b..525aa712d 100644 --- a/app/src/main/java/io/legado/app/help/http/api/CookieManager.kt +++ b/app/src/main/java/io/legado/app/help/http/api/CookieManager.kt @@ -5,7 +5,7 @@ interface CookieManager { /** * 保存cookie */ - fun putCookie(url: String, cookie: String?) + fun setCookie(url: String, cookie: String?) /** * 替换cookie 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 3812040ca..dffe03695 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 @@ -39,7 +39,7 @@ class SourceLogin : BaseActivity(R.layout.activity_source_login) { override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) { val cookie = cookieManager.getCookie(url) sourceUrl?.let { - CookieStore.putCookie(it, cookie) + CookieStore.setCookie(it, cookie) } super.onPageStarted(view, url, favicon) } @@ -47,7 +47,7 @@ class SourceLogin : BaseActivity(R.layout.activity_source_login) { override fun onPageFinished(view: WebView?, url: String?) { val cookie = cookieManager.getCookie(url) sourceUrl?.let { - CookieStore.putCookie(it, cookie) + CookieStore.setCookie(it, cookie) } if (checking) { finish()