Merge branch 'gedoor:master' into master

pull/1882/head
Xwite 3 years ago committed by GitHub
commit a65d234325
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/src/main/AndroidManifest.xml
  2. 4
      app/src/main/assets/updateLog.md
  3. 2
      app/src/main/java/io/legado/app/constant/BookType.kt
  4. 2
      app/src/main/java/io/legado/app/help/http/CookieStore.kt
  5. 11
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  6. 7
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt
  7. 11
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt
  8. 7
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt
  9. 22
      app/src/main/java/io/legado/app/ui/widget/text/BadgeView.kt
  10. 7
      app/src/main/res/layout/activity_rss_source_edit.xml
  11. 5
      app/src/main/res/menu/source_edit.xml
  12. 1
      app/src/main/res/values-es-rES/strings.xml
  13. 1
      app/src/main/res/values-ja-rJP/strings.xml
  14. 1
      app/src/main/res/values-pt-rBR/strings.xml
  15. 1
      app/src/main/res/values-zh-rHK/strings.xml
  16. 1
      app/src/main/res/values-zh-rTW/strings.xml
  17. 1
      app/src/main/res/values-zh/strings.xml
  18. 1
      app/src/main/res/values/strings.xml

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools"
package="io.legado.app">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />

@ -14,7 +14,9 @@
**2022/05/13** **2022/05/13**
* 书源编辑添加cookieJar选项 * 源编辑添加cookieJar选项
* 源编辑菜单里添加清除cookie,如果之前能用的书源不能用了,可以关闭cookieJar后点下菜单里的清除cookie后再试
* 书源支持文件类型 by Xwite
**2022/05/11** **2022/05/11**

@ -11,6 +11,6 @@ object BookType {
@Target(AnnotationTarget.VALUE_PARAMETER) @Target(AnnotationTarget.VALUE_PARAMETER)
@Retention(AnnotationRetention.SOURCE) @Retention(AnnotationRetention.SOURCE)
@IntDef(default, audio, image) @IntDef(default, audio, image, file)
annotation class Type annotation class Type
} }

@ -56,8 +56,8 @@ object CookieStore : CookieManager {
override fun removeCookie(url: String) { override fun removeCookie(url: String) {
val domain = NetworkUtils.getSubDomain(url) val domain = NetworkUtils.getSubDomain(url)
CacheManager.deleteMemory("${domain}_cookie")
appDb.cookieDao.delete(domain) appDb.cookieDao.delete(domain)
CacheManager.deleteMemory("${domain}_cookie")
} }
override fun cookieToMap(cookie: String): MutableMap<String, String> { override fun cookieToMap(cookie: String): MutableMap<String, String> {

@ -18,6 +18,7 @@ import io.legado.app.databinding.ActivityBookSourceEditBinding
import io.legado.app.help.config.LocalConfig import io.legado.app.help.config.LocalConfig
import io.legado.app.lib.dialogs.SelectItem import io.legado.app.lib.dialogs.SelectItem
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.book.source.debug.BookSourceDebugActivity import io.legado.app.ui.book.source.debug.BookSourceDebugActivity
@ -47,7 +48,7 @@ class BookSourceEditActivity :
private val qrCodeResult = registerForActivityResult(QrCodeResult()) { private val qrCodeResult = registerForActivityResult(QrCodeResult()) {
it ?: return@registerForActivityResult it ?: return@registerForActivityResult
viewModel.importSource(it) { source -> viewModel.importSource(it) { source ->
upRecyclerView(source) upSourceView(source)
} }
} }
private val selectDoc = registerForActivityResult(HandleFileContract()) { private val selectDoc = registerForActivityResult(HandleFileContract()) {
@ -68,7 +69,7 @@ class BookSourceEditActivity :
softKeyboardTool.attachToWindow(window) softKeyboardTool.attachToWindow(window)
initView() initView()
viewModel.initData(intent) { viewModel.initData(intent) {
upRecyclerView() upSourceView()
} }
} }
@ -109,9 +110,10 @@ class BookSourceEditActivity :
} }
} }
} }
R.id.menu_clear_cookie -> viewModel.clearCookie(getSource().bookSourceUrl)
R.id.menu_auto_complete -> viewModel.autoComplete = !viewModel.autoComplete R.id.menu_auto_complete -> viewModel.autoComplete = !viewModel.autoComplete
R.id.menu_copy_source -> sendToClip(GSON.toJson(getSource())) R.id.menu_copy_source -> sendToClip(GSON.toJson(getSource()))
R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } R.id.menu_paste_source -> viewModel.pasteSource { upSourceView(it) }
R.id.menu_qr_code_camera -> qrCodeResult.launch() R.id.menu_qr_code_camera -> qrCodeResult.launch()
R.id.menu_share_str -> share(GSON.toJson(getSource())) R.id.menu_share_str -> share(GSON.toJson(getSource()))
R.id.menu_share_qr -> shareWithQr( R.id.menu_share_qr -> shareWithQr(
@ -139,6 +141,7 @@ class BookSourceEditActivity :
binding.recyclerView.layoutManager = LinearLayoutManager(this) binding.recyclerView.layoutManager = LinearLayoutManager(this)
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
binding.tabLayout.setBackgroundColor(backgroundColor) binding.tabLayout.setBackgroundColor(backgroundColor)
binding.tabLayout.setSelectedTabIndicatorColor(accentColor)
binding.tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { binding.tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabReselected(tab: TabLayout.Tab?) { override fun onTabReselected(tab: TabLayout.Tab?) {
@ -186,7 +189,7 @@ class BookSourceEditActivity :
binding.recyclerView.scrollToPosition(0) binding.recyclerView.scrollToPosition(0)
} }
private fun upRecyclerView(source: BookSource? = viewModel.bookSource) { private fun upSourceView(source: BookSource? = viewModel.bookSource) {
source?.let { source?.let {
binding.cbIsEnable.isChecked = it.enabled binding.cbIsEnable.isChecked = it.enabled
binding.cbIsEnableFind.isChecked = it.enabledExplore binding.cbIsEnableFind.isChecked = it.enabledExplore

@ -7,6 +7,7 @@ import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.exception.NoStackTraceException import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.RuleComplete import io.legado.app.help.RuleComplete
import io.legado.app.help.http.CookieStore
import io.legado.app.help.http.newCallStrResponse import io.legado.app.help.http.newCallStrResponse
import io.legado.app.help.http.okHttpClient import io.legado.app.help.http.okHttpClient
import io.legado.app.utils.* import io.legado.app.utils.*
@ -95,6 +96,12 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat
} }
} }
fun clearCookie(url: String) {
execute {
CookieStore.removeCookie(url)
}
}
fun ruleComplete(rule: String?, preRule: String? = null, type: Int = 1): String? { fun ruleComplete(rule: String?, preRule: String? = null, type: Int = 1): String? {
if (autoComplete) { if (autoComplete) {
return RuleComplete.autoComplete(rule, preRule, type) return RuleComplete.autoComplete(rule, preRule, type)

@ -48,7 +48,7 @@ class RssSourceEditActivity :
private val qrCodeResult = registerForActivityResult(QrCodeResult()) { private val qrCodeResult = registerForActivityResult(QrCodeResult()) {
it?.let { it?.let {
viewModel.importSource(it) { source: RssSource -> viewModel.importSource(it) { source: RssSource ->
upRecyclerView(source) upSourceView(source)
} }
} }
} }
@ -57,7 +57,7 @@ class RssSourceEditActivity :
softKeyboardTool.attachToWindow(window) softKeyboardTool.attachToWindow(window)
initView() initView()
viewModel.initData(intent) { viewModel.initData(intent) {
upRecyclerView() upSourceView()
} }
} }
@ -130,10 +130,11 @@ class RssSourceEditActivity :
} }
} }
} }
R.id.menu_clear_cookie -> viewModel.clearCookie(getRssSource().sourceUrl)
R.id.menu_auto_complete -> viewModel.autoComplete = !viewModel.autoComplete R.id.menu_auto_complete -> viewModel.autoComplete = !viewModel.autoComplete
R.id.menu_copy_source -> sendToClip(GSON.toJson(getRssSource())) R.id.menu_copy_source -> sendToClip(GSON.toJson(getRssSource()))
R.id.menu_qr_code_camera -> qrCodeResult.launch() R.id.menu_qr_code_camera -> qrCodeResult.launch()
R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } R.id.menu_paste_source -> viewModel.pasteSource { upSourceView(it) }
R.id.menu_share_str -> share(GSON.toJson(getRssSource())) R.id.menu_share_str -> share(GSON.toJson(getRssSource()))
R.id.menu_share_qr -> shareWithQr( R.id.menu_share_qr -> shareWithQr(
GSON.toJson(getRssSource()), GSON.toJson(getRssSource()),
@ -150,10 +151,11 @@ class RssSourceEditActivity :
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
} }
private fun upRecyclerView(source: RssSource? = viewModel.rssSource) { private fun upSourceView(source: RssSource? = viewModel.rssSource) {
source?.let { source?.let {
binding.cbIsEnable.isChecked = source.enabled binding.cbIsEnable.isChecked = source.enabled
binding.cbSingleUrl.isChecked = source.singleUrl binding.cbSingleUrl.isChecked = source.singleUrl
binding.cbIsEnableCookie.isChecked = source.enabledCookieJar == true
binding.cbEnableJs.isChecked = source.enableJs binding.cbEnableJs.isChecked = source.enableJs
binding.cbEnableBaseUrl.isChecked = source.loadWithBaseUrl binding.cbEnableBaseUrl.isChecked = source.loadWithBaseUrl
} }
@ -191,6 +193,7 @@ class RssSourceEditActivity :
val source = viewModel.rssSource val source = viewModel.rssSource
source.enabled = binding.cbIsEnable.isChecked source.enabled = binding.cbIsEnable.isChecked
source.singleUrl = binding.cbSingleUrl.isChecked source.singleUrl = binding.cbSingleUrl.isChecked
source.enabledCookieJar = binding.cbIsEnableCookie.isChecked
source.enableJs = binding.cbEnableJs.isChecked source.enableJs = binding.cbEnableJs.isChecked
source.loadWithBaseUrl = binding.cbEnableBaseUrl.isChecked source.loadWithBaseUrl = binding.cbEnableBaseUrl.isChecked
sourceEntities.forEach { sourceEntities.forEach {

@ -6,6 +6,7 @@ import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.help.RuleComplete import io.legado.app.help.RuleComplete
import io.legado.app.help.http.CookieStore
import io.legado.app.utils.getClipText import io.legado.app.utils.getClipText
import io.legado.app.utils.msg import io.legado.app.utils.msg
import io.legado.app.utils.printOnDebug import io.legado.app.utils.printOnDebug
@ -77,6 +78,12 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati
} }
} }
fun clearCookie(url: String) {
execute {
CookieStore.removeCookie(url)
}
}
fun ruleComplete(rule: String?, preRule: String? = null, type: Int = 1): String? { fun ruleComplete(rule: String?, preRule: String? = null, type: Int = 1): String? {
if (autoComplete) { if (autoComplete) {
return RuleComplete.autoComplete(rule, preRule, type) return RuleComplete.autoComplete(rule, preRule, type)

@ -15,6 +15,7 @@ import android.widget.FrameLayout.LayoutParams
import androidx.appcompat.widget.AppCompatTextView import androidx.appcompat.widget.AppCompatTextView
import io.legado.app.R import io.legado.app.R
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.ColorUtils
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor
import io.legado.app.utils.invisible import io.legado.app.utils.invisible
import io.legado.app.utils.visible import io.legado.app.utils.visible
@ -87,8 +88,6 @@ class BadgeView @JvmOverloads constructor(
setLayoutParams(layoutParams) setLayoutParams(layoutParams)
} }
// set default font
setTextColor(Color.WHITE)
//setTypeface(Typeface.DEFAULT_BOLD); //setTypeface(Typeface.DEFAULT_BOLD);
setTextSize(TypedValue.COMPLEX_UNIT_SP, 11f) setTextSize(TypedValue.COMPLEX_UNIT_SP, 11f)
setPadding(dip2Px(5f), dip2Px(1f), dip2Px(5f), dip2Px(1f)) setPadding(dip2Px(5f), dip2Px(1f), dip2Px(5f), dip2Px(1f))
@ -106,6 +105,10 @@ class BadgeView @JvmOverloads constructor(
minHeight = dip2Px(16f) minHeight = dip2Px(16f)
} }
override fun setBackgroundColor(color: Int) {
setBackground(radius, color)
}
fun setBackground(dipRadius: Float, badgeColor: Int) { fun setBackground(dipRadius: Float, badgeColor: Int) {
val radius = dip2Px(dipRadius).toFloat() val radius = dip2Px(dipRadius).toFloat()
val radiusArray = val radiusArray =
@ -118,10 +121,13 @@ class BadgeView @JvmOverloads constructor(
val bgDrawable = ShapeDrawable(roundRect) val bgDrawable = ShapeDrawable(roundRect)
bgDrawable.paint.color = badgeColor bgDrawable.paint.color = badgeColor
background = bgDrawable background = bgDrawable
} setTextColor(
if (ColorUtils.isColorLight(badgeColor)) {
fun setBackground(badgeColor: Int) { Color.BLACK
setBackground(radius, badgeColor) } else {
Color.WHITE
}
)
} }
/** /**
@ -142,9 +148,9 @@ class BadgeView @JvmOverloads constructor(
fun setHighlight(highlight: Boolean) { fun setHighlight(highlight: Boolean) {
if (highlight) { if (highlight) {
setBackground(context.accentColor) setBackgroundColor(context.accentColor)
} else { } else {
setBackground(context.getCompatColor(R.color.darker_gray)) setBackgroundColor(context.getCompatColor(R.color.darker_gray))
} }
} }

@ -45,6 +45,13 @@
android:text="@string/single_url" android:text="@string/single_url"
tools:ignore="TouchTargetSizeCheck" /> tools:ignore="TouchTargetSizeCheck" />
<io.legado.app.lib.theme.view.ThemeCheckBox
android:id="@+id/cb_is_enable_cookie"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/auto_save_cookie" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout

@ -21,6 +21,11 @@
android:title="@string/login" android:title="@string/login"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/menu_clear_cookie"
android:title="@string/cookie"
app:showAsAction="never" />
<item <item
android:id="@+id/menu_auto_complete" android:id="@+id/menu_auto_complete"
android:title="@string/auto_complete" android:title="@string/auto_complete"

@ -980,5 +980,6 @@
<string name="import_txt_toc_rule">导入txt目录规则</string> <string name="import_txt_toc_rule">导入txt目录规则</string>
<string name="auto_save_cookie">CookieJar</string> <string name="auto_save_cookie">CookieJar</string>
<string name="click_read_button_load">点击阅读加载目录</string> <string name="click_read_button_load">点击阅读加载目录</string>
<string name="cookie">清除cookie</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -983,5 +983,6 @@
<string name="import_txt_toc_rule">导入txt目录规则</string> <string name="import_txt_toc_rule">导入txt目录规则</string>
<string name="auto_save_cookie">CookieJar</string> <string name="auto_save_cookie">CookieJar</string>
<string name="click_read_button_load">点击阅读加载目录</string> <string name="click_read_button_load">点击阅读加载目录</string>
<string name="cookie">清除cookie</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -983,5 +983,6 @@
<string name="import_txt_toc_rule">导入txt目录规则</string> <string name="import_txt_toc_rule">导入txt目录规则</string>
<string name="auto_save_cookie">CookieJar</string> <string name="auto_save_cookie">CookieJar</string>
<string name="click_read_button_load">点击阅读加载目录</string> <string name="click_read_button_load">点击阅读加载目录</string>
<string name="cookie">清除cookie</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -980,5 +980,6 @@
<string name="import_txt_toc_rule">导入txt目录规则</string> <string name="import_txt_toc_rule">导入txt目录规则</string>
<string name="auto_save_cookie">CookieJar</string> <string name="auto_save_cookie">CookieJar</string>
<string name="click_read_button_load">点击阅读加载目录</string> <string name="click_read_button_load">点击阅读加载目录</string>
<string name="cookie">清除cookie</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -982,5 +982,6 @@
<string name="import_txt_toc_rule">导入txt目录规则</string> <string name="import_txt_toc_rule">导入txt目录规则</string>
<string name="auto_save_cookie">CookieJar</string> <string name="auto_save_cookie">CookieJar</string>
<string name="click_read_button_load">点击阅读加载目录</string> <string name="click_read_button_load">点击阅读加载目录</string>
<string name="cookie">清除cookie</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -982,5 +982,6 @@
<string name="import_txt_toc_rule">导入txt目录规则</string> <string name="import_txt_toc_rule">导入txt目录规则</string>
<string name="auto_save_cookie">CookieJar</string> <string name="auto_save_cookie">CookieJar</string>
<string name="click_read_button_load">点击阅读加载目录</string> <string name="click_read_button_load">点击阅读加载目录</string>
<string name="cookie">清除cookie</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -983,5 +983,6 @@
<string name="import_txt_toc_rule">导入txt目录规则</string> <string name="import_txt_toc_rule">导入txt目录规则</string>
<string name="auto_save_cookie">CookieJar</string> <string name="auto_save_cookie">CookieJar</string>
<string name="click_read_button_load">点击阅读加载目录</string> <string name="click_read_button_load">点击阅读加载目录</string>
<string name="cookie">清除cookie</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

Loading…
Cancel
Save