mirror of
https://github.com/gedoor/legado.git
synced 2025-01-07 03:06:58 +08:00
优化
This commit is contained in:
parent
f1f1f3cd6b
commit
07f7f1bf3e
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 两端对齐
|
||||
*/
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新菜单
|
||||
*/
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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)
|
||||
|
@ -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<Drawable>,
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user