pull/487/head^2
gedoor 4 years ago
parent ad24761a10
commit 2878590f2f
  1. 1
      app/src/main/assets/updateLog.md
  2. 8
      app/src/main/java/io/legado/app/help/http/AjaxWebView.kt
  3. 19
      app/src/main/java/io/legado/app/help/http/CookieStore.kt
  4. 28
      app/src/main/java/io/legado/app/help/http/api/CookieManager.kt
  5. 4
      app/src/main/java/io/legado/app/ui/login/SourceLogin.kt

@ -6,6 +6,7 @@
**2020/11/18**
* 优化导航栏
* js添加java.log(msg: String)用于调试时输出消息
* js添加cookie对象,可用方法见io.legado.app.help.http.api.CookieManager
**2020/11/16**
* 修复导出添加替换净化引起的bug

@ -117,10 +117,10 @@ class AjaxWebView {
val isSniff: Boolean
get() = !TextUtils.isEmpty(sourceRegex)
fun setCookie(url: String) {
fun putCookie(url: String) {
tag?.let {
val cookie = CookieManager.getInstance().getCookie(url)
CookieStore.setCookie(it, cookie)
CookieStore.putCookie(it, cookie)
}
}
@ -140,7 +140,7 @@ class AjaxWebView {
) : WebViewClient() {
override fun onPageFinished(view: WebView, url: String) {
params.setCookie(url)
params.putCookie(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.setCookie(url)
params.putCookie(url)
if (params.hasJavaScript()) {
evaluateJavascript(view, params.javaScript)
params.clearJavaScript()

@ -8,42 +8,43 @@ 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 {
object CookieStore : CookiePersistor, CookieManager {
fun setCookie(url: String, cookie: String?) {
override fun putCookie(url: String, cookie: String?) {
Coroutine.async {
val cookieBean = Cookie(NetworkUtils.getSubDomain(url), cookie ?: "")
App.db.cookieDao().insert(cookieBean)
}
}
fun replaceCookie(url: String, cookie: String) {
override fun replaceCookie(url: String, cookie: String) {
if (TextUtils.isEmpty(url) || TextUtils.isEmpty(cookie)) {
return
}
val oldCookie = getCookie(url)
if (TextUtils.isEmpty(oldCookie)) {
setCookie(url, cookie)
putCookie(url, cookie)
} else {
val cookieMap = cookieToMap(oldCookie)
cookieMap.putAll(cookieToMap(cookie))
val newCookie = mapToCookie(cookieMap)
setCookie(url, newCookie)
putCookie(url, newCookie)
}
}
fun getCookie(url: String): String {
override fun getCookie(url: String): String {
val cookieBean = App.db.cookieDao().get(NetworkUtils.getSubDomain(url))
return cookieBean?.cookie ?: ""
}
fun removeCookie(url: String) {
override fun removeCookie(url: String) {
App.db.cookieDao().delete(NetworkUtils.getSubDomain(url))
}
fun cookieToMap(cookie: String): MutableMap<String, String> {
override fun cookieToMap(cookie: String): MutableMap<String, String> {
val cookieMap = mutableMapOf<String, String>()
if (cookie.isBlank()) {
return cookieMap
@ -63,7 +64,7 @@ object CookieStore : CookiePersistor {
return cookieMap
}
fun mapToCookie(cookieMap: Map<String, String>?): String? {
override fun mapToCookie(cookieMap: Map<String, String>?): String? {
if (cookieMap == null || cookieMap.isEmpty()) {
return null
}

@ -0,0 +1,28 @@
package io.legado.app.help.http.api
interface CookieManager {
/**
* 保存cookie
*/
fun putCookie(url: String, cookie: String?)
/**
* 替换cookie
*/
fun replaceCookie(url: String, cookie: String)
/**
* 获取cookie
*/
fun getCookie(url: String): String
/**
* 移除cookie
*/
fun removeCookie(url: String)
fun cookieToMap(cookie: String): MutableMap<String, String>
fun mapToCookie(cookieMap: Map<String, String>?): String?
}

@ -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.setCookie(it, cookie)
CookieStore.putCookie(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.setCookie(it, cookie)
CookieStore.putCookie(it, cookie)
}
if (checking) {
finish()

Loading…
Cancel
Save