mirror of
https://github.com/gedoor/legado.git
synced 2025-01-08 11:47:32 +08:00
优化
This commit is contained in:
parent
f1f1f3cd6b
commit
07f7f1bf3e
@ -150,14 +150,14 @@ object ReadBookConfig {
|
|||||||
|
|
||||||
fun deleteDur(): Boolean {
|
fun deleteDur(): Boolean {
|
||||||
if (configList.size > 5) {
|
if (configList.size > 5) {
|
||||||
configList.removeAt(styleSelect)
|
val removeIndex = styleSelect
|
||||||
if (styleSelect <= readStyleSelect) {
|
configList.removeAt(removeIndex)
|
||||||
|
if (removeIndex <= readStyleSelect) {
|
||||||
readStyleSelect -= 1
|
readStyleSelect -= 1
|
||||||
}
|
}
|
||||||
if (styleSelect <= comicStyleSelect) {
|
if (removeIndex <= comicStyleSelect) {
|
||||||
comicStyleSelect -= 1
|
comicStyleSelect -= 1
|
||||||
}
|
}
|
||||||
styleSelect = initSelectStyle()
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@ -178,6 +178,15 @@ object ReadBookConfig {
|
|||||||
field = value
|
field = value
|
||||||
appCtx.putPrefInt(PreferKey.autoReadSpeed, 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)
|
var readStyleSelect = appCtx.getPrefInt(PreferKey.readStyleSelect)
|
||||||
set(value) {
|
set(value) {
|
||||||
field = 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 {
|
ReadBookConfig.apply {
|
||||||
comicStyleSelect = appCtx.getPrefInt(PreferKey.comicStyleSelect)
|
comicStyleSelect = appCtx.getPrefInt(PreferKey.comicStyleSelect)
|
||||||
readStyleSelect = appCtx.getPrefInt(PreferKey.readStyleSelect)
|
readStyleSelect = appCtx.getPrefInt(PreferKey.readStyleSelect)
|
||||||
styleSelect = initSelectStyle()
|
|
||||||
shareLayout = appCtx.getPrefBoolean(PreferKey.shareLayout)
|
shareLayout = appCtx.getPrefBoolean(PreferKey.shareLayout)
|
||||||
hideStatusBar = appCtx.getPrefBoolean(PreferKey.hideStatusBar)
|
hideStatusBar = appCtx.getPrefBoolean(PreferKey.hideStatusBar)
|
||||||
hideNavigationBar = appCtx.getPrefBoolean(PreferKey.hideNavigationBar)
|
hideNavigationBar = appCtx.getPrefBoolean(PreferKey.hideNavigationBar)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package io.legado.app.model
|
package io.legado.app.model
|
||||||
|
|
||||||
import io.legado.app.constant.AppLog
|
import io.legado.app.constant.AppLog
|
||||||
|
import io.legado.app.constant.EventBus
|
||||||
import io.legado.app.constant.PageAnim.scrollPageAnim
|
import io.legado.app.constant.PageAnim.scrollPageAnim
|
||||||
import io.legado.app.data.appDb
|
import io.legado.app.data.appDb
|
||||||
import io.legado.app.data.entities.Book
|
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.AppWebDav
|
||||||
import io.legado.app.help.book.BookHelp
|
import io.legado.app.help.book.BookHelp
|
||||||
import io.legado.app.help.book.ContentProcessor
|
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.isLocal
|
||||||
import io.legado.app.help.book.readSimulating
|
import io.legado.app.help.book.readSimulating
|
||||||
import io.legado.app.help.book.simulatedTotalChapterNum
|
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.entities.TextChapter
|
||||||
import io.legado.app.ui.book.read.page.provider.ChapterProvider
|
import io.legado.app.ui.book.read.page.provider.ChapterProvider
|
||||||
import io.legado.app.ui.book.read.page.provider.LayoutProgressListener
|
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.stackTraceStr
|
||||||
import io.legado.app.utils.toastOnUi
|
import io.legado.app.utils.toastOnUi
|
||||||
import kotlinx.coroutines.CoroutineScope
|
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) {
|
fun setProgress(progress: BookProgress) {
|
||||||
if (progress.durChapterIndex < chapterSize &&
|
if (progress.durChapterIndex < chapterSize &&
|
||||||
(durChapterIndex != progress.durChapterIndex
|
(durChapterIndex != progress.durChapterIndex
|
||||||
|
@ -255,11 +255,6 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
private var justInitData: Boolean = false
|
private var justInitData: Boolean = false
|
||||||
private var syncDialog: AlertDialog? = null
|
private var syncDialog: AlertDialog? = null
|
||||||
|
|
||||||
override fun onStart() {
|
|
||||||
viewModel.initBookType(intent) { upStyle() }
|
|
||||||
super.onStart()
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
super.onActivityCreated(savedInstanceState)
|
super.onActivityCreated(savedInstanceState)
|
||||||
@ -299,6 +294,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
|
|
||||||
override fun onPostCreate(savedInstanceState: Bundle?) {
|
override fun onPostCreate(savedInstanceState: Bundle?) {
|
||||||
super.onPostCreate(savedInstanceState)
|
super.onPostCreate(savedInstanceState)
|
||||||
|
viewModel.initReadBookConfig(intent)
|
||||||
Looper.myQueue().addIdleHandler {
|
Looper.myQueue().addIdleHandler {
|
||||||
viewModel.initData(intent)
|
viewModel.initData(intent)
|
||||||
false
|
false
|
||||||
@ -406,14 +402,6 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
return super.onMenuOpened(featureId, menu)
|
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.removeType
|
||||||
import io.legado.app.help.book.simulatedTotalChapterNum
|
import io.legado.app.help.book.simulatedTotalChapterNum
|
||||||
import io.legado.app.help.config.AppConfig
|
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.help.coroutine.Coroutine
|
||||||
import io.legado.app.model.ImageProvider
|
import io.legado.app.model.ImageProvider
|
||||||
import io.legado.app.model.ReadAloud
|
import io.legado.app.model.ReadAloud
|
||||||
@ -68,14 +67,13 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
AppConfig.detectClickArea()
|
AppConfig.detectClickArea()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun initBookType(intent: Intent, callBack: (() -> Unit)? = null) {
|
fun initReadBookConfig(intent: Intent) {
|
||||||
val bookUrl = intent.getStringExtra("bookUrl")
|
val bookUrl = intent.getStringExtra("bookUrl")
|
||||||
val book = when {
|
val book = when {
|
||||||
bookUrl.isNullOrEmpty() -> appDb.bookDao.lastReadBook
|
bookUrl.isNullOrEmpty() -> appDb.bookDao.lastReadBook
|
||||||
else -> appDb.bookDao.getBook(bookUrl)
|
else -> appDb.bookDao.getBook(bookUrl)
|
||||||
}
|
} ?: return
|
||||||
ReadBookConfig.isComic = book?.type == BookType.image
|
ReadBook.upReadBookConfig(book)
|
||||||
callBack?.invoke()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -165,7 +165,7 @@ class ReadStyleDialog : BaseDialogFragment(R.layout.dialog_read_book_style),
|
|||||||
private fun changeBgTextConfig(index: Int) {
|
private fun changeBgTextConfig(index: Int) {
|
||||||
val oldIndex = ReadBookConfig.styleSelect
|
val oldIndex = ReadBookConfig.styleSelect
|
||||||
if (index != oldIndex) {
|
if (index != oldIndex) {
|
||||||
ReadBookConfig.updateStyleSelect(index)
|
ReadBookConfig.styleSelect = index
|
||||||
upView()
|
upView()
|
||||||
styleAdapter.notifyItemChanged(oldIndex)
|
styleAdapter.notifyItemChanged(oldIndex)
|
||||||
styleAdapter.notifyItemChanged(index)
|
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.help.glide.OkHttpModelLoader
|
||||||
import io.legado.app.lib.theme.accentColor
|
import io.legado.app.lib.theme.accentColor
|
||||||
import io.legado.app.model.BookCover
|
import io.legado.app.model.BookCover
|
||||||
import io.legado.app.utils.LogUtils
|
|
||||||
import io.legado.app.utils.textHeight
|
import io.legado.app.utils.textHeight
|
||||||
import io.legado.app.utils.toStringArray
|
import io.legado.app.utils.toStringArray
|
||||||
|
|
||||||
@ -159,7 +158,6 @@ class CoverImageView @JvmOverloads constructor(
|
|||||||
target: Target<Drawable>,
|
target: Target<Drawable>,
|
||||||
isFirstResource: Boolean
|
isFirstResource: Boolean
|
||||||
): Boolean {
|
): Boolean {
|
||||||
LogUtils.d("CoverImageView", "glide load fail model:$model\ne:$e")
|
|
||||||
defaultCover = true
|
defaultCover = true
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -189,8 +187,8 @@ class CoverImageView @JvmOverloads constructor(
|
|||||||
this.bitmapPath = path
|
this.bitmapPath = path
|
||||||
this.name = name?.replace(AppPattern.bdRegex, "")?.trim()
|
this.name = name?.replace(AppPattern.bdRegex, "")?.trim()
|
||||||
this.author = author?.replace(AppPattern.bdRegex, "")?.trim()
|
this.author = author?.replace(AppPattern.bdRegex, "")?.trim()
|
||||||
|
defaultCover = true
|
||||||
if (AppConfig.useDefaultCover) {
|
if (AppConfig.useDefaultCover) {
|
||||||
defaultCover = true
|
|
||||||
ImageLoader.load(context, BookCover.defaultDrawable)
|
ImageLoader.load(context, BookCover.defaultDrawable)
|
||||||
.centerCrop()
|
.centerCrop()
|
||||||
.into(this)
|
.into(this)
|
||||||
|
Loading…
Reference in New Issue
Block a user