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 40775f486..e7e198140 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 @@ -150,14 +150,14 @@ object ReadBookConfig { fun deleteDur(): Boolean { if (configList.size > 5) { - configList.removeAt(styleSelect) - if (styleSelect <= readStyleSelect) { + val removeIndex = styleSelect + configList.removeAt(removeIndex) + if (removeIndex <= readStyleSelect) { readStyleSelect -= 1 } - if (styleSelect <= comicStyleSelect) { + if (removeIndex <= comicStyleSelect) { comicStyleSelect -= 1 } - styleSelect = initSelectStyle() return true } return false @@ -178,6 +178,15 @@ object ReadBookConfig { field = value appCtx.putPrefInt(PreferKey.autoReadSpeed, value) } + var styleSelect: Int + get() = if (isComic) comicStyleSelect else readStyleSelect + set(value) { + if (isComic) { + comicStyleSelect = value + } else { + readStyleSelect = value + } + } var readStyleSelect = appCtx.getPrefInt(PreferKey.readStyleSelect) set(value) { field = value @@ -200,26 +209,6 @@ 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 69ccbecdf..a0b5e70cc 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 @@ -261,7 +261,6 @@ object Restore { ReadBookConfig.apply { 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/model/ReadBook.kt b/app/src/main/java/io/legado/app/model/ReadBook.kt index 43ea8583f..920469453 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -1,6 +1,7 @@ package io.legado.app.model import io.legado.app.constant.AppLog +import io.legado.app.constant.EventBus import io.legado.app.constant.PageAnim.scrollPageAnim import io.legado.app.data.appDb import io.legado.app.data.entities.Book @@ -11,6 +12,7 @@ import io.legado.app.data.entities.ReadRecord import io.legado.app.help.AppWebDav import io.legado.app.help.book.BookHelp import io.legado.app.help.book.ContentProcessor +import io.legado.app.help.book.isImage import io.legado.app.help.book.isLocal import io.legado.app.help.book.readSimulating import io.legado.app.help.book.simulatedTotalChapterNum @@ -24,6 +26,7 @@ import io.legado.app.service.BaseReadAloudService import io.legado.app.ui.book.read.page.entities.TextChapter import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.book.read.page.provider.LayoutProgressListener +import io.legado.app.utils.postEvent import io.legado.app.utils.stackTraceStr import io.legado.app.utils.toastOnUi import kotlinx.coroutines.CoroutineScope @@ -174,6 +177,14 @@ object ReadBook : CoroutineScope by MainScope() { } } + fun upReadBookConfig(book: Book) { + val oldIndex = ReadBookConfig.styleSelect + ReadBookConfig.isComic = book.isImage + if (oldIndex != ReadBookConfig.styleSelect) { + postEvent(EventBus.UP_CONFIG, arrayListOf(1, 2, 5)) + } + } + fun setProgress(progress: BookProgress) { if (progress.durChapterIndex < chapterSize && (durChapterIndex != progress.durChapterIndex 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 31bf7085a..604f09cdd 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,11 +255,6 @@ 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) @@ -299,6 +294,7 @@ class ReadBookActivity : BaseReadBookActivity(), override fun onPostCreate(savedInstanceState: Bundle?) { super.onPostCreate(savedInstanceState) + viewModel.initReadBookConfig(intent) Looper.myQueue().addIdleHandler { viewModel.initData(intent) false @@ -406,14 +402,6 @@ 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)) - } - } - /** * 更新菜单 */ 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 7c5c8d554..73d64e3b9 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,7 +23,6 @@ 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 @@ -68,14 +67,13 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { AppConfig.detectClickArea() } - fun initBookType(intent: Intent, callBack: (() -> Unit)? = null) { + fun initReadBookConfig(intent: Intent) { 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() + } ?: return + ReadBook.upReadBookConfig(book) } /** 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 cae4c6502..008996766 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.updateStyleSelect(index) + ReadBookConfig.styleSelect = index upView() styleAdapter.notifyItemChanged(oldIndex) styleAdapter.notifyItemChanged(index) diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt index 0b9da4319..0d3041224 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt @@ -21,7 +21,6 @@ import io.legado.app.help.glide.ImageLoader import io.legado.app.help.glide.OkHttpModelLoader import io.legado.app.lib.theme.accentColor import io.legado.app.model.BookCover -import io.legado.app.utils.LogUtils import io.legado.app.utils.textHeight import io.legado.app.utils.toStringArray @@ -159,7 +158,6 @@ class CoverImageView @JvmOverloads constructor( target: Target, isFirstResource: Boolean ): Boolean { - LogUtils.d("CoverImageView", "glide load fail model:$model\ne:$e") defaultCover = true return false } @@ -189,8 +187,8 @@ class CoverImageView @JvmOverloads constructor( this.bitmapPath = path this.name = name?.replace(AppPattern.bdRegex, "")?.trim() this.author = author?.replace(AppPattern.bdRegex, "")?.trim() + defaultCover = true if (AppConfig.useDefaultCover) { - defaultCover = true ImageLoader.load(context, BookCover.defaultDrawable) .centerCrop() .into(this)