漫画(图片)和书籍(文本)可以分别设置布局 (#4479)

* 漫画(图片)和书籍(文本)可以分别设置布局

* 优化
This commit is contained in:
niuhb 2024-12-30 11:48:42 +08:00 committed by GitHub
parent 9ee30fc86c
commit f1f1f3cd6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 65 additions and 6 deletions

View File

@ -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"

View File

@ -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
}
}
/**
* 两端对齐
*/

View File

@ -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)

View File

@ -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 -> {

View File

@ -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()
}
/**
* 初始化
*/

View File

@ -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)