Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Dec 30, 2024
1 parent f1f1f3c commit 07f7f1b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 47 deletions.
37 changes: 13 additions & 24 deletions app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
}

/**
* 两端对齐
*/
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/io/legado/app/help/storage/Restore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/io/legado/app/model/ReadBook.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 1 addition & 13 deletions app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
}
}

/**
* 更新菜单
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -159,7 +158,6 @@ class CoverImageView @JvmOverloads constructor(
target: Target<Drawable>,
isFirstResource: Boolean
): Boolean {
LogUtils.d("CoverImageView", "glide load fail model:$model\ne:$e")
defaultCover = true
return false
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 07f7f1b

Please sign in to comment.