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 5e8f84640..9511c9da1 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -69,6 +69,7 @@ object PreferKey { const val launcherIcon = "launcherIcon" const val textSelectAble = "selectText" const val shareLayout = "shareLayout" + const val comicStyleSelect = "comicStyleSelect" const val readStyleSelect = "readStyleSelect" const val systemTypefaces = "system_typefaces" const val readBodyToLh = "readBodyToLh" 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 2c5246193..40775f486 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 @@ -56,6 +56,7 @@ object ReadBookConfig { } } + var isComic: Boolean = false var bg: Drawable? = null var bgMeanColor: Int = 0 val textColor: Int get() = durConfig.curTextColor() @@ -150,9 +151,13 @@ object ReadBookConfig { fun deleteDur(): Boolean { if (configList.size > 5) { configList.removeAt(styleSelect) - if (styleSelect > 0) { - styleSelect -= 1 + if (styleSelect <= readStyleSelect) { + readStyleSelect -= 1 } + if (styleSelect <= comicStyleSelect) { + comicStyleSelect -= 1 + } + styleSelect = initSelectStyle() return true } return false @@ -173,13 +178,20 @@ object ReadBookConfig { field = value appCtx.putPrefInt(PreferKey.autoReadSpeed, value) } - var styleSelect = appCtx.getPrefInt(PreferKey.readStyleSelect) + var readStyleSelect = appCtx.getPrefInt(PreferKey.readStyleSelect) set(value) { field = value if (appCtx.getPrefInt(PreferKey.readStyleSelect) != value) { appCtx.putPrefInt(PreferKey.readStyleSelect, value) } } + var comicStyleSelect = appCtx.getPrefInt(PreferKey.comicStyleSelect, readStyleSelect) + set(value) { + field = value + if (appCtx.getPrefInt(PreferKey.comicStyleSelect) != value) { + appCtx.putPrefInt(PreferKey.comicStyleSelect, value) + } + } var shareLayout = appCtx.getPrefBoolean(PreferKey.shareLayout) set(value) { field = value @@ -188,6 +200,26 @@ object ReadBookConfig { } } + var styleSelect = initSelectStyle() + fun initSelectStyle(): Int { + return if (isComic) { + comicStyleSelect + }else { + readStyleSelect + } + } + + fun updateStyleSelect(value: Int) { + if (styleSelect != value) { + if (isComic) { + comicStyleSelect = value + }else { + readStyleSelect = value + } + styleSelect = value + } + } + /** * 两端对齐 */ diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 706d298f8..69ccbecdf 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -259,7 +259,9 @@ object Restore { edit.apply() } ReadBookConfig.apply { - styleSelect = appCtx.getPrefInt(PreferKey.readStyleSelect) + comicStyleSelect = appCtx.getPrefInt(PreferKey.comicStyleSelect) + readStyleSelect = appCtx.getPrefInt(PreferKey.readStyleSelect) + styleSelect = initSelectStyle() shareLayout = appCtx.getPrefBoolean(PreferKey.shareLayout) hideStatusBar = appCtx.getPrefBoolean(PreferKey.hideStatusBar) hideNavigationBar = appCtx.getPrefBoolean(PreferKey.hideNavigationBar) 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 df43ae71a..31bf7085a 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 @@ -255,6 +255,11 @@ class ReadBookActivity : BaseReadBookActivity(), private var justInitData: Boolean = false private var syncDialog: AlertDialog? = null + override fun onStart() { + viewModel.initBookType(intent) { upStyle() } + super.onStart() + } + @SuppressLint("ClickableViewAccessibility") override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) @@ -401,6 +406,14 @@ class ReadBookActivity : BaseReadBookActivity(), return super.onMenuOpened(featureId, menu) } + private fun upStyle() { + val oldIndex = ReadBookConfig.styleSelect + ReadBookConfig.styleSelect = ReadBookConfig.initSelectStyle() + if (oldIndex != ReadBookConfig.styleSelect){ + postEvent(EventBus.UP_CONFIG, arrayListOf(1, 2, 5)) + } + } + /** * 更新菜单 */ @@ -580,7 +593,7 @@ class ReadBookActivity : BaseReadBookActivity(), } R.id.menu_cover_progress -> ReadBook.book?.let { - ReadBook.uploadProgress({ toastOnUi(R.string.upload_book_success) }) + ReadBook.uploadProgress { toastOnUi(R.string.upload_book_success) } } R.id.menu_same_title_removed -> { 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 377fa163e..7c5c8d554 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 @@ -23,6 +23,7 @@ import io.legado.app.help.book.isLocalModified import io.legado.app.help.book.removeType import io.legado.app.help.book.simulatedTotalChapterNum import io.legado.app.help.config.AppConfig +import io.legado.app.help.config.ReadBookConfig import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.ImageProvider import io.legado.app.model.ReadAloud @@ -67,6 +68,16 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { AppConfig.detectClickArea() } + fun initBookType(intent: Intent, callBack: (() -> Unit)? = null) { + val bookUrl = intent.getStringExtra("bookUrl") + val book = when { + bookUrl.isNullOrEmpty() -> appDb.bookDao.lastReadBook + else -> appDb.bookDao.getBook(bookUrl) + } + ReadBookConfig.isComic = book?.type == BookType.image + callBack?.invoke() + } + /** * 初始化 */ 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 008996766..cae4c6502 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 @@ -165,7 +165,7 @@ class ReadStyleDialog : BaseDialogFragment(R.layout.dialog_read_book_style), private fun changeBgTextConfig(index: Int) { val oldIndex = ReadBookConfig.styleSelect if (index != oldIndex) { - ReadBookConfig.styleSelect = index + ReadBookConfig.updateStyleSelect(index) upView() styleAdapter.notifyItemChanged(oldIndex) styleAdapter.notifyItemChanged(index)