diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6328e86ea..da98accad 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ + xmlns:tools="http://schemas.android.com/tools" + package="io.legado.app"> diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 48cdffac7..18a4c3080 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -14,7 +14,9 @@ **2022/05/13** -* 书源编辑添加cookieJar选项 +* 源编辑添加cookieJar选项 +* 源编辑菜单里添加清除cookie,如果之前能用的书源不能用了,可以关闭cookieJar后点下菜单里的清除cookie后再试 +* 书源支持文件类型 by Xwite **2022/05/11** diff --git a/app/src/main/java/io/legado/app/constant/BookType.kt b/app/src/main/java/io/legado/app/constant/BookType.kt index 13c21f4ae..55b1c442f 100644 --- a/app/src/main/java/io/legado/app/constant/BookType.kt +++ b/app/src/main/java/io/legado/app/constant/BookType.kt @@ -11,6 +11,6 @@ object BookType { @Target(AnnotationTarget.VALUE_PARAMETER) @Retention(AnnotationRetention.SOURCE) - @IntDef(default, audio, image) + @IntDef(default, audio, image, file) annotation class Type } \ No newline at end of file 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 b19c1feca..be94137fa 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 @@ -56,8 +56,8 @@ object CookieStore : CookieManager { override fun removeCookie(url: String) { val domain = NetworkUtils.getSubDomain(url) - CacheManager.deleteMemory("${domain}_cookie") appDb.cookieDao.delete(domain) + CacheManager.deleteMemory("${domain}_cookie") } override fun cookieToMap(cookie: String): MutableMap { diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index 9fe743bad..ab93ccc0e 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -18,6 +18,7 @@ import io.legado.app.databinding.ActivityBookSourceEditBinding import io.legado.app.help.config.LocalConfig import io.legado.app.lib.dialogs.SelectItem 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.primaryColor import io.legado.app.ui.book.source.debug.BookSourceDebugActivity @@ -47,7 +48,7 @@ class BookSourceEditActivity : private val qrCodeResult = registerForActivityResult(QrCodeResult()) { it ?: return@registerForActivityResult viewModel.importSource(it) { source -> - upRecyclerView(source) + upSourceView(source) } } private val selectDoc = registerForActivityResult(HandleFileContract()) { @@ -68,7 +69,7 @@ class BookSourceEditActivity : softKeyboardTool.attachToWindow(window) initView() 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_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_share_str -> share(GSON.toJson(getSource())) R.id.menu_share_qr -> shareWithQr( @@ -139,6 +141,7 @@ class BookSourceEditActivity : binding.recyclerView.layoutManager = LinearLayoutManager(this) binding.recyclerView.adapter = adapter binding.tabLayout.setBackgroundColor(backgroundColor) + binding.tabLayout.setSelectedTabIndicatorColor(accentColor) binding.tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { override fun onTabReselected(tab: TabLayout.Tab?) { @@ -186,7 +189,7 @@ class BookSourceEditActivity : binding.recyclerView.scrollToPosition(0) } - private fun upRecyclerView(source: BookSource? = viewModel.bookSource) { + private fun upSourceView(source: BookSource? = viewModel.bookSource) { source?.let { binding.cbIsEnable.isChecked = it.enabled binding.cbIsEnableFind.isChecked = it.enabledExplore diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt index 3bf1e3562..d9fe5ca83 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt @@ -7,6 +7,7 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.BookSource import io.legado.app.exception.NoStackTraceException 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.okHttpClient 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? { if (autoComplete) { return RuleComplete.autoComplete(rule, preRule, type) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 9d9fe765b..01bd4bbe6 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -48,7 +48,7 @@ class RssSourceEditActivity : private val qrCodeResult = registerForActivityResult(QrCodeResult()) { it?.let { viewModel.importSource(it) { source: RssSource -> - upRecyclerView(source) + upSourceView(source) } } } @@ -57,7 +57,7 @@ class RssSourceEditActivity : softKeyboardTool.attachToWindow(window) initView() 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_copy_source -> sendToClip(GSON.toJson(getRssSource())) 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_qr -> shareWithQr( GSON.toJson(getRssSource()), @@ -150,10 +151,11 @@ class RssSourceEditActivity : binding.recyclerView.adapter = adapter } - private fun upRecyclerView(source: RssSource? = viewModel.rssSource) { + private fun upSourceView(source: RssSource? = viewModel.rssSource) { source?.let { binding.cbIsEnable.isChecked = source.enabled binding.cbSingleUrl.isChecked = source.singleUrl + binding.cbIsEnableCookie.isChecked = source.enabledCookieJar == true binding.cbEnableJs.isChecked = source.enableJs binding.cbEnableBaseUrl.isChecked = source.loadWithBaseUrl } @@ -191,6 +193,7 @@ class RssSourceEditActivity : val source = viewModel.rssSource source.enabled = binding.cbIsEnable.isChecked source.singleUrl = binding.cbSingleUrl.isChecked + source.enabledCookieJar = binding.cbIsEnableCookie.isChecked source.enableJs = binding.cbEnableJs.isChecked source.loadWithBaseUrl = binding.cbEnableBaseUrl.isChecked sourceEntities.forEach { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index 25002eb3a..da911a5f4 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -6,6 +6,7 @@ import io.legado.app.base.BaseViewModel import io.legado.app.data.appDb import io.legado.app.data.entities.RssSource import io.legado.app.help.RuleComplete +import io.legado.app.help.http.CookieStore import io.legado.app.utils.getClipText import io.legado.app.utils.msg 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? { if (autoComplete) { return RuleComplete.autoComplete(rule, preRule, type) diff --git a/app/src/main/java/io/legado/app/ui/widget/text/BadgeView.kt b/app/src/main/java/io/legado/app/ui/widget/text/BadgeView.kt index c83147618..c198a8f4b 100644 --- a/app/src/main/java/io/legado/app/ui/widget/text/BadgeView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/text/BadgeView.kt @@ -15,6 +15,7 @@ import android.widget.FrameLayout.LayoutParams import androidx.appcompat.widget.AppCompatTextView import io.legado.app.R import io.legado.app.lib.theme.accentColor +import io.legado.app.utils.ColorUtils import io.legado.app.utils.getCompatColor import io.legado.app.utils.invisible import io.legado.app.utils.visible @@ -87,8 +88,6 @@ class BadgeView @JvmOverloads constructor( setLayoutParams(layoutParams) } - // set default font - setTextColor(Color.WHITE) //setTypeface(Typeface.DEFAULT_BOLD); setTextSize(TypedValue.COMPLEX_UNIT_SP, 11f) setPadding(dip2Px(5f), dip2Px(1f), dip2Px(5f), dip2Px(1f)) @@ -106,6 +105,10 @@ class BadgeView @JvmOverloads constructor( minHeight = dip2Px(16f) } + override fun setBackgroundColor(color: Int) { + setBackground(radius, color) + } + fun setBackground(dipRadius: Float, badgeColor: Int) { val radius = dip2Px(dipRadius).toFloat() val radiusArray = @@ -118,10 +121,13 @@ class BadgeView @JvmOverloads constructor( val bgDrawable = ShapeDrawable(roundRect) bgDrawable.paint.color = badgeColor background = bgDrawable - } - - fun setBackground(badgeColor: Int) { - setBackground(radius, badgeColor) + setTextColor( + if (ColorUtils.isColorLight(badgeColor)) { + Color.BLACK + } else { + Color.WHITE + } + ) } /** @@ -142,9 +148,9 @@ class BadgeView @JvmOverloads constructor( fun setHighlight(highlight: Boolean) { if (highlight) { - setBackground(context.accentColor) + setBackgroundColor(context.accentColor) } else { - setBackground(context.getCompatColor(R.color.darker_gray)) + setBackgroundColor(context.getCompatColor(R.color.darker_gray)) } } diff --git a/app/src/main/res/layout/activity_rss_source_edit.xml b/app/src/main/res/layout/activity_rss_source_edit.xml index d839b5170..6baf96b5f 100644 --- a/app/src/main/res/layout/activity_rss_source_edit.xml +++ b/app/src/main/res/layout/activity_rss_source_edit.xml @@ -45,6 +45,13 @@ android:text="@string/single_url" tools:ignore="TouchTargetSizeCheck" /> + + + + 导入txt目录规则 CookieJar 点击阅读加载目录 + 清除cookie diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 06cff97fc..1cfcb0d47 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -983,5 +983,6 @@ 导入txt目录规则 CookieJar 点击阅读加载目录 + 清除cookie diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 09cc15699..1293cedc9 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -983,5 +983,6 @@ 导入txt目录规则 CookieJar 点击阅读加载目录 + 清除cookie diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index eb359a20f..94805b80d 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -980,5 +980,6 @@ 导入txt目录规则 CookieJar 点击阅读加载目录 + 清除cookie diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 8ae5eaca7..7dea2e10e 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -982,5 +982,6 @@ 导入txt目录规则 CookieJar 点击阅读加载目录 + 清除cookie diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index a9a530cc1..b20df127c 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -982,5 +982,6 @@ 导入txt目录规则 CookieJar 点击阅读加载目录 + 清除cookie diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3243f3d87..6799fca04 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -983,5 +983,6 @@ 导入txt目录规则 CookieJar 点击阅读加载目录 + 清除cookie