From c0bdf2bb30386a4fc38ce73a2e9cf32eb35d1ffb Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Sat, 3 Dec 2022 15:08:05 +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 --- .../legado/app/help/config/ReadBookConfig.kt | 1 + .../legado/app/help/config/ReadTipConfig.kt | 6 +++ .../legado/app/help/storage/BackupConfig.kt | 11 ++++- .../main/java/io/legado/app/model/ReadBook.kt | 12 +++--- .../app/ui/book/read/ReadBookActivity.kt | 20 ++++------ .../app/ui/book/read/ReadBookViewModel.kt | 40 ++++++++++--------- .../ui/book/read/config/TipConfigDialog.kt | 27 +++++++++++++ .../legado/app/ui/book/read/page/PageView.kt | 10 +++++ .../io/legado/app/ui/book/toc/TocActivity.kt | 18 ++++++++- app/src/main/res/layout/dialog_tip_config.xml | 26 ++++++++++++ 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 | 1 + 17 files changed, 137 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt index d39c0504f..cf3c75b01 100644 --- a/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt @@ -476,6 +476,7 @@ object ReadBookConfig { var tipFooterMiddle: Int = ReadTipConfig.none, var tipFooterRight: Int = ReadTipConfig.pageAndTotal, var tipColor: Int = 0, + var tipDividerColor: Int = -1, var headerMode: Int = 0, var footerMode: Int = 0 ) { diff --git a/app/src/main/java/io/legado/app/help/config/ReadTipConfig.kt b/app/src/main/java/io/legado/app/help/config/ReadTipConfig.kt index 114a9b275..cd47805a7 100644 --- a/app/src/main/java/io/legado/app/help/config/ReadTipConfig.kt +++ b/app/src/main/java/io/legado/app/help/config/ReadTipConfig.kt @@ -78,6 +78,12 @@ object ReadTipConfig { ReadBookConfig.config.tipColor = value } + var tipDividerColor: Int + get() = ReadBookConfig.config.tipDividerColor + set(value) { + ReadBookConfig.config.tipDividerColor = value + } + fun getHeaderModes(context: Context): LinkedHashMap { return linkedMapOf( Pair(0, context.getString(R.string.hide_when_status_bar_show)), diff --git a/app/src/main/java/io/legado/app/help/storage/BackupConfig.kt b/app/src/main/java/io/legado/app/help/storage/BackupConfig.kt index fb66bee7c..5174461ef 100644 --- a/app/src/main/java/io/legado/app/help/storage/BackupConfig.kt +++ b/app/src/main/java/io/legado/app/help/storage/BackupConfig.kt @@ -62,7 +62,16 @@ object BackupConfig { PreferKey.shareLayout, PreferKey.hideStatusBar, PreferKey.hideNavigationBar, - PreferKey.autoReadSpeed + PreferKey.autoReadSpeed, + PreferKey.clickActionTL, + PreferKey.clickActionTC, + PreferKey.clickActionTR, + PreferKey.clickActionML, + PreferKey.clickActionMC, + PreferKey.clickActionMR, + PreferKey.clickActionBL, + PreferKey.clickActionBC, + PreferKey.clickActionBR ) 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 a3ef50de9..08bd71c78 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -42,10 +42,13 @@ object ReadBook : CoroutineScope by MainScope() { private val loadingChapters = arrayListOf() private val readRecord = ReadRecord() var readStartTime: Long = System.currentTimeMillis() + /* 跳转历史记录 */ var bookProgressHistory: List? = null + /* 跳转进度前进度记录 */ var lastBookPress: BookProgress? = null + /* web端阅读进度记录 */ var webBookProgress: BookProgress? = null @@ -54,6 +57,7 @@ object ReadBook : CoroutineScope by MainScope() { if (lastBookPress != null) return //避免进度条连续跳转不能覆盖最初的进度记录 lastBookPress = book?.let { BookProgress(it) } } + //恢复跳转前进度 fun restoreLastBookProcess() { lastBookPress?.let { @@ -482,14 +486,10 @@ object ReadBook : CoroutineScope by MainScope() { } } - fun exit() { - callBack?.exit() - } - interface CallBack { fun upMenuView() - fun loadChapterList(book: Book) + fun loadChapterList(book: Book, callback: (() -> Unit)? = null) fun upContent( relativePosition: Int = 0, @@ -503,8 +503,6 @@ object ReadBook : CoroutineScope by MainScope() { fun upPageAnim() - fun exit() - fun notifyBookChanged() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index ab617af35..58187df6f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -49,6 +49,7 @@ import io.legado.app.ui.book.read.config.* import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.BG_COLOR import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.TEXT_COLOR import io.legado.app.ui.book.read.config.TipConfigDialog.Companion.TIP_COLOR +import io.legado.app.ui.book.read.config.TipConfigDialog.Companion.TIP_DIVIDER_COLOR import io.legado.app.ui.book.read.page.ContentTextView import io.legado.app.ui.book.read.page.ReadView import io.legado.app.ui.book.read.page.entities.PageDirection @@ -737,9 +738,9 @@ class ReadBookActivity : BaseReadBookActivity(), } } - override fun loadChapterList(book: Book) { + override fun loadChapterList(book: Book, callback: (() -> Unit)?) { ReadBook.upMsg(getString(R.string.toc_updateing)) - viewModel.loadChapterList(book) + viewModel.loadChapterList(book, callback) } /** @@ -776,16 +777,6 @@ class ReadBookActivity : BaseReadBookActivity(), } } - override fun exit() { - ReadBook.book?.let { - if (!ReadBook.inBookshelf) { - viewModel.removeFromBookshelf { super.finish() } - } else { - super.finish() - } - } ?: super.finish() - } - override fun notifyBookChanged() { bookChanged = true } @@ -1154,6 +1145,11 @@ class ReadBookActivity : BaseReadBookActivity(), postEvent(EventBus.TIP_COLOR, "") postEvent(EventBus.UP_CONFIG, true) } + TIP_DIVIDER_COLOR -> { + ReadTipConfig.tipDividerColor = color + postEvent(EventBus.TIP_COLOR, "") + postEvent(EventBus.UP_CONFIG, true) + } } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index f5123bc8f..3509021eb 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -135,7 +135,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { /** * 加载目录 */ - fun loadChapterList(book: Book) { + fun loadChapterList(book: Book, callback: (() -> Unit)? = null) { if (book.isLocal) { execute { LocalBook.getChapterList(book).let { @@ -157,28 +157,30 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { ReadBook.upMsg("LoadTocError:${it.localizedMessage}") } } + }.onFinally { + callback?.invoke() } } else { ReadBook.bookSource?.let { - viewModelScope.launch(IO) { - val oldBook = book.copy() - WebBook.getChapterList(viewModelScope, it, book, true) - .onSuccess(IO) { cList -> - if (oldBook.bookUrl == book.bookUrl) { - appDb.bookDao.update(book) - } else { - appDb.bookDao.insert(book) - BookHelp.updateCacheFolder(oldBook, book) - } - appDb.bookChapterDao.delByBook(oldBook.bookUrl) - appDb.bookChapterDao.insert(*cList.toTypedArray()) - ReadBook.chapterSize = cList.size - ReadBook.upMsg(null) - ReadBook.loadContent(resetPageOffset = true) - }.onError { - ReadBook.upMsg(context.getString(R.string.error_load_toc)) + val oldBook = book.copy() + WebBook.getChapterList(viewModelScope, it, book, true) + .onSuccess(IO) { cList -> + if (oldBook.bookUrl == book.bookUrl) { + appDb.bookDao.update(book) + } else { + appDb.bookDao.insert(book) + BookHelp.updateCacheFolder(oldBook, book) } - } + appDb.bookChapterDao.delByBook(oldBook.bookUrl) + appDb.bookChapterDao.insert(*cList.toTypedArray()) + ReadBook.chapterSize = cList.size + ReadBook.upMsg(null) + ReadBook.loadContent(resetPageOffset = true) + }.onError { + ReadBook.upMsg(context.getString(R.string.error_load_toc)) + }.onFinally { + callback?.invoke() + } } } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt index ddd588e9c..cca5a2798 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt @@ -19,6 +19,7 @@ class TipConfigDialog : BaseDialogFragment(R.layout.dialog_tip_config) { companion object { const val TIP_COLOR = 7897 + const val TIP_DIVIDER_COLOR = 7898 } private val binding by viewBinding(DialogTipConfigBinding::bind) @@ -33,6 +34,7 @@ class TipConfigDialog : BaseDialogFragment(R.layout.dialog_tip_config) { initEvent() observeEvent(EventBus.TIP_COLOR) { upTvTipColor() + upTvTipDividerColor() } } @@ -64,6 +66,7 @@ class TipConfigDialog : BaseDialogFragment(R.layout.dialog_tip_config) { } } upTvTipColor() + upTvTipDividerColor() } private fun upTvTipColor() { @@ -75,6 +78,14 @@ class TipConfigDialog : BaseDialogFragment(R.layout.dialog_tip_config) { } } + private fun upTvTipDividerColor() { + binding.tvTipDividerColor.text = when (ReadTipConfig.tipDividerColor) { + -1 -> "默认" + 0 -> "跟随文字颜色" + else -> "#${ReadTipConfig.tipDividerColor.hexString}" + } + } + private fun initEvent() = binding.run { rgTitleMode.setOnCheckedChangeListener { _, checkedId -> ReadBookConfig.titleMode = rgTitleMode.getIndexById(checkedId) @@ -178,6 +189,22 @@ class TipConfigDialog : BaseDialogFragment(R.layout.dialog_tip_config) { } } } + llTipDividerColor.setOnClickListener { + context?.selector(items = arrayListOf("默认", "跟随文字颜色", "自定义")) { _, i -> + when (i) { + 0, 1 -> { + ReadTipConfig.tipDividerColor = i - 1 + upTvTipDividerColor() + postEvent(EventBus.UP_CONFIG, true) + } + 2 -> ColorPickerDialog.newBuilder() + .setShowAlphaSlider(false) + .setDialogType(ColorPickerDialog.TYPE_CUSTOM) + .setDialogId(TIP_DIVIDER_COLOR) + .show(requireActivity()) + } + } + } } private fun clearRepeat(repeat: Int) = ReadTipConfig.apply { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index ba727f60e..59d5efe28 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -2,6 +2,7 @@ package io.legado.app.ui.book.read.page import android.annotation.SuppressLint import android.content.Context +import android.graphics.Color import android.view.LayoutInflater import android.widget.FrameLayout import androidx.core.view.isGone @@ -70,12 +71,21 @@ class PageView(context: Context) : FrameLayout(context) { val tipColor = with(ReadTipConfig) { if (tipColor == 0) it.textColor else tipColor } + val tipDividerColor = with(ReadTipConfig) { + when (tipDividerColor) { + -1 -> Color.parseColor("#66666666") + 0 -> tipColor + else -> tipDividerColor + } + } tvHeaderLeft.setColor(tipColor) tvHeaderMiddle.setColor(tipColor) tvHeaderRight.setColor(tipColor) tvFooterLeft.setColor(tipColor) tvFooterMiddle.setColor(tipColor) tvFooterRight.setColor(tipColor) + vwTopDivider.backgroundColor = tipDividerColor + vwBottomDivider.backgroundColor = tipDividerColor upStatusBar() llHeader.setPadding( it.headerPaddingLeft.dpToPx(), 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 dc8968325..b8ab036b2 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 @@ -8,7 +8,6 @@ import android.view.Menu import android.view.MenuItem import androidx.activity.viewModels import androidx.appcompat.widget.SearchView -import androidx.core.view.isGone import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentPagerAdapter import com.google.android.material.tabs.TabLayout @@ -19,8 +18,10 @@ import io.legado.app.help.book.isLocalTxt import io.legado.app.help.config.AppConfig import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.primaryTextColor +import io.legado.app.model.ReadBook import io.legado.app.ui.about.AppLogDialog import io.legado.app.ui.book.toc.rule.TxtTocRuleDialog +import io.legado.app.ui.widget.dialog.WaitDialog import io.legado.app.utils.applyTint import io.legado.app.utils.gone import io.legado.app.utils.showDialogFragment @@ -30,7 +31,8 @@ import io.legado.app.utils.visible /** * 目录 */ -class TocActivity : VMBaseActivity() { +class TocActivity : VMBaseActivity(), + TxtTocRuleDialog.CallBack { override val binding by viewBinding(ActivityChapterListBinding::inflate) override val viewModel by viewModels() @@ -38,6 +40,7 @@ class TocActivity : VMBaseActivity() { private lateinit var tabLayout: TabLayout private var menu: Menu? = null private var searchView: SearchView? = null + private val waitDialog by lazy { WaitDialog(this) } override fun onActivityCreated(savedInstanceState: Bundle?) { tabLayout = binding.titleBar.findViewById(R.id.tab_layout) @@ -122,6 +125,17 @@ class TocActivity : VMBaseActivity() { return super.onCompatOptionsItemSelected(item) } + override fun onTocRegexDialogResult(tocRegex: String) { + ReadBook.book?.let { book -> + book.tocUrl = tocRegex + waitDialog.show() + ReadBook.callBack?.loadChapterList(book) { + viewModel.initBook(book.bookUrl) + waitDialog.dismiss() + } + } + } + @Suppress("DEPRECATION") private inner class TabFragmentPageAdapter : FragmentPagerAdapter(supportFragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { diff --git a/app/src/main/res/layout/dialog_tip_config.xml b/app/src/main/res/layout/dialog_tip_config.xml index 2cd7353ab..2764e47a3 100644 --- a/app/src/main/res/layout/dialog_tip_config.xml +++ b/app/src/main/res/layout/dialog_tip_config.xml @@ -322,6 +322,32 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index a088a13b5..a69ff0917 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -1059,4 +1059,5 @@ 替换(启用/禁用) 显示上次更新时间 刷新列表 + 分隔线颜色 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 98ca97c84..0b784ec69 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -1062,4 +1062,5 @@ 替换(启用/禁用) 显示上次更新时间 刷新列表 + 分隔线颜色 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 21e9402c0..de5439ef4 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -1062,4 +1062,5 @@ 替换(启用/禁用) 显示上次更新时间 刷新列表 + 分隔线颜色 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 18005bc08..d0ed3b823 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -1059,4 +1059,5 @@ 替换(启用/禁用) 显示上次更新时间 刷新列表 + 分隔线颜色 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 02e02daca..797ecb5f9 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -1061,4 +1061,5 @@ 取代(啟用/禁用) 顯示上次更新時間 刷新列表 + 分隔线颜色 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 823eac757..f286ff772 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -1061,4 +1061,5 @@ 替换(启用/禁用) 显示上次更新时间 刷新列表 + 分隔线颜色 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 820f50c0c..650418452 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1062,4 +1062,5 @@ 替换(启用/禁用) 显示上次更新时间 刷新列表 + 分隔线颜色