From 1b53fa30c4434b0ca7961b0f400d2e8984d9e26a Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 10 Feb 2022 08:52:21 +0800 Subject: [PATCH] =?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" /> + +