Merge pull request #11 from gedoor/master

merge
pull/441/head
口口吕 4 years ago committed by GitHub
commit e09d5c19db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/src/main/assets/updateLog.md
  2. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  3. 12
      app/src/main/java/io/legado/app/help/JsExtensions.kt
  4. 4
      app/src/main/java/io/legado/app/help/http/CookieStore.kt
  5. 30
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  6. 7
      app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt
  7. 2
      app/src/main/res/values-zh-rHK/strings.xml
  8. 2
      app/src/main/res/values-zh-rTW/strings.xml
  9. 2
      app/src/main/res/values-zh/strings.xml
  10. 2
      app/src/main/res/values/strings.xml
  11. 16
      app/src/main/res/xml/pref_config_other.xml

@ -6,7 +6,11 @@
**2020/10/23** **2020/10/23**
* 修复选择错误的bug * 修复选择错误的bug
* 修复长图最后一张不能滚动的bug * 修复长图最后一张不能滚动的bug
* js添加java.getCookie(sourceUrl)来获取登录后的cookie by [AndyBernie](https://github.com/AndyBernie) * js添加java.getCookie(sourceUrl:String, key:String? = null)来获取登录后的cookie by [AndyBernie](https://github.com/AndyBernie)
```
java.getCookie("http://baidu.com", null) => userid=1234;pwd=adbcd
java.getCookie("http://baidu.com", "userid") => 1234
```
* 修复简繁转换没有处理标题 * 修复简繁转换没有处理标题
**2020/10/21** **2020/10/21**

@ -51,6 +51,7 @@ object PreferKey {
const val defaultCover = "defaultCover" const val defaultCover = "defaultCover"
const val replaceEnableDefault = "replaceEnableDefault" const val replaceEnableDefault = "replaceEnableDefault"
const val showBrightnessView = "showBrightnessView" const val showBrightnessView = "showBrightnessView"
const val autoClearExpired = "autoClearExpired"
const val cPrimary = "colorPrimary" const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent" const val cAccent = "colorAccent"

@ -3,8 +3,8 @@ package io.legado.app.help
import android.util.Base64 import android.util.Base64
import androidx.annotation.Keep import androidx.annotation.Keep
import io.legado.app.constant.AppConst.dateFormat import io.legado.app.constant.AppConst.dateFormat
import io.legado.app.help.http.SSLHelper
import io.legado.app.help.http.CookieStore import io.legado.app.help.http.CookieStore
import io.legado.app.help.http.SSLHelper
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.* import io.legado.app.utils.*
import org.jsoup.Connection import org.jsoup.Connection
@ -123,8 +123,14 @@ interface JsExtensions {
/** /**
*js实现读取cookie *js实现读取cookie
*/ */
fun getCookie(tag: String): String { fun getCookie(tag: String, key: String? = null): String {
return CookieStore.getCookie(tag) val cookie = CookieStore.getCookie(tag)
val cookieMap = CookieStore.cookieToMap(cookie)
return if (key != null) {
cookieMap[key] ?: ""
} else {
cookie
}
} }
/** /**

@ -43,7 +43,7 @@ object CookieStore : CookiePersistor {
App.db.cookieDao().delete(NetworkUtils.getSubDomain(url)) App.db.cookieDao().delete(NetworkUtils.getSubDomain(url))
} }
private fun cookieToMap(cookie: String): MutableMap<String, String> { fun cookieToMap(cookie: String): MutableMap<String, String> {
val cookieMap = mutableMapOf<String, String>() val cookieMap = mutableMapOf<String, String>()
if (cookie.isBlank()) { if (cookie.isBlank()) {
return cookieMap return cookieMap
@ -63,7 +63,7 @@ object CookieStore : CookiePersistor {
return cookieMap return cookieMap
} }
private fun mapToCookie(cookieMap: Map<String, String>?): String? { fun mapToCookie(cookieMap: Map<String, String>?): String? {
if (cookieMap == null || cookieMap.isEmpty()) { if (cookieMap == null || cookieMap.isEmpty()) {
return null return null
} }

@ -281,7 +281,13 @@ class AnalyzeUrl(
fun getResponse(tag: String): Call<String> { fun getResponse(tag: String): Call<String> {
val cookie = CookieStore.getCookie(tag) val cookie = CookieStore.getCookie(tag)
if (cookie.isNotEmpty()) { if (cookie.isNotEmpty()) {
headerMap["Cookie"] += ";${cookie}" val cookieMap = CookieStore.cookieToMap(cookie)
val customCookieMap = CookieStore.cookieToMap(headerMap["Cookie"] ?: "")
cookieMap.putAll(customCookieMap)
val newCookie = CookieStore.mapToCookie(cookieMap)
newCookie?.let {
headerMap.put("Cookie", it)
}
} }
return when { return when {
method == RequestMethod.POST -> { method == RequestMethod.POST -> {
@ -312,6 +318,16 @@ class AnalyzeUrl(
if (type != null) { if (type != null) {
return Res(url, StringUtils.byteToHexString(getResponseBytes(tag))) return Res(url, StringUtils.byteToHexString(getResponseBytes(tag)))
} }
val cookie = CookieStore.getCookie(tag)
if (cookie.isNotEmpty()) {
val cookieMap = CookieStore.cookieToMap(cookie)
val customCookieMap = CookieStore.cookieToMap(headerMap["Cookie"] ?: "")
cookieMap.putAll(customCookieMap)
val newCookie = CookieStore.mapToCookie(cookieMap)
newCookie?.let {
headerMap.put("Cookie", it)
}
}
if (useWebView) { if (useWebView) {
val params = AjaxWebView.AjaxParams(url) val params = AjaxWebView.AjaxParams(url)
params.headerMap = headerMap params.headerMap = headerMap
@ -322,10 +338,6 @@ class AnalyzeUrl(
params.tag = tag params.tag = tag
return HttpHelper.ajax(params) return HttpHelper.ajax(params)
} }
val cookie = CookieStore.getCookie(tag)
if (cookie.isNotEmpty()) {
headerMap["Cookie"] += ";${cookie}"
}
val res = when { val res = when {
method == RequestMethod.POST -> { method == RequestMethod.POST -> {
if (fieldMap.isNotEmpty()) { if (fieldMap.isNotEmpty()) {
@ -356,7 +368,13 @@ class AnalyzeUrl(
if (tag != null) { if (tag != null) {
val cookie = CookieStore.getCookie(tag) val cookie = CookieStore.getCookie(tag)
if (cookie.isNotEmpty()) { if (cookie.isNotEmpty()) {
headerMap["Cookie"] += ";${cookie}" val cookieMap = CookieStore.cookieToMap(cookie)
val customCookieMap = CookieStore.cookieToMap(headerMap["Cookie"] ?: "")
cookieMap.putAll(customCookieMap)
val newCookie = CookieStore.mapToCookie(cookieMap)
newCookie?.let {
headerMap.put("Cookie", it)
}
} }
} }
val response = when { val response = when {

@ -6,6 +6,7 @@ import com.hankcs.hanlp.HanLP
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseActivity import io.legado.app.base.BaseActivity
import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.storage.SyncBookProgress import io.legado.app.help.storage.SyncBookProgress
@ -33,8 +34,10 @@ open class WelcomeActivity : BaseActivity(R.layout.activity_welcome) {
private fun init() { private fun init() {
Coroutine.async { Coroutine.async {
//清除过期数据 //清除过期数据
App.db.searchBookDao() if (getPrefBoolean(PreferKey.autoClearExpired, true)) {
.clearExpired(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1)) App.db.searchBookDao()
.clearExpired(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1))
}
//初始化简繁转换引擎 //初始化简繁转换引擎
when (AppConfig.chineseConverterType) { when (AppConfig.chineseConverterType) {
1 -> HanLP.convertToSimplifiedChinese("初始化") 1 -> HanLP.convertToSimplifiedChinese("初始化")

@ -771,5 +771,7 @@
<string name="explore_empty">当前没有发现源,关注公众号[开源阅读]添加带发现的书源!</string> <string name="explore_empty">当前没有发现源,关注公众号[开源阅读]添加带发现的书源!</string>
<string name="page_key_set_help">将焦点放到输入框按下物理按键会自动录入键值,多个按键会自动用英文逗号隔开.</string> <string name="page_key_set_help">将焦点放到输入框按下物理按键会自动录入键值,多个按键会自动用英文逗号隔开.</string>
<string name="theme_name">主题名称</string> <string name="theme_name">主题名称</string>
<string name="auto_clear_expired">自动清除过期搜索数据</string>
<string name="auto_clear_expired_summary">超过一天的搜索数据</string>
</resources> </resources>

@ -771,5 +771,7 @@
<string name="explore_empty">目前沒有發現源,關注公眾號[开源阅读]添加包含發現的書源!</string> <string name="explore_empty">目前沒有發現源,關注公眾號[开源阅读]添加包含發現的書源!</string>
<string name="page_key_set_help">将焦点放到输入框按下物理按键会自动录入键值,多个按键会自动用英文逗号隔开.</string> <string name="page_key_set_help">将焦点放到输入框按下物理按键会自动录入键值,多个按键会自动用英文逗号隔开.</string>
<string name="theme_name">主题名称</string> <string name="theme_name">主题名称</string>
<string name="auto_clear_expired">自动清除过期搜索数据</string>
<string name="auto_clear_expired_summary">超过一天的搜索数据</string>
</resources> </resources>

@ -774,5 +774,7 @@
<string name="explore_empty">当前没有发现源,关注公众号[开源阅读]添加带发现的书源!</string> <string name="explore_empty">当前没有发现源,关注公众号[开源阅读]添加带发现的书源!</string>
<string name="page_key_set_help">将焦点放到输入框按下物理按键会自动录入键值,多个按键会自动用英文逗号隔开.</string> <string name="page_key_set_help">将焦点放到输入框按下物理按键会自动录入键值,多个按键会自动用英文逗号隔开.</string>
<string name="theme_name">主题名称</string> <string name="theme_name">主题名称</string>
<string name="auto_clear_expired">自动清除过期搜索数据</string>
<string name="auto_clear_expired_summary">超过一天的搜索数据</string>
</resources> </resources>

@ -777,5 +777,7 @@
<string name="explore_empty">当前没有发现源,关注公众号[开源阅读]添加带发现的书源!</string> <string name="explore_empty">当前没有发现源,关注公众号[开源阅读]添加带发现的书源!</string>
<string name="page_key_set_help">将焦点放到输入框按下物理按键会自动录入键值,多个按键会自动用英文逗号隔开.</string> <string name="page_key_set_help">将焦点放到输入框按下物理按键会自动录入键值,多个按键会自动用英文逗号隔开.</string>
<string name="theme_name">主题名称</string> <string name="theme_name">主题名称</string>
<string name="auto_clear_expired">自动清除过期搜索数据</string>
<string name="auto_clear_expired_summary">超过一天的搜索数据</string>
</resources> </resources>

@ -58,11 +58,6 @@
android:summary="@string/replace_enable_default_s" android:summary="@string/replace_enable_default_s"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.Preference
android:key="threadCount"
android:title="@string/threads_num_title"
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:key="mediaButtonOnExit" android:key="mediaButtonOnExit"
@ -70,6 +65,12 @@
android:summary="@string/media_button_on_exit_summary" android:summary="@string/media_button_on_exit_summary"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true"
android:key="autoClearExpired"
android:title="@string/auto_clear_expired"
android:summary="@string/auto_clear_expired_summary" />
<io.legado.app.ui.widget.prefs.Preference <io.legado.app.ui.widget.prefs.Preference
android:key="webPort" android:key="webPort"
android:title="@string/web_port_title" android:title="@string/web_port_title"
@ -81,6 +82,11 @@
android:summary="@string/clear_cache_summary" android:summary="@string/clear_cache_summary"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.Preference
android:key="threadCount"
android:title="@string/threads_num_title"
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:key="process_text" android:key="process_text"

Loading…
Cancel
Save