diff --git a/app/build.gradle b/app/build.gradle index e9bb04249..a75be02e8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,8 +15,8 @@ def version = "3." + releaseTime() def gitCommits = Integer.parseInt('git rev-list HEAD --count'.execute().text.trim()) android { - compileSdkVersion 31 - buildToolsVersion '31.0.0' + compileSdkVersion 32 + buildToolsVersion '32.0.0' kotlinOptions { jvmTarget = "11" } @@ -38,7 +38,7 @@ android { defaultConfig { applicationId "io.legado.app" minSdkVersion 21 - targetSdkVersion 31 + targetSdkVersion 32 versionCode 10000 + gitCommits versionName version testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index d15b2c493..48cdffac7 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -11,13 +11,20 @@ * 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。 * 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源! + **2022/05/13** * 书源编辑添加cookieJar选项 +**2022/05/11** + +* 修复替换报错的bug +* 优化目录界面替换 + **2022/05/10** * 更新cronet: 101.0.4951.61 +* 更新到SDK 32 * js添加 getVerificationCode startBrowserAwait * 监测网络变化及时更新web服务的IP * 优化在线tts导入 diff --git a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt index 124261a3f..ab840ce89 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt @@ -7,6 +7,7 @@ import androidx.room.Ignore import androidx.room.Index import com.github.liuyueyi.quick.transfer.ChineseUtils import io.legado.app.R +import io.legado.app.constant.AppLog import io.legado.app.constant.AppPattern import io.legado.app.data.appDb import io.legado.app.exception.RegexTimeoutException @@ -15,6 +16,7 @@ import io.legado.app.help.config.AppConfig import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.RuleDataInterface import io.legado.app.utils.* +import kotlinx.coroutines.CancellationException import kotlinx.parcelize.IgnoredOnParcel import kotlinx.parcelize.Parcelize import splitties.init.appCtx @@ -93,7 +95,7 @@ data class BookChapter( 2 -> displayTitle = ChineseUtils.s2t(displayTitle) } } - if (useReplace && replaceRules != null) { + if (useReplace && replaceRules != null) kotlin.run { replaceRules.forEach { item -> if (item.pattern.isNotEmpty()) { try { @@ -112,7 +114,10 @@ data class BookChapter( } catch (e: RegexTimeoutException) { item.isEnabled = false appDb.replaceRuleDao.update(item) + } catch (e: CancellationException) { + return@run } catch (e: Exception) { + AppLog.put("${item.name}替换出错\n替换内容\n${displayTitle}", e) appCtx.toastOnUi("${item.name}替换出错") } } diff --git a/app/src/main/java/io/legado/app/help/ContentProcessor.kt b/app/src/main/java/io/legado/app/help/ContentProcessor.kt index e841f8844..466b348a6 100644 --- a/app/src/main/java/io/legado/app/help/ContentProcessor.kt +++ b/app/src/main/java/io/legado/app/help/ContentProcessor.kt @@ -12,6 +12,7 @@ import io.legado.app.help.config.ReadBookConfig import io.legado.app.utils.msg import io.legado.app.utils.replace import io.legado.app.utils.toastOnUi +import kotlinx.coroutines.CancellationException import splitties.init.appCtx import java.lang.ref.WeakReference import java.util.concurrent.CopyOnWriteArrayList @@ -135,7 +136,7 @@ class ContentProcessor private constructor( var mContent = content getContentReplaceRules().forEach { item -> if (item.pattern.isNotEmpty()) { - kotlin.runCatching { + try { mContent = if (item.isRegex) { mContent.replace( item.pattern.toRegex(), @@ -145,18 +146,15 @@ class ContentProcessor private constructor( } else { mContent.replace(item.pattern, item.replacement) } - }.onFailure { - when (it) { - is RegexTimeoutException -> { - item.isEnabled = false - appDb.replaceRuleDao.update(item) - return item.name + it.msg - } - else -> { - AppLog.put("${item.name}替换出错\n${it.localizedMessage}", it) - appCtx.toastOnUi("${item.name}替换出错") - } - } + } catch (e: RegexTimeoutException) { + item.isEnabled = false + appDb.replaceRuleDao.update(item) + return item.name + e.msg + } catch (e: CancellationException) { + return mContent + } catch (e: Exception) { + AppLog.put("${item.name}替换出错\n替换内容\n${mContent}", e) + appCtx.toastOnUi("${item.name}替换出错") } } } diff --git a/app/src/main/java/io/legado/app/help/ReplaceAnalyzer.kt b/app/src/main/java/io/legado/app/help/ReplaceAnalyzer.kt index a8e126f9e..d714363b1 100644 --- a/app/src/main/java/io/legado/app/help/ReplaceAnalyzer.kt +++ b/app/src/main/java/io/legado/app/help/ReplaceAnalyzer.kt @@ -1,43 +1,47 @@ package io.legado.app.help import io.legado.app.data.entities.ReplaceRule +import io.legado.app.exception.NoStackTraceException import io.legado.app.utils.* object ReplaceAnalyzer { - fun jsonToReplaceRules(json: String): List { - val replaceRules = mutableListOf() - val items: List> = jsonPath.parse(json).read("$") - for (item in items) { - val jsonItem = jsonPath.parse(item) - jsonToReplaceRule(jsonItem.jsonString())?.let { - if (it.isValid()) { - replaceRules.add(it) + fun jsonToReplaceRules(json: String): Result> { + return kotlin.runCatching { + val replaceRules = mutableListOf() + val items: List> = jsonPath.parse(json).read("$") + for (item in items) { + val jsonItem = jsonPath.parse(item) + jsonToReplaceRule(jsonItem.jsonString()).getOrThrow().let { + if (it.isValid()) { + replaceRules.add(it) + } } } + replaceRules } - return replaceRules } - private fun jsonToReplaceRule(json: String): ReplaceRule? { - val replaceRule: ReplaceRule? = GSON.fromJsonObject(json.trim()).getOrNull() - runCatching { + fun jsonToReplaceRule(json: String): Result { + return runCatching { + val replaceRule: ReplaceRule? = + GSON.fromJsonObject(json.trim()).getOrNull() if (replaceRule == null || replaceRule.pattern.isBlank()) { val jsonItem = jsonPath.parse(json.trim()) val rule = ReplaceRule() rule.id = jsonItem.readLong("$.id") ?: System.currentTimeMillis() rule.pattern = jsonItem.readString("$.regex") ?: "" - if (rule.pattern.isEmpty()) return null + if (rule.pattern.isEmpty()) throw NoStackTraceException("格式不对") rule.name = jsonItem.readString("$.replaceSummary") ?: "" rule.replacement = jsonItem.readString("$.replacement") ?: "" rule.isRegex = jsonItem.readBool("$.isRegex") == true rule.scope = jsonItem.readString("$.useTo") rule.isEnabled = jsonItem.readBool("$.enable") == true rule.order = jsonItem.readInt("$.serialNumber") ?: 0 - return rule + return@runCatching rule } + return@runCatching replaceRule } - return replaceRule } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/http/BackstageWebView.kt b/app/src/main/java/io/legado/app/help/http/BackstageWebView.kt index 1ed16c894..c90e25179 100644 --- a/app/src/main/java/io/legado/app/help/http/BackstageWebView.kt +++ b/app/src/main/java/io/legado/app/help/http/BackstageWebView.kt @@ -18,6 +18,7 @@ import org.apache.commons.text.StringEscapeUtils import splitties.init.appCtx import java.lang.ref.WeakReference import kotlin.coroutines.resume +import kotlin.coroutines.resumeWithException /** * 后台webView @@ -50,14 +51,14 @@ class BackstageWebView( override fun onError(error: Throwable) { if (!block.isCompleted) - block.cancel(error) + block.resumeWithException(error) } } runOnUI { try { load() } catch (error: Throwable) { - block.cancel(error) + block.resumeWithException(error) } } } 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 ace5ac5ca..b19c1feca 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 @@ -5,8 +5,8 @@ package io.legado.app.help.http import android.text.TextUtils import io.legado.app.data.appDb import io.legado.app.data.entities.Cookie -import io.legado.app.help.http.api.CookieManager import io.legado.app.help.CacheManager +import io.legado.app.help.http.api.CookieManager import io.legado.app.utils.NetworkUtils object CookieStore : CookieManager { @@ -44,7 +44,7 @@ object CookieStore : CookieManager { CacheManager.getFromMemory("${domain}_cookie")?.let { return it } val cookieBean = appDb.cookieDao.get(domain) val cookie = cookieBean?.cookie ?: "" - CacheManager.putMemory(url, cookie ?: "") + CacheManager.putMemory(url, cookie) return cookie } diff --git a/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt b/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt index 1a10c0280..6d4eda465 100644 --- a/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt +++ b/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt @@ -98,9 +98,12 @@ object ImportOldData { } private fun importOldReplaceRule(json: String): Int { - val rules = ReplaceAnalyzer.jsonToReplaceRules(json) - appDb.replaceRuleDao.insert(*rules.toTypedArray()) - return rules.size + val rules = ReplaceAnalyzer.jsonToReplaceRules(json).getOrNull() + rules?.let { + appDb.replaceRuleDao.insert(*rules.toTypedArray()) + return rules.size + } + return 0 } private fun fromOldBooks(json: String): List { diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt b/app/src/main/java/io/legado/app/lib/prefs/ColorPreference.kt similarity index 99% rename from app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt rename to app/src/main/java/io/legado/app/lib/prefs/ColorPreference.kt index 806cb9ac9..3ea1181a1 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt +++ b/app/src/main/java/io/legado/app/lib/prefs/ColorPreference.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.widget.prefs +package io.legado.app.lib.prefs import android.content.Context import android.content.ContextWrapper @@ -118,7 +118,7 @@ class ColorPreference(context: Context, attrs: AttributeSet) : Preference(contex } override fun onBindViewHolder(holder: PreferenceViewHolder) { - val v = io.legado.app.ui.widget.prefs.Preference.bindView( + val v = io.legado.app.lib.prefs.Preference.bindView( context, holder, icon, title, summary, widgetLayoutResource, io.legado.app.R.id.cpv_preference_preview_color_panel, 30, 30 ) diff --git a/app/src/main/java/io/legado/app/lib/prefs/EditTextPreference.kt b/app/src/main/java/io/legado/app/lib/prefs/EditTextPreference.kt new file mode 100644 index 000000000..defe645a8 --- /dev/null +++ b/app/src/main/java/io/legado/app/lib/prefs/EditTextPreference.kt @@ -0,0 +1,36 @@ +package io.legado.app.lib.prefs + +import android.content.Context +import android.util.AttributeSet +import android.widget.TextView +import androidx.preference.EditTextPreference.OnBindEditTextListener +import androidx.preference.PreferenceViewHolder +import io.legado.app.R +import io.legado.app.lib.theme.accentColor +import io.legado.app.utils.applyTint + +class EditTextPreference(context: Context, attrs: AttributeSet) : + androidx.preference.EditTextPreference(context, attrs) { + + private var mOnBindEditTextListener: OnBindEditTextListener? = null + private val onBindEditTextListener = OnBindEditTextListener { editText -> + editText.applyTint(context.accentColor) + mOnBindEditTextListener?.onBindEditText(editText) + } + + init { + // isPersistent = true + layoutResource = R.layout.view_preference + super.setOnBindEditTextListener(onBindEditTextListener) + } + + override fun onBindViewHolder(holder: PreferenceViewHolder) { + Preference.bindView(context, holder, icon, title, summary, null, null) + super.onBindViewHolder(holder) + } + + override fun setOnBindEditTextListener(onBindEditTextListener: OnBindEditTextListener?) { + mOnBindEditTextListener = onBindEditTextListener + } + +} diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/EditTextPreferenceDialog.kt b/app/src/main/java/io/legado/app/lib/prefs/EditTextPreferenceDialog.kt similarity index 64% rename from app/src/main/java/io/legado/app/ui/widget/prefs/EditTextPreferenceDialog.kt rename to app/src/main/java/io/legado/app/lib/prefs/EditTextPreferenceDialog.kt index 06a6bb960..70066e770 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/EditTextPreferenceDialog.kt +++ b/app/src/main/java/io/legado/app/lib/prefs/EditTextPreferenceDialog.kt @@ -1,9 +1,11 @@ -package io.legado.app.ui.widget.prefs +package io.legado.app.lib.prefs import android.app.Dialog import android.os.Bundle +import androidx.appcompat.app.AlertDialog import androidx.preference.EditTextPreferenceDialogFragmentCompat import androidx.preference.PreferenceDialogFragmentCompat +import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.filletBackground class EditTextPreferenceDialog : EditTextPreferenceDialogFragmentCompat() { @@ -23,6 +25,13 @@ class EditTextPreferenceDialog : EditTextPreferenceDialogFragmentCompat() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val dialog = super.onCreateDialog(savedInstanceState) dialog.window?.setBackgroundDrawable(requireContext().filletBackground) + dialog.window?.decorView?.post { + (dialog as AlertDialog).run { + getButton(AlertDialog.BUTTON_NEGATIVE)?.setTextColor(accentColor) + getButton(AlertDialog.BUTTON_POSITIVE)?.setTextColor(accentColor) + getButton(AlertDialog.BUTTON_NEUTRAL)?.setTextColor(accentColor) + } + } return dialog } diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt b/app/src/main/java/io/legado/app/lib/prefs/IconListPreference.kt similarity index 99% rename from app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt rename to app/src/main/java/io/legado/app/lib/prefs/IconListPreference.kt index de1718472..046d6d7d6 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt +++ b/app/src/main/java/io/legado/app/lib/prefs/IconListPreference.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.widget.prefs +package io.legado.app.lib.prefs import android.content.Context import android.content.ContextWrapper diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/ListPreferenceDialog.kt b/app/src/main/java/io/legado/app/lib/prefs/ListPreferenceDialog.kt similarity index 64% rename from app/src/main/java/io/legado/app/ui/widget/prefs/ListPreferenceDialog.kt rename to app/src/main/java/io/legado/app/lib/prefs/ListPreferenceDialog.kt index 3c324601e..7165ef744 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/ListPreferenceDialog.kt +++ b/app/src/main/java/io/legado/app/lib/prefs/ListPreferenceDialog.kt @@ -1,9 +1,11 @@ -package io.legado.app.ui.widget.prefs +package io.legado.app.lib.prefs import android.app.Dialog import android.os.Bundle +import androidx.appcompat.app.AlertDialog import androidx.preference.ListPreferenceDialogFragmentCompat import androidx.preference.PreferenceDialogFragmentCompat +import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.filletBackground class ListPreferenceDialog : ListPreferenceDialogFragmentCompat() { @@ -23,6 +25,13 @@ class ListPreferenceDialog : ListPreferenceDialogFragmentCompat() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val dialog = super.onCreateDialog(savedInstanceState) dialog.window?.setBackgroundDrawable(requireContext().filletBackground) + dialog.window?.decorView?.post { + (dialog as AlertDialog).run { + getButton(AlertDialog.BUTTON_NEGATIVE)?.setTextColor(accentColor) + getButton(AlertDialog.BUTTON_POSITIVE)?.setTextColor(accentColor) + getButton(AlertDialog.BUTTON_NEUTRAL)?.setTextColor(accentColor) + } + } return dialog } diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/MultiSelectListPreferenceDialog.kt b/app/src/main/java/io/legado/app/lib/prefs/MultiSelectListPreferenceDialog.kt similarity index 66% rename from app/src/main/java/io/legado/app/ui/widget/prefs/MultiSelectListPreferenceDialog.kt rename to app/src/main/java/io/legado/app/lib/prefs/MultiSelectListPreferenceDialog.kt index 62c057f74..c1ab77708 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/MultiSelectListPreferenceDialog.kt +++ b/app/src/main/java/io/legado/app/lib/prefs/MultiSelectListPreferenceDialog.kt @@ -1,9 +1,11 @@ -package io.legado.app.ui.widget.prefs +package io.legado.app.lib.prefs import android.app.Dialog import android.os.Bundle +import androidx.appcompat.app.AlertDialog import androidx.preference.MultiSelectListPreferenceDialogFragmentCompat import androidx.preference.PreferenceDialogFragmentCompat +import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.filletBackground class MultiSelectListPreferenceDialog : MultiSelectListPreferenceDialogFragmentCompat() { @@ -25,6 +27,13 @@ class MultiSelectListPreferenceDialog : MultiSelectListPreferenceDialogFragmentC override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val dialog = super.onCreateDialog(savedInstanceState) dialog.window?.setBackgroundDrawable(requireContext().filletBackground) + dialog.window?.decorView?.post { + (dialog as AlertDialog).run { + getButton(AlertDialog.BUTTON_NEGATIVE)?.setTextColor(accentColor) + getButton(AlertDialog.BUTTON_POSITIVE)?.setTextColor(accentColor) + getButton(AlertDialog.BUTTON_NEUTRAL)?.setTextColor(accentColor) + } + } return dialog } diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt b/app/src/main/java/io/legado/app/lib/prefs/NameListPreference.kt similarity index 97% rename from app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt rename to app/src/main/java/io/legado/app/lib/prefs/NameListPreference.kt index cf06ec6f8..8658c2ccc 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt +++ b/app/src/main/java/io/legado/app/lib/prefs/NameListPreference.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.widget.prefs +package io.legado.app.lib.prefs import android.content.Context import android.util.AttributeSet diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt b/app/src/main/java/io/legado/app/lib/prefs/Preference.kt similarity index 99% rename from app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt rename to app/src/main/java/io/legado/app/lib/prefs/Preference.kt index 6cd98ce18..6ed4c9cfc 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt +++ b/app/src/main/java/io/legado/app/lib/prefs/Preference.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.widget.prefs +package io.legado.app.lib.prefs import android.content.Context import android.graphics.drawable.Drawable diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/PreferenceCategory.kt b/app/src/main/java/io/legado/app/lib/prefs/PreferenceCategory.kt similarity index 98% rename from app/src/main/java/io/legado/app/ui/widget/prefs/PreferenceCategory.kt rename to app/src/main/java/io/legado/app/lib/prefs/PreferenceCategory.kt index 74ff487df..725fab609 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/PreferenceCategory.kt +++ b/app/src/main/java/io/legado/app/lib/prefs/PreferenceCategory.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.widget.prefs +package io.legado.app.lib.prefs import android.content.Context import android.util.AttributeSet diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt b/app/src/main/java/io/legado/app/lib/prefs/SwitchPreference.kt similarity index 97% rename from app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt rename to app/src/main/java/io/legado/app/lib/prefs/SwitchPreference.kt index 3c4e29aa9..d71e914b7 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt +++ b/app/src/main/java/io/legado/app/lib/prefs/SwitchPreference.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.widget.prefs +package io.legado.app.lib.prefs import android.content.Context import android.util.AttributeSet diff --git a/app/src/main/java/io/legado/app/base/BasePreferenceFragment.kt b/app/src/main/java/io/legado/app/lib/prefs/fragment/PreferenceFragment.kt similarity index 80% rename from app/src/main/java/io/legado/app/base/BasePreferenceFragment.kt rename to app/src/main/java/io/legado/app/lib/prefs/fragment/PreferenceFragment.kt index f444985e3..b18dbdece 100644 --- a/app/src/main/java/io/legado/app/base/BasePreferenceFragment.kt +++ b/app/src/main/java/io/legado/app/lib/prefs/fragment/PreferenceFragment.kt @@ -1,13 +1,13 @@ -package io.legado.app.base +package io.legado.app.lib.prefs.fragment import android.annotation.SuppressLint import androidx.fragment.app.DialogFragment import androidx.preference.* -import io.legado.app.ui.widget.prefs.EditTextPreferenceDialog -import io.legado.app.ui.widget.prefs.ListPreferenceDialog -import io.legado.app.ui.widget.prefs.MultiSelectListPreferenceDialog +import io.legado.app.lib.prefs.EditTextPreferenceDialog +import io.legado.app.lib.prefs.ListPreferenceDialog +import io.legado.app.lib.prefs.MultiSelectListPreferenceDialog -abstract class BasePreferenceFragment : PreferenceFragmentCompat() { +abstract class PreferenceFragment : PreferenceFragmentCompat() { private val dialogFragmentTag = "androidx.preference.PreferenceFragment.DIALOG" @@ -34,7 +34,7 @@ abstract class BasePreferenceFragment : PreferenceFragmentCompat() { return } - val f: DialogFragment = when (preference) { + val dialogFragment: DialogFragment = when (preference) { is EditTextPreference -> { EditTextPreferenceDialog.newInstance(preference.getKey()) } @@ -54,10 +54,9 @@ abstract class BasePreferenceFragment : PreferenceFragmentCompat() { } } @Suppress("DEPRECATION") - f.setTargetFragment(this, 0) + dialogFragment.setTargetFragment(this, 0) - f.show(parentFragmentManager, dialogFragmentTag) + dialogFragment.show(parentFragmentManager, dialogFragmentTag) } - } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/model/CacheBook.kt b/app/src/main/java/io/legado/app/model/CacheBook.kt index 92f61b1a5..79394d5c4 100644 --- a/app/src/main/java/io/legado/app/model/CacheBook.kt +++ b/app/src/main/java/io/legado/app/model/CacheBook.kt @@ -131,9 +131,9 @@ object CacheBook { class CacheBookModel(var bookSource: BookSource, var book: Book) { - private val waitDownloadSet = hashSetOf() - private val onDownloadSet = hashSetOf() - private val successDownloadSet = hashSetOf() + private val waitDownloadSet = linkedSetOf() + private val onDownloadSet = linkedSetOf() + private val successDownloadSet = linkedSetOf() private val errorDownloadMap = hashMapOf() val waitCount get() = waitDownloadSet.size @@ -174,7 +174,7 @@ object CacheBook { } onDownloadSet.remove(index) //重试3次 - if (errorDownloadMap[index] ?: 0 < 3) { + if ((errorDownloadMap[index] ?: 0) < 3) { waitDownloadSet.add(index) } else { AppLog.put( diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index 65c57af4d..e17780c35 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -537,8 +537,7 @@ class AnalyzeUrl( val cookieMap = CookieStore.cookieToMap(cookie) val customCookieMap = CookieStore.cookieToMap(headerMap["Cookie"] ?: "") cookieMap.putAll(customCookieMap) - val newCookie = CookieStore.mapToCookie(cookieMap) - newCookie?.let { + CookieStore.mapToCookie(cookieMap)?.let { headerMap.put("Cookie", it) } } diff --git a/app/src/main/java/io/legado/app/ui/association/ImportHttpTtsViewModel.kt b/app/src/main/java/io/legado/app/ui/association/ImportHttpTtsViewModel.kt index d4628cf0d..52bdd597c 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportHttpTtsViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportHttpTtsViewModel.kt @@ -61,21 +61,7 @@ class ImportHttpTtsViewModel(app: Application) : BaseViewModel(app) { fun importSource(text: String) { execute { - val mText = text.trim() - when { - mText.isJsonObject() -> { - HttpTTS.fromJson(mText).getOrThrow().let { - allSources.add(it) - } - } - mText.isJsonArray() -> HttpTTS.fromJsonArray(mText).getOrThrow().let { items -> - allSources.addAll(items) - } - mText.isAbsUrl() -> { - importSourceUrl(mText) - } - else -> throw NoStackTraceException(context.getString(R.string.wrong_format)) - } + importSourceAwait(text.trim()) }.onError { it.printOnDebug() errorLiveData.postValue(it.localizedMessage ?: "") @@ -84,11 +70,28 @@ class ImportHttpTtsViewModel(app: Application) : BaseViewModel(app) { } } + private suspend fun importSourceAwait(text: String) { + when { + text.isJsonObject() -> { + HttpTTS.fromJson(text).getOrThrow().let { + allSources.add(it) + } + } + text.isJsonArray() -> HttpTTS.fromJsonArray(text).getOrThrow().let { items -> + allSources.addAll(items) + } + text.isAbsUrl() -> { + importSourceUrl(text) + } + else -> throw NoStackTraceException(context.getString(R.string.wrong_format)) + } + } + private suspend fun importSourceUrl(url: String) { okHttpClient.newCallResponseBody { url(url) }.text().let { - allSources.addAll(HttpTTS.fromJsonArray(it).getOrThrow()) + importSourceAwait(it) } } diff --git a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt index 895b0f8eb..e2d7474da 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt @@ -88,14 +88,14 @@ class ImportReplaceRuleDialog() : BaseDialogFragment(R.layout.dialog_recycler_vi adapter.notifyDataSetChanged() upSelectText() } - viewModel.errorLiveData.observe(this, { + viewModel.errorLiveData.observe(this) { binding.rotateLoading.hide() binding.tvMsg.apply { text = it visible() } - }) - viewModel.successLiveData.observe(this, { + } + viewModel.successLiveData.observe(this) { binding.rotateLoading.hide() if (it > 0) { adapter.setItems(viewModel.allRules) @@ -106,7 +106,7 @@ class ImportReplaceRuleDialog() : BaseDialogFragment(R.layout.dialog_recycler_vi visible() } } - }) + } val source = arguments?.getString("source") if (source.isNullOrEmpty()) { dismiss() diff --git a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleViewModel.kt index 448e79be9..a4e050f22 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleViewModel.kt @@ -6,12 +6,15 @@ import io.legado.app.base.BaseViewModel import io.legado.app.constant.AppPattern import io.legado.app.data.appDb import io.legado.app.data.entities.ReplaceRule +import io.legado.app.exception.NoStackTraceException import io.legado.app.help.ReplaceAnalyzer import io.legado.app.help.config.AppConfig import io.legado.app.help.http.newCallResponseBody import io.legado.app.help.http.okHttpClient import io.legado.app.help.http.text import io.legado.app.utils.isAbsUrl +import io.legado.app.utils.isJsonArray +import io.legado.app.utils.isJsonObject import io.legado.app.utils.splitNotBlank class ImportReplaceRuleViewModel(app: Application) : BaseViewModel(app) { @@ -83,17 +86,7 @@ class ImportReplaceRuleViewModel(app: Application) : BaseViewModel(app) { fun import(text: String) { execute { - if (text.isAbsUrl()) { - okHttpClient.newCallResponseBody { - url(text) - }.text("utf-8").let { - val rules = ReplaceAnalyzer.jsonToReplaceRules(it) - allRules.addAll(rules) - } - } else { - val rules = ReplaceAnalyzer.jsonToReplaceRules(text) - allRules.addAll(rules) - } + importAwait(text.trim()) }.onError { errorLiveData.postValue(it.localizedMessage ?: "ERROR") }.onSuccess { @@ -101,6 +94,29 @@ class ImportReplaceRuleViewModel(app: Application) : BaseViewModel(app) { } } + private suspend fun importAwait(text: String) { + when { + text.isAbsUrl() -> importUrl(text) + text.isJsonArray() -> { + val rules = ReplaceAnalyzer.jsonToReplaceRules(text).getOrThrow() + allRules.addAll(rules) + } + text.isJsonObject() -> { + val rule = ReplaceAnalyzer.jsonToReplaceRule(text).getOrThrow() + allRules.add(rule) + } + else -> throw NoStackTraceException("格式不对") + } + } + + private suspend fun importUrl(url: String) { + okHttpClient.newCallResponseBody { + url(url) + }.text("utf-8").let { + importAwait(it) + } + } + private fun comparisonSource() { execute { allRules.forEach { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt index adf6afd12..76462ca18 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt @@ -9,10 +9,10 @@ import android.widget.LinearLayout import androidx.fragment.app.DialogFragment import androidx.preference.Preference import io.legado.app.R -import io.legado.app.base.BasePreferenceFragment import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.help.config.ReadBookConfig +import io.legado.app.lib.prefs.fragment.PreferenceFragment import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.primaryColor import io.legado.app.model.ReadBook @@ -67,7 +67,7 @@ class MoreConfigDialog : DialogFragment() { (activity as ReadBookActivity).bottomDialog-- } - class ReadPreferenceFragment : BasePreferenceFragment(), + class ReadPreferenceFragment : PreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener { @SuppressLint("RestrictedApi") diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt index b64446039..e303a6d7e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt @@ -10,12 +10,12 @@ import androidx.fragment.app.DialogFragment import androidx.preference.ListPreference import androidx.preference.Preference import io.legado.app.R -import io.legado.app.base.BasePreferenceFragment import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.data.appDb import io.legado.app.help.IntentHelp import io.legado.app.lib.dialogs.SelectItem +import io.legado.app.lib.prefs.fragment.PreferenceFragment import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.primaryColor import io.legado.app.model.ReadAloud @@ -54,7 +54,7 @@ class ReadAloudConfigDialog : DialogFragment() { .commit() } - class ReadAloudPreferenceFragment : BasePreferenceFragment(), + class ReadAloudPreferenceFragment : PreferenceFragment(), SpeakEngineDialog.CallBack, SharedPreferences.OnSharedPreferenceChangeListener { diff --git a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt index ba6420570..7b152e77c 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt @@ -19,8 +19,10 @@ import io.legado.app.utils.gone import io.legado.app.utils.longToastOnUi import io.legado.app.utils.visible import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.isActive -import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.Dispatchers.Main +import kotlinx.coroutines.async +import kotlinx.coroutines.ensureActive +import kotlinx.coroutines.withContext import java.util.concurrent.ConcurrentHashMap class ChapterListAdapter(context: Context, val callback: Callback) : @@ -54,17 +56,10 @@ class ChapterListAdapter(context: Context, val callback: Callback) : } - private val replaceRules - get() = callback.book?.let { - ContentProcessor.get(it.name, it.origin).getTitleReplaceRules() - } - private val useReplace - get() = AppConfig.tocUiUseReplace && callback.book?.getUseReplaceRule() == true private var upDisplayTileJob: Coroutine<*>? = null override fun onCurrentListChanged() { super.onCurrentListChanged() - upDisplayTitle() callback.onListChanged() } @@ -73,36 +68,50 @@ class ChapterListAdapter(context: Context, val callback: Callback) : displayTitleMap.clear() } - fun upDisplayTitle() { + fun upDisplayTitles(startIndex: Int) { upDisplayTileJob?.cancel() upDisplayTileJob = Coroutine.async(callback.scope) { - val replaceRules = replaceRules - val useReplace = useReplace - getItems().forEach { - if (!isActive) { - return@async + val book = callback.book ?: return@async + val replaceRules = ContentProcessor.get(book.name, book.origin).getTitleReplaceRules() + val useReplace = AppConfig.tocUiUseReplace && book.getUseReplaceRule() + val items = getItems() + async { + for (i in startIndex until items.size) { + val item = items[i] + if (displayTitleMap[item.title] == null) { + ensureActive() + val displayTitle = item.getDisplayTitle(replaceRules, useReplace) + ensureActive() + displayTitleMap[item.title] = displayTitle + withContext(Main) { + notifyItemChanged(i, true) + } + } } - if (displayTitleMap[it.title] == null) { - displayTitleMap[it.title] = it.getDisplayTitle(replaceRules, useReplace) + }.start() + async { + for (i in startIndex downTo 0) { + val item = items[i] + if (displayTitleMap[item.title] == null) { + ensureActive() + val displayTitle = item.getDisplayTitle(replaceRules, useReplace) + ensureActive() + displayTitleMap[item.title] = displayTitle + withContext(Main) { + notifyItemChanged(i, true) + } + } } - } + }.start() } } - override fun getViewBinding(parent: ViewGroup): ItemChapterListBinding { - return ItemChapterListBinding.inflate(inflater, parent, false) + private fun getDisplayTitle(chapter: BookChapter): String { + return displayTitleMap[chapter.title] ?: chapter.title } - private fun getDisplayTile(chapter: BookChapter): String { - var displayTitle = displayTitleMap[chapter.title] - if (displayTitle != null) { - return displayTitle - } - displayTitle = runBlocking { - chapter.getDisplayTitle(replaceRules, useReplace) - } - displayTitleMap[chapter.title] = displayTitle - return displayTitle + override fun getViewBinding(parent: ViewGroup): ItemChapterListBinding { + return ItemChapterListBinding.inflate(inflater, parent, false) } override fun convert( @@ -120,7 +129,7 @@ class ChapterListAdapter(context: Context, val callback: Callback) : } else { tvChapterName.setTextColor(context.getCompatColor(R.color.primaryText)) } - tvChapterName.text = getDisplayTile(item) + tvChapterName.text = getDisplayTitle(item) if (item.isVolume) { //卷名,如第一卷 突出显示 tvChapterItem.setBackgroundColor(context.getCompatColor(R.color.btn_bg_press)) @@ -138,6 +147,7 @@ class ChapterListAdapter(context: Context, val callback: Callback) : } upHasCache(binding, isDur, cached) } else { + tvChapterName.text = getDisplayTitle(item) upHasCache(binding, isDur, cached) } } @@ -150,8 +160,8 @@ class ChapterListAdapter(context: Context, val callback: Callback) : } } holder.itemView.setOnLongClickListener { - getItem(holder.layoutPosition)?.let { - context.longToastOnUi(getDisplayTile(it)) + getItem(holder.layoutPosition)?.let { item -> + context.longToastOnUi(getDisplayTitle(item)) } true } diff --git a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt index 7dbe80e92..a6e561347 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt @@ -97,7 +97,15 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt viewModel.bookData.value?.bookUrl?.let { bookUrl -> if (chapter.bookUrl == bookUrl) { adapter.cacheFileNames.add(chapter.getFileName()) - adapter.notifyItemChanged(chapter.index, true) + if (viewModel.searchKey.isNullOrEmpty()) { + adapter.notifyItemChanged(chapter.index, true) + } else { + adapter.getItems().forEachIndexed { index, bookChapter -> + if (bookChapter.index == chapter.index) { + adapter.notifyItemChanged(index, true) + } + } + } } } } @@ -128,12 +136,13 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt } } mLayoutManager.scrollToPositionWithOffset(scrollPos, 0) + adapter.upDisplayTitles(scrollPos) } } override fun clearDisplayTitle() { adapter.clearDisplayTitle() - adapter.upDisplayTitle() + adapter.upDisplayTitles(mLayoutManager.findFirstVisibleItemPosition()) } override val scope: CoroutineScope diff --git a/app/src/main/java/io/legado/app/ui/book/toc/TocActivity.kt b/app/src/main/java/io/legado/app/ui/book/toc/TocActivity.kt index 0dc596cb6..8cb93e35f 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/TocActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/TocActivity.kt @@ -59,10 +59,12 @@ class TocActivity : VMBaseActivity() { setOnSearchClickListener { tabLayout.gone() } setOnQueryTextListener(object : SearchView.OnQueryTextListener { override fun onQueryTextSubmit(query: String): Boolean { + viewModel.searchKey = query return false } override fun onQueryTextChange(newText: String): Boolean { + viewModel.searchKey = newText if (tabLayout.selectedTabPosition == 1) { viewModel.startBookmarkSearch(newText) } else { diff --git a/app/src/main/java/io/legado/app/ui/book/toc/TocViewModel.kt b/app/src/main/java/io/legado/app/ui/book/toc/TocViewModel.kt index b766fad2a..feb989943 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/TocViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/TocViewModel.kt @@ -12,6 +12,7 @@ class TocViewModel(application: Application) : BaseViewModel(application) { var bookData = MutableLiveData() var chapterListCallBack: ChapterListCallBack? = null var bookMarkCallBack: BookmarkCallBack? = null + var searchKey: String? = null fun initBook(bookUrl: String) { this.bookUrl = bookUrl diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index 425651827..65a72dd9b 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -15,7 +15,6 @@ import androidx.preference.EditTextPreference import androidx.preference.ListPreference import androidx.preference.Preference import io.legado.app.R -import io.legado.app.base.BasePreferenceFragment import io.legado.app.constant.AppLog import io.legado.app.constant.PreferKey import io.legado.app.help.config.AppConfig @@ -25,7 +24,7 @@ import io.legado.app.help.storage.* import io.legado.app.lib.dialogs.alert import io.legado.app.lib.permission.Permissions import io.legado.app.lib.permission.PermissionsCompat -import io.legado.app.lib.theme.accentColor +import io.legado.app.lib.prefs.fragment.PreferenceFragment import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.document.HandleFileContract import io.legado.app.ui.widget.dialog.TextDialog @@ -34,7 +33,7 @@ import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.launch import splitties.init.appCtx -class BackupConfigFragment : BasePreferenceFragment(), +class BackupConfigFragment : PreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener { private val viewModel by activityViewModels() @@ -100,34 +99,18 @@ class BackupConfigFragment : BasePreferenceFragment(), override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.pref_config_backup) - findPreference(PreferKey.webDavUrl)?.let { - it.setOnBindEditTextListener { editText -> - editText.applyTint(requireContext().accentColor) - } - } - findPreference(PreferKey.webDavAccount)?.let { - it.setOnBindEditTextListener { editText -> - editText.applyTint(requireContext().accentColor) - } - } findPreference(PreferKey.webDavPassword)?.let { it.setOnBindEditTextListener { editText -> - editText.applyTint(requireContext().accentColor) editText.inputType = InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT } } - findPreference(PreferKey.webDavDir)?.let { - it.setOnBindEditTextListener { editText -> - editText.applyTint(requireContext().accentColor) - } - } upPreferenceSummary(PreferKey.webDavUrl, getPrefString(PreferKey.webDavUrl)) upPreferenceSummary(PreferKey.webDavAccount, getPrefString(PreferKey.webDavAccount)) upPreferenceSummary(PreferKey.webDavPassword, getPrefString(PreferKey.webDavPassword)) upPreferenceSummary(PreferKey.webDavDir, AppConfig.webDavDir) upPreferenceSummary(PreferKey.backupPath, getPrefString(PreferKey.backupPath)) - findPreference("web_dav_restore") + findPreference("web_dav_restore") ?.onLongClick { restoreDir.launch(); true } } diff --git a/app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt index eca0334dd..45496d0c9 100644 --- a/app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt @@ -7,16 +7,16 @@ import android.os.Bundle import android.view.View import androidx.preference.Preference import io.legado.app.R -import io.legado.app.base.BasePreferenceFragment import io.legado.app.constant.PreferKey import io.legado.app.lib.dialogs.selector +import io.legado.app.lib.prefs.SwitchPreference +import io.legado.app.lib.prefs.fragment.PreferenceFragment import io.legado.app.lib.theme.primaryColor import io.legado.app.model.BookCover -import io.legado.app.ui.widget.prefs.SwitchPreference import io.legado.app.utils.* import java.io.FileOutputStream -class CoverConfigFragment : BasePreferenceFragment(), +class CoverConfigFragment : PreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener { private val requestCodeCover = 111 diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 4e7192418..f1ec03bce 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -10,12 +10,12 @@ import androidx.fragment.app.activityViewModels import androidx.preference.ListPreference import androidx.preference.Preference import io.legado.app.R -import io.legado.app.base.BasePreferenceFragment import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.help.config.AppConfig import io.legado.app.lib.dialogs.alert +import io.legado.app.lib.prefs.fragment.PreferenceFragment import io.legado.app.lib.theme.primaryColor import io.legado.app.model.CheckSource import io.legado.app.receiver.SharedReceiverActivity @@ -26,7 +26,7 @@ import io.legado.app.utils.* import splitties.init.appCtx -class OtherConfigFragment : BasePreferenceFragment(), +class OtherConfigFragment : PreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener { private val viewModel by activityViewModels() diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index d143ac8e1..567217e07 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -13,7 +13,6 @@ import android.widget.SeekBar import androidx.preference.Preference import io.legado.app.R import io.legado.app.base.AppContextWrapper -import io.legado.app.base.BasePreferenceFragment import io.legado.app.constant.AppConst import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey @@ -24,16 +23,17 @@ import io.legado.app.help.config.AppConfig import io.legado.app.help.config.ThemeConfig import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.selector +import io.legado.app.lib.prefs.ColorPreference +import io.legado.app.lib.prefs.fragment.PreferenceFragment import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.widget.number.NumberPickerDialog -import io.legado.app.ui.widget.prefs.ColorPreference import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.utils.* import java.io.FileOutputStream @Suppress("SameParameterValue") -class ThemeConfigFragment : BasePreferenceFragment(), +class ThemeConfigFragment : PreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener { private val requestCodeBgLight = 121 diff --git a/app/src/main/java/io/legado/app/ui/config/WelcomeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WelcomeConfigFragment.kt index 60d205b4c..2e9ea30c5 100644 --- a/app/src/main/java/io/legado/app/ui/config/WelcomeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WelcomeConfigFragment.kt @@ -7,15 +7,15 @@ import android.os.Bundle import android.view.View import androidx.preference.Preference import io.legado.app.R -import io.legado.app.base.BasePreferenceFragment import io.legado.app.constant.PreferKey import io.legado.app.lib.dialogs.selector +import io.legado.app.lib.prefs.fragment.PreferenceFragment import io.legado.app.lib.theme.primaryColor import io.legado.app.model.BookCover import io.legado.app.utils.* import java.io.FileOutputStream -class WelcomeConfigFragment : BasePreferenceFragment(), +class WelcomeConfigFragment : PreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener { private val requestWelcomeImage = 221 diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index 92c31c288..df40f6cad 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -8,13 +8,16 @@ import android.view.View import androidx.preference.Preference import io.legado.app.R import io.legado.app.base.BaseFragment -import io.legado.app.base.BasePreferenceFragment import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.databinding.FragmentMyConfigBinding import io.legado.app.help.config.AppConfig import io.legado.app.help.config.ThemeConfig import io.legado.app.lib.dialogs.selector +import io.legado.app.lib.prefs.NameListPreference +import io.legado.app.lib.prefs.PreferenceCategory +import io.legado.app.lib.prefs.SwitchPreference +import io.legado.app.lib.prefs.fragment.PreferenceFragment import io.legado.app.lib.theme.primaryColor import io.legado.app.service.WebService import io.legado.app.ui.about.AboutActivity @@ -26,9 +29,6 @@ import io.legado.app.ui.config.ConfigActivity import io.legado.app.ui.config.ConfigTag import io.legado.app.ui.replace.ReplaceRuleActivity import io.legado.app.ui.widget.dialog.TextDialog -import io.legado.app.ui.widget.prefs.NameListPreference -import io.legado.app.ui.widget.prefs.PreferenceCategory -import io.legado.app.ui.widget.prefs.SwitchPreference import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding @@ -40,7 +40,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { setSupportToolbar(binding.titleBar.toolbar) val fragmentTag = "prefFragment" var preferenceFragment = childFragmentManager.findFragmentByTag(fragmentTag) - if (preferenceFragment == null) preferenceFragment = PreferenceFragment() + if (preferenceFragment == null) preferenceFragment = MyPreferenceFragment() childFragmentManager.beginTransaction() .replace(R.id.pre_fragment, preferenceFragment, fragmentTag).commit() } @@ -61,7 +61,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { /** * 配置 */ - class PreferenceFragment : BasePreferenceFragment(), + class MyPreferenceFragment : PreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt index 296965a1e..cf769b459 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt @@ -14,6 +14,7 @@ import io.legado.app.base.VMBaseActivity import io.legado.app.databinding.ActivityRssArtivlesBinding import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.lib.dialogs.alert +import io.legado.app.lib.theme.accentColor import io.legado.app.ui.login.SourceLoginActivity import io.legado.app.ui.rss.source.edit.RssSourceEditActivity import io.legado.app.utils.StartActivityContract @@ -45,9 +46,10 @@ class RssSortActivity : VMBaseActivity(context, holder, icon, title, summary, null, null) - super.onBindViewHolder(holder) - } - -} diff --git a/app/src/main/java/io/legado/app/utils/RegexExtensions.kt b/app/src/main/java/io/legado/app/utils/RegexExtensions.kt index 188b1ea9a..9250b4db8 100644 --- a/app/src/main/java/io/legado/app/utils/RegexExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/RegexExtensions.kt @@ -6,6 +6,7 @@ import kotlinx.coroutines.suspendCancellableCoroutine import splitties.init.appCtx import kotlin.concurrent.thread import kotlin.coroutines.resume +import kotlin.coroutines.resumeWithException /** * 带有超时检测的正则替换 @@ -19,7 +20,7 @@ suspend fun CharSequence.replace(regex: Regex, replacement: String, timeout: Lon val result = regex.replace(charSequence, replacement) block.resume(result) } catch (e: Exception) { - block.cancel(e) + block.resumeWithException(e) } } mainHandler.postDelayed({ diff --git a/app/src/main/res/xml/about.xml b/app/src/main/res/xml/about.xml index d0a498c0d..b62f4a2f4 100644 --- a/app/src/main/res/xml/about.xml +++ b/app/src/main/res/xml/about.xml @@ -2,82 +2,82 @@ - - - - - - - - - - - - - - + - - - - - + \ No newline at end of file diff --git a/app/src/main/res/xml/donate.xml b/app/src/main/res/xml/donate.xml index 1b4d7af60..9b43609cb 100644 --- a/app/src/main/res/xml/donate.xml +++ b/app/src/main/res/xml/donate.xml @@ -2,20 +2,20 @@ - - - - + - - - - - + - - - + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_config_aloud.xml b/app/src/main/res/xml/pref_config_aloud.xml index edb0e7ca7..333e0aa40 100644 --- a/app/src/main/res/xml/pref_config_aloud.xml +++ b/app/src/main/res/xml/pref_config_aloud.xml @@ -2,38 +2,38 @@ - - - - - - + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_config_backup.xml b/app/src/main/res/xml/pref_config_backup.xml index 06085208d..faf7e214b 100644 --- a/app/src/main/res/xml/pref_config_backup.xml +++ b/app/src/main/res/xml/pref_config_backup.xml @@ -2,39 +2,39 @@ - - - - - - - + - - - - - - - + diff --git a/app/src/main/res/xml/pref_config_cover.xml b/app/src/main/res/xml/pref_config_cover.xml index ca692fb57..1d8db29ed 100644 --- a/app/src/main/res/xml/pref_config_cover.xml +++ b/app/src/main/res/xml/pref_config_cover.xml @@ -2,13 +2,13 @@ - - - - - - - - + - - - - - + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index 0b0d6ffa8..931deb5f9 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -2,41 +2,41 @@ - - - - - - - + - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_config_read.xml b/app/src/main/res/xml/pref_config_read.xml index 4b26da4b7..1c8a29afb 100644 --- a/app/src/main/res/xml/pref_config_read.xml +++ b/app/src/main/res/xml/pref_config_read.xml @@ -2,7 +2,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_config_welcome.xml b/app/src/main/res/xml/pref_config_welcome.xml index 66f780983..bdd19fe68 100644 --- a/app/src/main/res/xml/pref_config_welcome.xml +++ b/app/src/main/res/xml/pref_config_welcome.xml @@ -2,7 +2,7 @@ - - - - - - + - - - - - + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_main.xml b/app/src/main/res/xml/pref_main.xml index 45cba0157..70d80013d 100644 --- a/app/src/main/res/xml/pref_main.xml +++ b/app/src/main/res/xml/pref_main.xml @@ -5,21 +5,21 @@ app:allowDividerAbove="false" app:allowDividerBelow="false"> - - - - - - - - - + - - - - - - + \ No newline at end of file