Skip to content

Commit

Permalink
漫画(图片)和书籍(文本)可以分别设置布局 (#4479)
Browse files Browse the repository at this point in the history
* 漫画(图片)和书籍(文本)可以分别设置布局

* 优化
  • Loading branch information
niu-hb authored Dec 30, 2024
1 parent 9ee30fc commit f1f1f3c
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/io/legado/app/constant/PreferKey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
38 changes: 35 additions & 3 deletions app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ object ReadBookConfig {
}
}

var isComic: Boolean = false
var bg: Drawable? = null
var bgMeanColor: Int = 0
val textColor: Int get() = durConfig.curTextColor()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
}

/**
* 两端对齐
*/
Expand Down
4 changes: 3 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 @@ -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)
Expand Down
15 changes: 14 additions & 1 deletion 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,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)
Expand Down Expand Up @@ -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))
}
}

/**
* 更新菜单
*/
Expand Down Expand Up @@ -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 -> {
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}

/**
* 初始化
*/
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.styleSelect = index
ReadBookConfig.updateStyleSelect(index)
upView()
styleAdapter.notifyItemChanged(oldIndex)
styleAdapter.notifyItemChanged(index)
Expand Down

0 comments on commit f1f1f3c

Please sign in to comment.