pull/487/head^2
gedoor 4 years ago
parent 2878590f2f
commit 04149d2bf7
  1. 8
      app/src/main/java/io/legado/app/help/http/AjaxWebView.kt
  2. 13
      app/src/main/java/io/legado/app/help/http/CookieStore.kt
  3. 2
      app/src/main/java/io/legado/app/help/http/api/CookieManager.kt
  4. 4
      app/src/main/java/io/legado/app/ui/login/SourceLogin.kt

@ -117,10 +117,10 @@ class AjaxWebView {
val isSniff: Boolean val isSniff: Boolean
get() = !TextUtils.isEmpty(sourceRegex) get() = !TextUtils.isEmpty(sourceRegex)
fun putCookie(url: String) { fun setCookie(url: String) {
tag?.let { tag?.let {
val cookie = CookieManager.getInstance().getCookie(url) val cookie = CookieManager.getInstance().getCookie(url)
CookieStore.putCookie(it, cookie) CookieStore.setCookie(it, cookie)
} }
} }
@ -140,7 +140,7 @@ class AjaxWebView {
) : WebViewClient() { ) : WebViewClient() {
override fun onPageFinished(view: WebView, url: String) { override fun onPageFinished(view: WebView, url: String) {
params.putCookie(url) params.setCookie(url)
val runnable = EvalJsRunnable(view, url, params.getJs(), handler) val runnable = EvalJsRunnable(view, url, params.getJs(), handler)
handler.postDelayed(runnable, 1000) handler.postDelayed(runnable, 1000)
} }
@ -193,7 +193,7 @@ class AjaxWebView {
} }
override fun onPageFinished(view: WebView, url: String) { override fun onPageFinished(view: WebView, url: String) {
params.putCookie(url) params.setCookie(url)
if (params.hasJavaScript()) { if (params.hasJavaScript()) {
evaluateJavascript(view, params.javaScript) evaluateJavascript(view, params.javaScript)
params.clearJavaScript() params.clearJavaScript()

@ -7,17 +7,14 @@ import com.franmontiel.persistentcookiejar.persistence.CookiePersistor
import com.franmontiel.persistentcookiejar.persistence.SerializableCookie import com.franmontiel.persistentcookiejar.persistence.SerializableCookie
import io.legado.app.App import io.legado.app.App
import io.legado.app.data.entities.Cookie 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.help.http.api.CookieManager
import io.legado.app.utils.NetworkUtils import io.legado.app.utils.NetworkUtils
object CookieStore : CookiePersistor, CookieManager { object CookieStore : CookiePersistor, CookieManager {
override fun putCookie(url: String, cookie: String?) { override fun setCookie(url: String, cookie: String?) {
Coroutine.async { val cookieBean = Cookie(NetworkUtils.getSubDomain(url), cookie ?: "")
val cookieBean = Cookie(NetworkUtils.getSubDomain(url), cookie ?: "") App.db.cookieDao().insert(cookieBean)
App.db.cookieDao().insert(cookieBean)
}
} }
override fun replaceCookie(url: String, cookie: String) { override fun replaceCookie(url: String, cookie: String) {
@ -26,12 +23,12 @@ object CookieStore : CookiePersistor, CookieManager {
} }
val oldCookie = getCookie(url) val oldCookie = getCookie(url)
if (TextUtils.isEmpty(oldCookie)) { if (TextUtils.isEmpty(oldCookie)) {
putCookie(url, cookie) setCookie(url, cookie)
} else { } else {
val cookieMap = cookieToMap(oldCookie) val cookieMap = cookieToMap(oldCookie)
cookieMap.putAll(cookieToMap(cookie)) cookieMap.putAll(cookieToMap(cookie))
val newCookie = mapToCookie(cookieMap) val newCookie = mapToCookie(cookieMap)
putCookie(url, newCookie) setCookie(url, newCookie)
} }
} }

@ -5,7 +5,7 @@ interface CookieManager {
/** /**
* 保存cookie * 保存cookie
*/ */
fun putCookie(url: String, cookie: String?) fun setCookie(url: String, cookie: String?)
/** /**
* 替换cookie * 替换cookie

@ -39,7 +39,7 @@ class SourceLogin : BaseActivity(R.layout.activity_source_login) {
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) { override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
val cookie = cookieManager.getCookie(url) val cookie = cookieManager.getCookie(url)
sourceUrl?.let { sourceUrl?.let {
CookieStore.putCookie(it, cookie) CookieStore.setCookie(it, cookie)
} }
super.onPageStarted(view, url, favicon) super.onPageStarted(view, url, favicon)
} }
@ -47,7 +47,7 @@ class SourceLogin : BaseActivity(R.layout.activity_source_login) {
override fun onPageFinished(view: WebView?, url: String?) { override fun onPageFinished(view: WebView?, url: String?) {
val cookie = cookieManager.getCookie(url) val cookie = cookieManager.getCookie(url)
sourceUrl?.let { sourceUrl?.let {
CookieStore.putCookie(it, cookie) CookieStore.setCookie(it, cookie)
} }
if (checking) { if (checking) {
finish() finish()

Loading…
Cancel
Save