From 8caa77891aa6d5a1e3671926a099476121672427 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 10 Feb 2022 10:56:28 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/DirectLinkUpload.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/help/DirectLinkUpload.kt b/app/src/main/java/io/legado/app/help/DirectLinkUpload.kt index fcceecfd6..14c91a1e6 100644 --- a/app/src/main/java/io/legado/app/help/DirectLinkUpload.kt +++ b/app/src/main/java/io/legado/app/help/DirectLinkUpload.kt @@ -15,6 +15,7 @@ object DirectLinkUpload { private const val downloadUrlRuleKey = "directLinkDownloadUrlRule" private const val summaryKey = "directSummary" + @Throws(NoStackTraceException::class) suspend fun upLoad(fileName: String, file: Any, contentType: String): String { val url = getUploadUrl() if (url.isNullOrBlank()) { From a5d64f9425e4a23186113e515391994a9ccc4e60 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 10 Feb 2022 14:41:26 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=95=E7=8B=AC?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=B9=A6=E7=B1=8Dtts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/book/read/config/SpeakEngineDialog.kt | 57 ++++++++++++------- .../book/read/config/SpeakEngineViewModel.kt | 2 +- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt index 26d52ba59..36d4e0dce 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt @@ -5,6 +5,7 @@ import android.os.Bundle import android.view.MenuItem import android.view.View import android.view.ViewGroup +import android.widget.RadioButton import androidx.appcompat.widget.Toolbar import androidx.fragment.app.viewModels import androidx.recyclerview.widget.LinearLayoutManager @@ -21,15 +22,17 @@ import io.legado.app.help.AppConfig import io.legado.app.help.DirectLinkUpload import io.legado.app.lib.dialogs.SelectItem import io.legado.app.lib.dialogs.alert -import io.legado.app.lib.dialogs.selector import io.legado.app.lib.theme.primaryColor +import io.legado.app.model.ReadAloud +import io.legado.app.model.ReadBook import io.legado.app.ui.document.HandleFileContract import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding -import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch - +/** + * tts引擎管理 + */ class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view), Toolbar.OnMenuItemClickListener { @@ -37,7 +40,8 @@ class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view), private val viewModel: SpeakEngineViewModel by viewModels() private val ttsUrlKey = "ttsUrlKey" private val adapter by lazy { Adapter(requireContext()) } - private var ttsEngine: String? = AppConfig.ttsEngine + private var ttsEngine: String? = ReadAloud.ttsEngine + private val sysTtsViews = arrayListOf() private val importDocResult = registerForActivityResult(HandleFileContract()) { it.uri?.let { uri -> viewModel.importLocal(uri) @@ -80,13 +84,31 @@ class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view), recyclerView.setEdgeEffectColor(primaryColor) recyclerView.layoutManager = LinearLayoutManager(requireContext()) recyclerView.adapter = adapter - tvFooterLeft.setText(R.string.system_tts) + viewModel.sysEngines.forEach { engine -> + adapter.addHeaderView { + ItemHttpTtsBinding.inflate(layoutInflater, recyclerView, false).apply { + sysTtsViews.add(cbName) + ivEdit.gone() + ivMenuDelete.gone() + cbName.text = engine.label + cbName.tag = engine.name + cbName.isChecked = + GSON.fromJsonObject>(ttsEngine)?.value == cbName.tag + cbName.setOnClickListener { + upTts(GSON.toJson(SelectItem(engine.label, engine.name))) + } + } + } + } + tvFooterLeft.setText(R.string.book) tvFooterLeft.visible() tvFooterLeft.setOnClickListener { - selectSysTts() + ReadBook.book?.setTtsEngine(ttsEngine) + dismissAllowingStateLoss() } tvOk.visible() tvOk.setOnClickListener { + ReadBook.book?.setTtsEngine(null) AppConfig.ttsEngine = ttsEngine dismissAllowingStateLoss() } @@ -131,18 +153,6 @@ class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view), return true } - private fun selectSysTts() { - val ttsItems = viewModel.tts.engines.map { - SelectItem(it.label, it.name) - } - context?.selector(R.string.system_tts, ttsItems) { _, item, _ -> - AppConfig.ttsEngine = GSON.toJson(item) - ttsEngine = null - adapter.notifyItemRangeChanged(0, adapter.itemCount) - dismissAllowingStateLoss() - } - } - private fun importAlert() { val aCache = ACache.get(requireContext(), cacheDir = false) val cacheUrls: MutableList = aCache @@ -171,6 +181,14 @@ class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view), } } + private fun upTts(tts: String) { + ttsEngine = tts + sysTtsViews.forEach { + it.isChecked = GSON.fromJsonObject>(ttsEngine)?.value == it.tag + } + adapter.notifyItemRangeChanged(adapter.getHeaderCount(), adapter.itemCount) + } + inner class Adapter(context: Context) : RecyclerAdapter(context) { @@ -194,8 +212,7 @@ class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view), binding.run { cbName.setOnClickListener { getItemByLayoutPosition(holder.layoutPosition)?.let { httpTTS -> - ttsEngine = httpTTS.id.toString() - notifyItemRangeChanged(getHeaderCount(), itemCount) + upTts(httpTTS.id.toString()) } } ivEdit.setOnClickListener { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt index d12f2e76c..b85cebed1 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt @@ -18,7 +18,7 @@ import io.legado.app.utils.toastOnUi class SpeakEngineViewModel(application: Application) : BaseViewModel(application) { - val tts = TextToSpeech(context, null) + val sysEngines = TextToSpeech(context, null).engines fun importDefault() { execute { From 7cd8bfa9b4d33aaf2e6b36433eae9a83b5137e74 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 10 Feb 2022 15:09:37 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=95=E7=8B=AC?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=B9=A6=E7=B1=8Dtts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/config/SpeakEngineDialog.kt | 1 + app/src/main/res/values-es-rES/strings.xml | 1 + app/src/main/res/values-ja-rJP/strings.xml | 1 + app/src/main/res/values-pt-rBR/strings.xml | 3 +++ app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 8 files changed, 10 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt index 36d4e0dce..58a91d19f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt @@ -106,6 +106,7 @@ class SpeakEngineDialog : BaseDialogFragment(R.layout.dialog_recycler_view), ReadBook.book?.setTtsEngine(ttsEngine) dismissAllowingStateLoss() } + tvOk.setText(R.string.general) tvOk.visible() tvOk.setOnClickListener { ReadBook.book?.setTtsEngine(null) diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 1a404a11c..afa569586 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -928,5 +928,6 @@ 校验超时: %1$s秒\n校验项目:%2$s 记录调试日志 子文件夹 + 全局 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 118b873f2..6d04aa906 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -931,5 +931,6 @@ 校验超时: %1$s秒\n校验项目:%2$s 记录调试日志 子文件夹 + 全局 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 94949dc6d..8854912c2 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -918,6 +918,8 @@ 选择保存书籍的文件夹 用户代理 背景透明度 + 限制正文长度 + 正文长度过长时,加载正文可能会花费更多时间 校验设置 @@ -929,5 +931,6 @@ 校验超时: %1$s秒\n校验项目:%2$s 记录调试日志 子文件夹 + 全局 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 2158736f8..87aaf6199 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -928,5 +928,6 @@ 校验超时: %1$s秒\n校验项目:%2$s 记录调试日志 子文件夹 + 全局 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index c99dc1ecc..5c24f16ba 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -930,5 +930,6 @@ 校验超时: %1$s秒\n校验项目:%2$s 记录调试日志 子文件夹 + 全局 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 26ac234e2..701d5337f 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -930,5 +930,6 @@ 校验超时: %1$s秒\n校验项目:%2$s 记录调试日志 子文件夹 + 全局 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d10a2350d..aa0aa6ad8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -931,5 +931,6 @@ 校验超时: %1$s秒\n校验项目:%2$s 记录调试日志 Sub dir + 全局 From 639e416224ebf8fea807439d173f478ae77334b5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 10 Feb 2022 15:13:23 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=95=E7=8B=AC?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=B9=A6=E7=B1=8Dtts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index a21aae56a..ad1ec886e 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -11,6 +11,10 @@ * 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。 * 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源! +**2022/02/10** + +* 可以单独给书籍设置朗读tts + **2022/02/09** * 校验失效分组具体到搜索发现目录正文 by Xwite From f8efc8f52961b16bc5bd228424355f2578ce91a0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 10 Feb 2022 16:38:10 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E7=9B=AE=E5=BD=95=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=B7=BB=E5=8A=A0=E6=9B=BF=E6=8D=A2=E5=BC=80?= =?UTF-8?q?=E5=85=B3,=E5=BC=80=E5=90=AF=E6=9B=BF=E6=8D=A2=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E6=97=B6=E9=97=B4=E4=BC=9A=E9=95=BF=E4=B8=80=E4=BA=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 1 + app/src/main/java/io/legado/app/constant/PreferKey.kt | 1 + app/src/main/java/io/legado/app/help/AppConfig.kt | 6 ++++++ .../io/legado/app/ui/book/toc/ChapterListFragment.kt | 4 +++- .../main/java/io/legado/app/ui/book/toc/TocActivity.kt | 7 +++++++ app/src/main/res/menu/book_toc.xml | 10 ++++++++-- app/src/main/res/values-es-rES/strings.xml | 1 + app/src/main/res/values-ja-rJP/strings.xml | 1 + app/src/main/res/values-pt-rBR/strings.xml | 1 + app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 7 ++++--- 13 files changed, 36 insertions(+), 6 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index ad1ec886e..3ada71306 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -14,6 +14,7 @@ **2022/02/10** * 可以单独给书籍设置朗读tts +* 目录界面菜单添加替换开关,开启替换加载时间会长一些 **2022/02/09** diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index c0951a129..93f9d9d18 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -93,6 +93,7 @@ object PreferKey { const val defaultBookTreeUri = "defaultBookTreeUri" const val checkSource = "checkSource" const val uploadRule = "uploadRule" + const val tocUiUseReplace = "tocUiUseReplace" const val cPrimary = "colorPrimary" const val cAccent = "colorAccent" diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index 8375e07d6..83a889fa6 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -250,6 +250,12 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { appCtx.putPrefInt(PreferKey.webPort, value) } + var tocUiUseReplace: Boolean + get() = appCtx.getPrefBoolean(PreferKey.tocUiUseReplace) + set(value) { + appCtx.putPrefBoolean(PreferKey.tocUiUseReplace, value) + } + val autoChangeSource: Boolean get() = appCtx.getPrefBoolean(PreferKey.autoChangeSource, 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 ab0bc4dbe..3fd41aec9 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 @@ -13,6 +13,7 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.databinding.FragmentChapterListBinding +import io.legado.app.help.AppConfig import io.legado.app.help.BookHelp import io.legado.app.help.ContentProcessor import io.legado.app.lib.theme.bottomBackground @@ -115,7 +116,8 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt val replaces = viewModel.bookData.value?.let { book -> ContentProcessor.get(book.name, book.origin).getReplaceRules() } - val useReplace = viewModel.bookData.value?.getUseReplaceRule() == true + val useReplace = + AppConfig.tocUiUseReplace && viewModel.bookData.value?.getUseReplaceRule() == true it.map { chapter -> Pair( chapter, 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 46310a27e..535c22103 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 @@ -15,6 +15,7 @@ import com.google.android.material.tabs.TabLayout import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.databinding.ActivityChapterListBinding +import io.legado.app.help.AppConfig import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.primaryTextColor import io.legado.app.ui.about.AppLogDialog @@ -74,6 +75,11 @@ class TocActivity : VMBaseActivity() { return super.onCompatCreateOptionsMenu(menu) } + override fun onMenuOpened(featureId: Int, menu: Menu): Boolean { + menu.findItem(R.id.menu_use_replace)?.isChecked = AppConfig.tocUiUseReplace + return super.onMenuOpened(featureId, menu) + } + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.menu_reverse_toc -> viewModel.reverseToc { @@ -82,6 +88,7 @@ class TocActivity : VMBaseActivity() { putExtra("chapterPos", it.durChapterPos) }) } + R.id.menu_use_replace -> AppConfig.tocUiUseReplace = !item.isChecked R.id.menu_log -> showDialogFragment() } return super.onCompatOptionsItemSelected(item) diff --git a/app/src/main/res/menu/book_toc.xml b/app/src/main/res/menu/book_toc.xml index d5c6dadf0..7bb1c39a6 100644 --- a/app/src/main/res/menu/book_toc.xml +++ b/app/src/main/res/menu/book_toc.xml @@ -1,7 +1,7 @@ - + + 记录调试日志 子文件夹 全局 + 使用替换 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 6d04aa906..b60570614 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -932,5 +932,6 @@ 记录调试日志 子文件夹 全局 + 使用替换 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 8854912c2..387d3c92d 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -932,5 +932,6 @@ 记录调试日志 子文件夹 全局 + 使用替换 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 87aaf6199..1dd5bb76a 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -929,5 +929,6 @@ 记录调试日志 子文件夹 全局 + 使用替换 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 5c24f16ba..8d2d569bd 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -931,5 +931,6 @@ 记录调试日志 子文件夹 全局 + 使用替换 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 701d5337f..c65bc03e8 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -931,5 +931,6 @@ 记录调试日志 子文件夹 全局 + 使用替换 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index aa0aa6ad8..16b0eb388 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -918,8 +918,8 @@ 书籍保存位置 从其它应用打开的书籍保存位置 选择保存书籍的文件夹 - 用户代理 - 背景透明度 + User agent + Background alpha 校验设置 @@ -931,6 +931,7 @@ 校验超时: %1$s秒\n校验项目:%2$s 记录调试日志 Sub dir - 全局 + General + Use replace From 28a1057acbd72c552aca4797009532006dc39e0e Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 10 Feb 2022 16:43:34 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E7=9B=AE=E5=BD=95=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=B7=BB=E5=8A=A0=E6=9B=BF=E6=8D=A2=E5=BC=80?= =?UTF-8?q?=E5=85=B3,=E5=BC=80=E5=90=AF=E6=9B=BF=E6=8D=A2=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E6=97=B6=E9=97=B4=E4=BC=9A=E9=95=BF=E4=B8=80=E4=BA=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/ui/book/toc/TocActivity.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 535c22103..f69ea0235 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 @@ -88,7 +88,10 @@ class TocActivity : VMBaseActivity() { putExtra("chapterPos", it.durChapterPos) }) } - R.id.menu_use_replace -> AppConfig.tocUiUseReplace = !item.isChecked + R.id.menu_use_replace -> { + AppConfig.tocUiUseReplace = !item.isChecked + viewModel.chapterCallBack?.upChapterList(null) + } R.id.menu_log -> showDialogFragment() } return super.onCompatOptionsItemSelected(item) From e885c30cacaa5a20fa914717e96aa2c2e16abe98 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 10 Feb 2022 16:56:44 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/toc/ChapterListAdapter.kt | 5 +++-- .../java/io/legado/app/ui/book/toc/ChapterListFragment.kt | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) 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 9a9cfa421..8072f2d70 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 @@ -17,7 +17,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Deferred import kotlinx.coroutines.launch -class ChapterListAdapter(context: Context, val callback: Callback, private val scope: CoroutineScope) : +class ChapterListAdapter(context: Context, val callback: Callback) : RecyclerAdapter>, ItemChapterListBinding>(context) { val cacheFileNames = hashSetOf() @@ -64,7 +64,7 @@ class ChapterListAdapter(context: Context, val callback: Callback, private val s } else { tvChapterName.setTextColor(context.getCompatColor(R.color.primaryText)) } - scope.launch { + callback.scope.launch { tvChapterName.text = item.second.await() } if (item.first.isVolume) { @@ -108,6 +108,7 @@ class ChapterListAdapter(context: Context, val callback: Callback, private val s } interface Callback { + val scope: CoroutineScope val isLocalBook: Boolean fun openChapter(bookChapter: BookChapter) fun durChapterIndex(): Int 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 3fd41aec9..338c454ff 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 @@ -33,7 +33,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt override val viewModel by activityViewModels() private val binding by viewBinding(FragmentChapterListBinding::bind) private val mLayoutManager by lazy { UpLinearLayoutManager(requireContext()) } - private val adapter by lazy { ChapterListAdapter(requireContext(), this, this) } + private val adapter by lazy { ChapterListAdapter(requireContext(), this) } private var durChapterIndex = 0 private var tocFlowJob: Job? = null @@ -136,6 +136,9 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt } } + override val scope: CoroutineScope + get() = this + override val isLocalBook: Boolean get() = viewModel.bookData.value?.isLocalBook() == true From 412119a3f1fb9aeebabe27e2cf9d81f280dff2af Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 10 Feb 2022 16:58:57 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/main/explore/ExploreAdapter.kt | 9 +++++---- .../io/legado/app/ui/main/explore/ExploreFragment.kt | 6 +++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index 5f7f9cb3b..e5617fd6c 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -23,7 +23,7 @@ import io.legado.app.utils.* import kotlinx.coroutines.CoroutineScope import splitties.views.onLongClick -class ExploreAdapter(context: Context, private val scope: CoroutineScope, val callBack: CallBack) : +class ExploreAdapter(context: Context, val callBack: CallBack) : RecyclerAdapter(context) { private val recycler = arrayListOf() @@ -56,7 +56,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca if (scrollTo >= 0) { callBack.scrollTo(scrollTo) } - Coroutine.async(scope) { + Coroutine.async(callBack.scope) { item.exploreKinds }.onSuccess { kindList -> upKindList(flexbox, item.bookSourceUrl, kindList) @@ -167,12 +167,12 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca putExtra("type", "bookSource") putExtra("key", source.bookSourceUrl) } - R.id.menu_refresh -> Coroutine.async(scope) { + R.id.menu_refresh -> Coroutine.async(callBack.scope) { ACache.get(context, "explore").remove(source.bookSourceUrl) }.onSuccess { callBack.refreshData() } - R.id.menu_del -> Coroutine.async(scope) { + R.id.menu_del -> Coroutine.async(callBack.scope) { appDb.bookSourceDao.delete(source) } } @@ -183,6 +183,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca } interface CallBack { + val scope: CoroutineScope fun refreshData() fun scrollTo(pos: Int) fun openExplore(sourceUrl: String, title: String, exploreUrl: String?) diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index 7c321c9ca..86ceded1c 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -24,6 +24,7 @@ import io.legado.app.ui.book.explore.ExploreShowActivity import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding +import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch @@ -35,7 +36,7 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_explo ExploreAdapter.CallBack { override val viewModel by viewModels() private val binding by viewBinding(FragmentExploreBinding::bind) - private val adapter by lazy { ExploreAdapter(requireContext(), lifecycleScope, this) } + private val adapter by lazy { ExploreAdapter(requireContext(), this) } private val linearLayoutManager by lazy { LinearLayoutManager(context) } private val searchView: SearchView by lazy { binding.titleBar.findViewById(R.id.search_view) @@ -142,6 +143,9 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_explo } } + override val scope: CoroutineScope + get() = lifecycleScope + override fun onCompatOptionsItemSelected(item: MenuItem) { super.onCompatOptionsItemSelected(item) if (item.groupId == R.id.menu_group_text) { From a3a21c9c42793af84ba4ef5adda9b4a1d19e88dc Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 10 Feb 2022 17:06:25 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/service/CheckSourceService.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index 758eac57f..bded2777d 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -19,6 +19,7 @@ import io.legado.app.utils.activityPendingIntent import io.legado.app.utils.postEvent import io.legado.app.utils.servicePendingIntent import io.legado.app.utils.toastOnUi +import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.asCoroutineDispatcher import java.util.concurrent.Executors import kotlin.math.min @@ -204,8 +205,9 @@ class CheckSourceService : BaseService() { "" else "\n\n${source.bookSourceComment}" Debug.updateFinalMessage(source.bookSourceUrl, "校验失败:${it.localizedMessage}") }.onSuccess(searchCoroutine) { + source.removeGroup("失效") Debug.updateFinalMessage(source.bookSourceUrl, "校验成功") - }.onFinally(searchCoroutine) { + }.onFinally(IO) { source.respondTime = Debug.getRespondTime(source.bookSourceUrl) appDb.bookSourceDao.update(source) onNext(source.bookSourceUrl, source.bookSourceName)