From bf85726ddf596e9ebd19ec29033bd5fe165fcef3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 9 Feb 2022 19:51:12 +0800 Subject: [PATCH 1/6] =?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/6] =?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/6] =?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/6] =?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/6] =?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/6] =?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)