From bf85726ddf596e9ebd19ec29033bd5fe165fcef3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 9 Feb 2022 19:51:12 +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/build.gradle | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index fc6cbf200..c26b10c28 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -192,8 +192,9 @@ dependencies { implementation(fileTree(dir: 'cronetlib', include: ['*.jar', '*.aar'])) //Glide - implementation('com.github.bumptech.glide:glide:4.12.0') - kapt('com.github.bumptech.glide:compiler:4.12.0') + def glideVersion = "4.13.0" + implementation("com.github.bumptech.glide:glide:$glideVersion") + kapt("com.github.bumptech.glide:compiler:$glideVersion") //webServer def nanoHttpdVersion = "2.3.1" From 339cabb696183612e54009c33437d3feb9589d78 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 9 Feb 2022 19:52:15 +0800 Subject: [PATCH 2/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/assets/updateLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 105bae5e3..486855672 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -18,6 +18,7 @@ * txt单章字数超102400均分txt,添加开关 by Xwite * 修复tts被回收后无法继续朗读的bug,重新初始化tts * webDav备份支持自定义文件夹 +* 其它一些优化 **2022/02/03** From d4a99ea5dff08cb46b2edb2d9712e80ed4216671 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 9 Feb 2022 19:52:37 +0800 Subject: [PATCH 3/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/assets/updateLog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 486855672..a21aae56a 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -11,7 +11,7 @@ * 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。 * 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源! -**2022/02/08** +**2022/02/09** * 校验失效分组具体到搜索发现目录正文 by Xwite * txt文件初次解析目录不选择禁用的正则 From 9c28737a4033acfed5e792bf6701666cce56eb6a Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 9 Feb 2022 21:27:33 +0800 Subject: [PATCH 4/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 --- .../io/legado/app/data/entities/BookChapter.kt | 3 ++- .../legado/app/ui/book/toc/ChapterListAdapter.kt | 14 ++++++++++---- .../legado/app/ui/book/toc/ChapterListFragment.kt | 3 +-- 3 files changed, 13 insertions(+), 7 deletions(-) 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 ac5718872..8258151dd 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 @@ -16,7 +16,6 @@ import kotlinx.parcelize.IgnoredOnParcel import kotlinx.parcelize.Parcelize import splitties.init.appCtx -@Suppress("unused") @Parcelize @Entity( tableName = "chapters", @@ -124,8 +123,10 @@ data class BookChapter( } } + @Suppress("unused") fun getFileName(): String = String.format("%05d-%s.nb", index, MD5Utils.md5Encode16(title)) + @Suppress("unused") fun getFontName(): String = String.format("%05d-%s.ttf", index, MD5Utils.md5Encode16(title)) } 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 5dd420649..5868981ec 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 @@ -10,20 +10,22 @@ import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.databinding.ItemChapterListBinding import io.legado.app.help.ContentProcessor +import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.theme.ThemeUtils import io.legado.app.lib.theme.accentColor import io.legado.app.utils.getCompatColor import io.legado.app.utils.gone import io.legado.app.utils.visible +import kotlinx.coroutines.CoroutineScope -class ChapterListAdapter(context: Context, val callback: Callback) : +class ChapterListAdapter(context: Context, private val scope: CoroutineScope, val callback: Callback) : RecyclerAdapter(context) { - val replaceRules + private val replaceRules get() = callback.book?.let { ContentProcessor.get(it.name, it.origin).getReplaceRules() } - val useReplace get() = callback.book?.getUseReplaceRule() == true + private val useReplace get() = callback.book?.getUseReplaceRule() == true val cacheFileNames = hashSetOf() val diffCallBack = object : DiffUtil.ItemCallback() { @@ -62,7 +64,11 @@ class ChapterListAdapter(context: Context, val callback: Callback) : } else { tvChapterName.setTextColor(context.getCompatColor(R.color.primaryText)) } - tvChapterName.text = item.getDisplayTitle(replaceRules, useReplace) + Coroutine.async(scope) { + item.getDisplayTitle(replaceRules, useReplace) + }.onSuccess { + tvChapterName.text = it + } if (item.isVolume) { //卷名,如第一卷 突出显示 tvChapterItem.setBackgroundColor(context.getCompatColor(R.color.btn_bg_press)) 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 d3154e64f..64c65f80a 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 @@ -24,7 +24,6 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Job -import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -34,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) } + private val adapter by lazy { ChapterListAdapter(requireContext(), this, this) } private var durChapterIndex = 0 private var tocFlowJob: Job? = null From d639b993a62081a5412b821633070bffcdf2e23f Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 9 Feb 2022 23:01:04 +0800 Subject: [PATCH 5/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/ui/book/toc/BookmarkFragment.kt | 1 - .../app/ui/book/toc/ChapterListAdapter.kt | 62 ++++++++----------- .../app/ui/book/toc/ChapterListFragment.kt | 17 +++-- 3 files changed, 39 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt b/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt index 9dacaca92..21c5cf785 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt @@ -17,7 +17,6 @@ import io.legado.app.utils.setEdgeEffectColor import io.legado.app.utils.showDialogFragment import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Job -import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch 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 5868981ec..bd1db1305 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 @@ -6,41 +6,38 @@ import androidx.recyclerview.widget.DiffUtil import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.RecyclerAdapter -import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.databinding.ItemChapterListBinding -import io.legado.app.help.ContentProcessor -import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.theme.ThemeUtils import io.legado.app.lib.theme.accentColor import io.legado.app.utils.getCompatColor import io.legado.app.utils.gone import io.legado.app.utils.visible -import kotlinx.coroutines.CoroutineScope -class ChapterListAdapter(context: Context, private val scope: CoroutineScope, val callback: Callback) : - RecyclerAdapter(context) { +class ChapterListAdapter(context: Context, val callback: Callback) : + RecyclerAdapter, ItemChapterListBinding>(context) { - private val replaceRules - get() = callback.book?.let { - ContentProcessor.get(it.name, it.origin).getReplaceRules() - } - private val useReplace get() = callback.book?.getUseReplaceRule() == true val cacheFileNames = hashSetOf() - val diffCallBack = object : DiffUtil.ItemCallback() { + val diffCallBack = object : DiffUtil.ItemCallback>() { - override fun areItemsTheSame(oldItem: BookChapter, newItem: BookChapter): Boolean { - return oldItem.index == newItem.index + override fun areItemsTheSame( + oldItem: Pair, + newItem: Pair + ): Boolean { + return oldItem.first.index == newItem.first.index } - override fun areContentsTheSame(oldItem: BookChapter, newItem: BookChapter): Boolean { - return oldItem.bookUrl == newItem.bookUrl - && oldItem.url == newItem.url - && oldItem.isVip == newItem.isVip - && oldItem.isPay == newItem.isPay - && oldItem.title == newItem.title - && oldItem.tag == newItem.tag - && oldItem.isVolume == newItem.isVolume + override fun areContentsTheSame( + oldItem: Pair, + newItem: Pair + ): Boolean { + return oldItem.first.bookUrl == newItem.first.bookUrl + && oldItem.first.url == newItem.first.url + && oldItem.first.isVip == newItem.first.isVip + && oldItem.first.isPay == newItem.first.isPay + && oldItem.first.title == newItem.first.title + && oldItem.first.tag == newItem.first.tag + && oldItem.first.isVolume == newItem.first.isVolume } } @@ -52,24 +49,20 @@ class ChapterListAdapter(context: Context, private val scope: CoroutineScope, va override fun convert( holder: ItemViewHolder, binding: ItemChapterListBinding, - item: BookChapter, + item: Pair, payloads: MutableList ) { binding.run { - val isDur = callback.durChapterIndex() == item.index - val cached = callback.isLocalBook || cacheFileNames.contains(item.getFileName()) + val isDur = callback.durChapterIndex() == item.first.index + val cached = callback.isLocalBook || cacheFileNames.contains(item.first.getFileName()) if (payloads.isEmpty()) { if (isDur) { tvChapterName.setTextColor(context.accentColor) } else { tvChapterName.setTextColor(context.getCompatColor(R.color.primaryText)) } - Coroutine.async(scope) { - item.getDisplayTitle(replaceRules, useReplace) - }.onSuccess { - tvChapterName.text = it - } - if (item.isVolume) { + tvChapterName.text = item.second + if (item.first.isVolume) { //卷名,如第一卷 突出显示 tvChapterItem.setBackgroundColor(context.getCompatColor(R.color.btn_bg_press)) } else { @@ -77,9 +70,9 @@ class ChapterListAdapter(context: Context, private val scope: CoroutineScope, va tvChapterItem.background = ThemeUtils.resolveDrawable(context, android.R.attr.selectableItemBackground) } - if (!item.tag.isNullOrEmpty() && !item.isVolume) { + if (!item.first.tag.isNullOrEmpty() && !item.first.isVolume) { //卷名不显示tag(更新时间规则) - tvTag.text = item.tag + tvTag.text = item.first.tag tvTag.visible() } else { tvTag.gone() @@ -94,7 +87,7 @@ class ChapterListAdapter(context: Context, private val scope: CoroutineScope, va override fun registerListener(holder: ItemViewHolder, binding: ItemChapterListBinding) { holder.itemView.setOnClickListener { getItem(holder.layoutPosition)?.let { - callback.openChapter(it) + callback.openChapter(it.first) } } } @@ -110,7 +103,6 @@ class ChapterListAdapter(context: Context, private val scope: CoroutineScope, va } interface Callback { - val book: Book? 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 64c65f80a..b941a881a 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 @@ -14,6 +14,7 @@ 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.BookHelp +import io.legado.app.help.ContentProcessor import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.ui.widget.recycler.UpLinearLayoutManager @@ -33,7 +34,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 @@ -111,7 +112,16 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt else -> appDb.bookChapterDao.flowSearch(viewModel.bookUrl, searchKey) }.collect { if (!(searchKey.isNullOrBlank() && it.isEmpty())) { - adapter.setItems(it, adapter.diffCallBack) + val data = withContext(IO) { + val replaces = viewModel.bookData.value?.let { book -> + ContentProcessor.get(book.name, book.origin).getReplaceRules() + } + val useReplace = viewModel.bookData.value?.getUseReplaceRule() == true + it.map { chapter -> + Pair(chapter, chapter.getDisplayTitle(replaces, useReplace)) + } + } + adapter.setItems(data, adapter.diffCallBack) if (searchKey.isNullOrBlank() && mLayoutManager.findFirstVisibleItemPosition() < 0) { mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) } @@ -120,9 +130,6 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt } } - override val book: Book? - get() = viewModel.bookData.value - override val isLocalBook: Boolean get() = viewModel.bookData.value?.isLocalBook() == true From 5520ffc2fdcb2f7e9e3bfffb7a58dbd4abf7c74b Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 9 Feb 2022 23:18:44 +0800 Subject: [PATCH 6/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/ui/book/toc/ChapterListAdapter.kt | 23 +++++++++++-------- .../app/ui/book/toc/ChapterListFragment.kt | 5 ++-- 2 files changed, 17 insertions(+), 11 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 bd1db1305..9a9cfa421 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 @@ -13,23 +13,26 @@ import io.legado.app.lib.theme.accentColor import io.legado.app.utils.getCompatColor import io.legado.app.utils.gone import io.legado.app.utils.visible +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Deferred +import kotlinx.coroutines.launch -class ChapterListAdapter(context: Context, val callback: Callback) : - RecyclerAdapter, ItemChapterListBinding>(context) { +class ChapterListAdapter(context: Context, val callback: Callback, private val scope: CoroutineScope) : + RecyclerAdapter>, ItemChapterListBinding>(context) { val cacheFileNames = hashSetOf() - val diffCallBack = object : DiffUtil.ItemCallback>() { + val diffCallBack = object : DiffUtil.ItemCallback>>() { override fun areItemsTheSame( - oldItem: Pair, - newItem: Pair + oldItem: Pair>, + newItem: Pair> ): Boolean { return oldItem.first.index == newItem.first.index } override fun areContentsTheSame( - oldItem: Pair, - newItem: Pair + oldItem: Pair>, + newItem: Pair> ): Boolean { return oldItem.first.bookUrl == newItem.first.bookUrl && oldItem.first.url == newItem.first.url @@ -49,7 +52,7 @@ class ChapterListAdapter(context: Context, val callback: Callback) : override fun convert( holder: ItemViewHolder, binding: ItemChapterListBinding, - item: Pair, + item: Pair>, payloads: MutableList ) { binding.run { @@ -61,7 +64,9 @@ class ChapterListAdapter(context: Context, val callback: Callback) : } else { tvChapterName.setTextColor(context.getCompatColor(R.color.primaryText)) } - tvChapterName.text = item.second + scope.launch { + tvChapterName.text = item.second.await() + } if (item.first.isVolume) { //卷名,如第一卷 突出显示 tvChapterItem.setBackgroundColor(context.getCompatColor(R.color.btn_bg_press)) 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 b941a881a..218d96d6e 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 @@ -25,6 +25,7 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Job +import kotlinx.coroutines.async import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -34,7 +35,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) } + private val adapter by lazy { ChapterListAdapter(requireContext(), this, this) } private var durChapterIndex = 0 private var tocFlowJob: Job? = null @@ -118,7 +119,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt } val useReplace = viewModel.bookData.value?.getUseReplaceRule() == true it.map { chapter -> - Pair(chapter, chapter.getDisplayTitle(replaces, useReplace)) + Pair(chapter, async { chapter.getDisplayTitle(replaces, useReplace) }) } } adapter.setItems(data, adapter.diffCallBack) From 0039473314618e38ee91e59dca27fd6dfdbfb0a9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 9 Feb 2022 23:28:09 +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 --- .../io/legado/app/ui/book/toc/ChapterListFragment.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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 218d96d6e..9694f3e72 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 @@ -22,12 +22,9 @@ import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.ColorUtils import io.legado.app.utils.observeEvent import io.legado.app.utils.viewbindingdelegate.viewBinding +import kotlinx.coroutines.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main -import kotlinx.coroutines.Job -import kotlinx.coroutines.async -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapter_list), ChapterListAdapter.Callback, @@ -119,7 +116,11 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt } val useReplace = viewModel.bookData.value?.getUseReplaceRule() == true it.map { chapter -> - Pair(chapter, async { chapter.getDisplayTitle(replaces, useReplace) }) + Pair( + chapter, + async(start = CoroutineStart.LAZY) { + chapter.getDisplayTitle(replaces, useReplace) + }) } } adapter.setItems(data, adapter.diffCallBack) From 1b53fa30c4434b0ca7961b0f400d2e8984d9e26a Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 10 Feb 2022 08:52:21 +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 --- .../main/java/io/legado/app/data/entities/Book.kt | 15 ++++++++++----- app/src/main/java/io/legado/app/model/ReadBook.kt | 8 +------- .../app/ui/book/read/config/ReadStyleDialog.kt | 2 +- .../legado/app/ui/book/toc/ChapterListFragment.kt | 4 +++- app/src/main/res/layout/fragment_chapter_list.xml | 10 ++++++++++ 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index 8384e7305..55063af34 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -6,6 +6,7 @@ import io.legado.app.constant.AppPattern import io.legado.app.constant.BookType import io.legado.app.data.appDb import io.legado.app.help.AppConfig +import io.legado.app.help.ReadBookConfig import io.legado.app.model.ReadBook import io.legado.app.utils.GSON import io.legado.app.utils.MD5Utils @@ -149,7 +150,7 @@ data class Book( } fun getUseReplaceRule(): Boolean { - return config().useReplaceRule + return config().useReplaceRule ?: AppConfig.replaceEnableDefault } fun getReSegment(): Boolean { @@ -169,10 +170,14 @@ data class Book( } fun getPageAnim(): Int { - return config().pageAnim + var pageAnim = config().pageAnim ?: ReadBookConfig.pageAnim + if (pageAnim < 0) { + pageAnim = ReadBookConfig.pageAnim + } + return pageAnim } - fun setPageAnim(pageAnim: Int) { + fun setPageAnim(pageAnim: Int?) { config().pageAnim = pageAnim } @@ -276,11 +281,11 @@ data class Book( @Parcelize data class ReadConfig( var reverseToc: Boolean = false, - var pageAnim: Int = -1, + var pageAnim: Int? = null, var reSegment: Boolean = false, var limitContentLength: Boolean = true, //txt规则解析目录时超过规定的最大字数时均分txt var imageStyle: String? = null, - var useReplaceRule: Boolean = AppConfig.replaceEnableDefault,// 正文使用净化替换规则 + var useReplaceRule: Boolean? = null,// 正文使用净化替换规则 var delTag: Long = 0L,//去除标签 ) : Parcelable diff --git a/app/src/main/java/io/legado/app/model/ReadBook.kt b/app/src/main/java/io/legado/app/model/ReadBook.kt index 7ae26ffa0..ef2af53d5 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -402,13 +402,7 @@ object ReadBook : CoroutineScope by MainScope() { } fun pageAnim(): Int { - book?.let { - return if (it.getPageAnim() < 0) - ReadBookConfig.pageAnim - else - it.getPageAnim() - } - return ReadBookConfig.pageAnim + return book?.getPageAnim() ?: ReadBookConfig.pageAnim } fun setCharset(charset: String) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index 06f3119c8..768dc3ef1 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -126,7 +126,7 @@ class ReadStyleDialog : BaseDialogFragment(R.layout.dialog_read_book_style), TipConfigDialog().show(childFragmentManager, "tipConfigDialog") } rgPageAnim.setOnCheckedChangeListener { _, checkedId -> - ReadBook.book?.setPageAnim(-1) + ReadBook.book?.setPageAnim(null) ReadBookConfig.pageAnim = binding.rgPageAnim.getIndexById(checkedId) callBack?.upPageAnim() ReadBook.loadContent(false) 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 9694f3e72..ab0bc4dbe 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 @@ -110,6 +110,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt else -> appDb.bookChapterDao.flowSearch(viewModel.bookUrl, searchKey) }.collect { if (!(searchKey.isNullOrBlank() && it.isEmpty())) { + binding.rotateLoading.show() val data = withContext(IO) { val replaces = viewModel.bookData.value?.let { book -> ContentProcessor.get(book.name, book.origin).getReplaceRules() @@ -118,11 +119,12 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt it.map { chapter -> Pair( chapter, - async(start = CoroutineStart.LAZY) { + async(IO) { chapter.getDisplayTitle(replaces, useReplace) }) } } + binding.rotateLoading.hide() adapter.setItems(data, adapter.diffCallBack) if (searchKey.isNullOrBlank() && mLayoutManager.findFirstVisibleItemPosition() < 0) { mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) diff --git a/app/src/main/res/layout/fragment_chapter_list.xml b/app/src/main/res/layout/fragment_chapter_list.xml index 3d8943d79..902cda807 100644 --- a/app/src/main/res/layout/fragment_chapter_list.xml +++ b/app/src/main/res/layout/fragment_chapter_list.xml @@ -14,6 +14,16 @@ app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toTopOf="@+id/ll_chapter_base_info" /> + + Date: Thu, 10 Feb 2022 10:17:22 +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/data/entities/Book.kt | 9 +++++++++ app/src/main/java/io/legado/app/model/ReadAloud.kt | 3 ++- .../java/io/legado/app/service/TTSReadAloudService.kt | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index 55063af34..2f260e5aa 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -189,6 +189,14 @@ data class Book( config().imageStyle = imageStyle } + fun setTtsEngine(ttsEngine: String?) { + config().ttsEngine = ttsEngine + } + + fun getTtsEngine(): String? { + return config().ttsEngine + } + fun getDelTag(tag: Long): Boolean { return config().delTag and tag == tag } @@ -287,6 +295,7 @@ data class Book( var imageStyle: String? = null, var useReplaceRule: Boolean? = null,// 正文使用净化替换规则 var delTag: Long = 0L,//去除标签 + var ttsEngine: String? = null, ) : Parcelable class Converters { diff --git a/app/src/main/java/io/legado/app/model/ReadAloud.kt b/app/src/main/java/io/legado/app/model/ReadAloud.kt index 65f5ee6eb..7c26182ea 100644 --- a/app/src/main/java/io/legado/app/model/ReadAloud.kt +++ b/app/src/main/java/io/legado/app/model/ReadAloud.kt @@ -14,10 +14,11 @@ import splitties.init.appCtx object ReadAloud { private var aloudClass: Class<*> = getReadAloudClass() + val ttsEngine get() = ReadBook.book?.getTtsEngine() ?: AppConfig.ttsEngine var httpTTS: HttpTTS? = null private fun getReadAloudClass(): Class<*> { - val ttsEngine = AppConfig.ttsEngine + val ttsEngine = ttsEngine if (ttsEngine.isNullOrBlank()) { return TTSReadAloudService::class.java } diff --git a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt index dac6e3ced..bc8d55cd1 100644 --- a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt @@ -12,6 +12,7 @@ import io.legado.app.help.AppConfig import io.legado.app.help.MediaHelp import io.legado.app.lib.dialogs.SelectItem import io.legado.app.model.NoStackTraceException +import io.legado.app.model.ReadAloud import io.legado.app.model.ReadBook import io.legado.app.utils.* import java.util.* @@ -36,7 +37,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener @Synchronized private fun initTts() { ttsInitFinish = false - val engine = GSON.fromJsonObject>(AppConfig.ttsEngine)?.value + val engine = GSON.fromJsonObject>(ReadAloud.ttsEngine)?.value textToSpeech = if (engine.isNullOrBlank()) { TextToSpeech(this, this) } else {