fix: 漫画偏好设置问题

This commit is contained in:
HapeLee committed 2026-06-10 01:45:32 +08:00
1 parent 7bf9dfa09b
commit 43d5f6d5e2
19 files changed
+312 -540

No files matched your search

@@ -1,182 +0,0 @@
package io.legado.app.data.repository
import android.content.Context
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.emptyPreferences
import androidx.datastore.preferences.core.intPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import io.legado.app.constant.PreferKey
import io.legado.app.ui.book.manga.config.MangaScrollMode
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.map
import java.io.IOException
data class MangaPreferences(
val showMangaUi: Boolean = true,
val disableMangaScale: Boolean = true,
val disableMangaScrollAnimation: Boolean = false,
val disableMangaCrossFade: Boolean = false,
val disableClickScroll: Boolean = false,
val mangaPreDownloadNum: Int = 10,
val mangaAutoPageSpeed: Int = 3,
val mangaFooterConfig: String = "",
val mangaScrollMode: Int = MangaScrollMode.WEBTOON,
val mangaLongClick: Boolean = true,
val mangaBackground: Int = 0xFF000000.toInt(),
val mangaColorFilter: String = "",
val hideMangaTitle: Boolean = false,
val enableMangaEInk: Boolean = false,
val mangaEInkThreshold: Int = 150,
val enableMangaGray: Boolean = false,
val webtoonSidePaddingDp: Int = 0,
val mangaVolumeKeyPage: Boolean = false,
val reverseVolumeKeyPage: Boolean = false,
val clickActionTL: Int = -1,
val clickActionTC: Int = -1,
val clickActionTR: Int = 1,
val clickActionML: Int = 2,
val clickActionMC: Int = 0,
val clickActionMR: Int = 1,
val clickActionBL: Int = 2,
val clickActionBC: Int = 1,
val clickActionBR: Int = 1
)
class MangaSettingsRepository(
private val context: Context,
private val settingsRepository: SettingsRepository
) {
val preferences: Flow<MangaPreferences> = context.dataStore.data
.catch { exception ->
if (exception is IOException) {
emit(emptyPreferences())
} else {
throw exception
}
}
.map { preferences ->
preferences.toMangaPreferences()
}
suspend fun setShowMangaUi(value: Boolean) =
settingsRepository.putBoolean(PreferKey.showMangaUi, value)
suspend fun setMangaPreDownloadNum(value: Int) =
settingsRepository.putInt(PreferKey.mangaPreDownloadNum, value)
suspend fun setMangaAutoPageSpeed(value: Int) =
settingsRepository.putInt(PreferKey.mangaAutoPageSpeed, value)
suspend fun setDisableClickScroll(value: Boolean) =
settingsRepository.putBoolean(PreferKey.disableClickScroll, value)
suspend fun setDisableMangaScrollAnimation(value: Boolean) =
settingsRepository.putBoolean(PreferKey.disableMangaScrollAnimation, value)
suspend fun setDisableMangaCrossFade(value: Boolean) =
settingsRepository.putBoolean(PreferKey.disableMangaCrossFade, value)
suspend fun setDisableMangaScale(value: Boolean) =
settingsRepository.putBoolean(PreferKey.disableMangaScale, value)
suspend fun setEnableMangaEInk(value: Boolean) =
settingsRepository.putBoolean(PreferKey.enableMangaEInk, value)
suspend fun setMangaEInkThreshold(value: Int) =
settingsRepository.putInt(PreferKey.mangaEInkThreshold, value)
suspend fun setEnableMangaGray(value: Boolean) =
settingsRepository.putBoolean(PreferKey.enableMangaGray, value)
suspend fun setMangaAutoColorFilter(value: String) =
settingsRepository.putString(PreferKey.mangaColorFilter, value)
suspend fun setMangaBackground(value: Int) =
settingsRepository.putInt(PreferKey.mangaBackground, value)
suspend fun setMangaLongClick(value: Boolean) =
settingsRepository.putBoolean(PreferKey.mangaLongClick, value)
suspend fun setMangaVolumeKeyPage(value: Boolean) =
settingsRepository.putBoolean(PreferKey.mangaVolumeKeyPage, value)
suspend fun setReverseVolumeKeyPage(value: Boolean) =
settingsRepository.putBoolean(PreferKey.reverseVolumeKeyPage, value)
suspend fun setHideMangaTitle(value: Boolean) =
settingsRepository.putBoolean(PreferKey.hideMangaTitle, value)
suspend fun setMangaFooterConfig(value: String) =
settingsRepository.putString(PreferKey.mangaFooterConfig, value)
suspend fun setMangaClickAction(key: String, value: Int) =
settingsRepository.putInt(key, value)
private fun Preferences.toMangaPreferences(): MangaPreferences {
return MangaPreferences(
showMangaUi = this[Keys.ShowMangaUi] ?: true,
disableMangaScale = this[Keys.DisableMangaScale] ?: true,
disableMangaScrollAnimation = this[Keys.DisableMangaScrollAnimation] ?: false,
disableMangaCrossFade = this[Keys.DisableMangaCrossFade] ?: false,
disableClickScroll = this[Keys.DisableClickScroll] ?: false,
mangaPreDownloadNum = this[Keys.MangaPreDownloadNum] ?: 10,
mangaAutoPageSpeed = this[Keys.MangaAutoPageSpeed] ?: 3,
mangaFooterConfig = this[Keys.MangaFooterConfig] ?: "",
mangaScrollMode = this[Keys.MangaScrollMode] ?: MangaScrollMode.WEBTOON,
mangaLongClick = this[Keys.MangaLongClick] ?: true,
mangaBackground = this[Keys.MangaBackground] ?: 0xFF000000.toInt(),
mangaColorFilter = this[Keys.MangaColorFilter] ?: "",
hideMangaTitle = this[Keys.HideMangaTitle] ?: false,
enableMangaEInk = this[Keys.EnableMangaEInk] ?: false,
mangaEInkThreshold = this[Keys.MangaEInkThreshold] ?: 150,
enableMangaGray = this[Keys.EnableMangaGray] ?: false,
webtoonSidePaddingDp = this[Keys.WebtoonSidePaddingDp] ?: 0,
mangaVolumeKeyPage = this[Keys.MangaVolumeKeyPage] ?: false,
reverseVolumeKeyPage = this[Keys.ReverseVolumeKeyPage] ?: false,
clickActionTL = this[Keys.ClickActionTL] ?: -1,
clickActionTC = this[Keys.ClickActionTC] ?: -1,
clickActionTR = this[Keys.ClickActionTR] ?: 1,
clickActionML = this[Keys.ClickActionML] ?: 2,
clickActionMC = this[Keys.ClickActionMC] ?: 0,
clickActionMR = this[Keys.ClickActionMR] ?: 1,
clickActionBL = this[Keys.ClickActionBL] ?: 2,
clickActionBC = this[Keys.ClickActionBC] ?: 1,
clickActionBR = this[Keys.ClickActionBR] ?: 1
)
}
private object Keys {
val ShowMangaUi = booleanPreferencesKey(PreferKey.showMangaUi)
val DisableMangaScale = booleanPreferencesKey(PreferKey.disableMangaScale)
val DisableMangaScrollAnimation =
booleanPreferencesKey(PreferKey.disableMangaScrollAnimation)
val DisableMangaCrossFade = booleanPreferencesKey(PreferKey.disableMangaCrossFade)
val DisableClickScroll = booleanPreferencesKey(PreferKey.disableClickScroll)
val MangaPreDownloadNum = intPreferencesKey(PreferKey.mangaPreDownloadNum)
val MangaAutoPageSpeed = intPreferencesKey(PreferKey.mangaAutoPageSpeed)
val MangaFooterConfig = stringPreferencesKey(PreferKey.mangaFooterConfig)
val MangaScrollMode = intPreferencesKey(PreferKey.mangaScrollMode)
val MangaLongClick = booleanPreferencesKey(PreferKey.mangaLongClick)
val MangaBackground = intPreferencesKey(PreferKey.mangaBackground)
val MangaColorFilter = stringPreferencesKey(PreferKey.mangaColorFilter)
val HideMangaTitle = booleanPreferencesKey(PreferKey.hideMangaTitle)
val EnableMangaEInk = booleanPreferencesKey(PreferKey.enableMangaEInk)
val MangaEInkThreshold = intPreferencesKey(PreferKey.mangaEInkThreshold)
val EnableMangaGray = booleanPreferencesKey(PreferKey.enableMangaGray)
val WebtoonSidePaddingDp = intPreferencesKey(PreferKey.webtoonSidePaddingDp)
val MangaVolumeKeyPage = booleanPreferencesKey(PreferKey.mangaVolumeKeyPage)
val ReverseVolumeKeyPage = booleanPreferencesKey(PreferKey.reverseVolumeKeyPage)
val ClickActionTL = intPreferencesKey(PreferKey.mangaClickActionTL)
val ClickActionTC = intPreferencesKey(PreferKey.mangaClickActionTC)
val ClickActionTR = intPreferencesKey(PreferKey.mangaClickActionTR)
val ClickActionML = intPreferencesKey(PreferKey.mangaClickActionML)
val ClickActionMC = intPreferencesKey(PreferKey.mangaClickActionMC)
val ClickActionMR = intPreferencesKey(PreferKey.mangaClickActionMR)
val ClickActionBL = intPreferencesKey(PreferKey.mangaClickActionBL)
val ClickActionBC = intPreferencesKey(PreferKey.mangaClickActionBC)
val ClickActionBR = intPreferencesKey(PreferKey.mangaClickActionBR)
}
}
@@ -25,7 +25,6 @@ import io.legado.app.data.repository.ExploreRepositoryImpl
import io.legado.app.data.repository.HomepageModulesRepository
import io.legado.app.data.repository.LlmTranslateRepositoryImpl
import io.legado.app.data.repository.LocalBookRepository
import io.legado.app.data.repository.MangaSettingsRepository
import io.legado.app.data.repository.ReadBookStyleConfigRepository
import io.legado.app.data.repository.ReadAloudSettingsRepository
import io.legado.app.data.repository.ReadRecordRepository
@@ -157,7 +156,6 @@ val appModule = module {
singleOf(::ReadSettingsRepository)
singleOf(::ReadAloudSettingsRepository)
singleOf(::ReadBookStyleConfigRepository)
singleOf(::MangaSettingsRepository)
singleOf(::LocalPreferencesRepository)
singleOf(::ExploreBooksUseCase)
singleOf(::ExploreKindUiUseCase)
@@ -5,7 +5,6 @@ import io.legado.app.BuildConfig
import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
import io.legado.app.data.repository.ReadPreferences
import io.legado.app.ui.book.manga.config.MangaScrollMode
import io.legado.app.ui.config.backupConfig.BackupConfig
import io.legado.app.ui.config.bookshelfConfig.BookshelfConfig
import io.legado.app.ui.config.coverConfig.CoverConfig
@@ -13,6 +12,7 @@ import io.legado.app.ui.config.downloadCacheConfig.DownloadCacheConfig
import io.legado.app.ui.config.importBookConfig.ImportBookConfig
import io.legado.app.ui.config.otherConfig.OtherConfig
import io.legado.app.ui.config.readConfig.ReadConfig
import io.legado.app.ui.config.readMangaConfig.ReadMangaConfig
import io.legado.app.ui.config.themeConfig.ThemeConfig
import io.legado.app.utils.canvasrecorder.CanvasRecorderFactory
import io.legado.app.utils.getPrefBoolean
@@ -46,15 +46,33 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
var clickActionBR = appCtx.getPrefInt(PreferKey.clickActionBR, 1)
// -1无操作 1下一页 2上一页 0显示菜单
var mangaClickActionTL = appCtx.getPrefInt(PreferKey.mangaClickActionTL, -1)
var mangaClickActionTC = appCtx.getPrefInt(PreferKey.mangaClickActionTC, -1)
var mangaClickActionTR = appCtx.getPrefInt(PreferKey.mangaClickActionTR, 1)
var mangaClickActionML = appCtx.getPrefInt(PreferKey.mangaClickActionML, 2)
var mangaClickActionMC = appCtx.getPrefInt(PreferKey.mangaClickActionMC, 0)
var mangaClickActionMR = appCtx.getPrefInt(PreferKey.mangaClickActionMR, 1)
var mangaClickActionBL = appCtx.getPrefInt(PreferKey.mangaClickActionBL, 2)
var mangaClickActionBC = appCtx.getPrefInt(PreferKey.mangaClickActionBC, 1)
var mangaClickActionBR = appCtx.getPrefInt(PreferKey.mangaClickActionBR, 1)
var mangaClickActionTL
get() = ReadMangaConfig.mangaClickActionTL
set(value) { ReadMangaConfig.mangaClickActionTL = value }
var mangaClickActionTC
get() = ReadMangaConfig.mangaClickActionTC
set(value) { ReadMangaConfig.mangaClickActionTC = value }
var mangaClickActionTR
get() = ReadMangaConfig.mangaClickActionTR
set(value) { ReadMangaConfig.mangaClickActionTR = value }
var mangaClickActionML
get() = ReadMangaConfig.mangaClickActionML
set(value) { ReadMangaConfig.mangaClickActionML = value }
var mangaClickActionMC
get() = ReadMangaConfig.mangaClickActionMC
set(value) { ReadMangaConfig.mangaClickActionMC = value }
var mangaClickActionMR
get() = ReadMangaConfig.mangaClickActionMR
set(value) { ReadMangaConfig.mangaClickActionMR = value }
var mangaClickActionBL
get() = ReadMangaConfig.mangaClickActionBL
set(value) { ReadMangaConfig.mangaClickActionBL = value }
var mangaClickActionBC
get() = ReadMangaConfig.mangaClickActionBC
set(value) { ReadMangaConfig.mangaClickActionBC = value }
var mangaClickActionBR
get() = ReadMangaConfig.mangaClickActionBR
set(value) { ReadMangaConfig.mangaClickActionBR = value }
val AppTheme get() = ThemeConfig.appTheme
@@ -160,33 +178,6 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
PreferKey.clickActionBR -> clickActionBR =
appCtx.getPrefInt(PreferKey.clickActionBR, 1)
PreferKey.mangaClickActionTL -> mangaClickActionTL =
appCtx.getPrefInt(PreferKey.mangaClickActionTL, -1)
PreferKey.mangaClickActionTC -> mangaClickActionTC =
appCtx.getPrefInt(PreferKey.mangaClickActionTC, -1)
PreferKey.mangaClickActionTR -> mangaClickActionTR =
appCtx.getPrefInt(PreferKey.mangaClickActionTR, 1)
PreferKey.mangaClickActionML -> mangaClickActionML =
appCtx.getPrefInt(PreferKey.mangaClickActionML, 2)
PreferKey.mangaClickActionMC -> mangaClickActionMC =
appCtx.getPrefInt(PreferKey.mangaClickActionMC, 0)
PreferKey.mangaClickActionMR -> mangaClickActionMR =
appCtx.getPrefInt(PreferKey.mangaClickActionMR, 1)
PreferKey.mangaClickActionBL -> mangaClickActionBL =
appCtx.getPrefInt(PreferKey.mangaClickActionBL, 2)
PreferKey.mangaClickActionBC -> mangaClickActionBC =
appCtx.getPrefInt(PreferKey.mangaClickActionBC, 1)
PreferKey.mangaClickActionBR -> mangaClickActionBR =
appCtx.getPrefInt(PreferKey.mangaClickActionBR, 1)
PreferKey.readBodyToLh -> ReadBookConfig.readBodyToLh =
appCtx.getPrefBoolean(PreferKey.readBodyToLh, true)
@@ -745,13 +736,7 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
}
fun detectMangaClickArea() {
if (mangaClickActionTL * mangaClickActionTC * mangaClickActionTR
* mangaClickActionML * mangaClickActionMC * mangaClickActionMR
* mangaClickActionBL * mangaClickActionBC * mangaClickActionBR != 0
) {
appCtx.putPrefInt(PreferKey.mangaClickActionMC, 0)
appCtx.toastOnUi("当前没有配置菜单区域,自动恢复中间区域为菜单.")
}
ReadMangaConfig.detectMangaClickArea()
}
var firebaseEnable: Boolean
@@ -762,26 +747,20 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
//跳转到漫画界面不使用富文本模式
val showMangaUi: Boolean
get() = appCtx.getPrefBoolean(PreferKey.showMangaUi, true)
get() = ReadMangaConfig.showMangaUi
//禁用漫画缩放
var disableMangaScale: Boolean
get() = appCtx.getPrefBoolean(PreferKey.disableMangaScale, true)
set(value) {
appCtx.putPrefBoolean(PreferKey.disableMangaScale, value)
}
get() = ReadMangaConfig.disableMangaScale
set(value) { ReadMangaConfig.disableMangaScale = value }
var disableMangaScrollAnimation: Boolean
get() = appCtx.getPrefBoolean(PreferKey.disableMangaScrollAnimation, false)
set(value) {
appCtx.putPrefBoolean(PreferKey.disableMangaScrollAnimation, value)
}
get() = ReadMangaConfig.disableMangaScrollAnimation
set(value) { ReadMangaConfig.disableMangaScrollAnimation = value }
var disableMangaCrossFade: Boolean
get() = appCtx.getPrefBoolean(PreferKey.disableMangaCrossFade, false)
set(value) {
appCtx.putPrefBoolean(PreferKey.disableMangaCrossFade, value)
}
get() = ReadMangaConfig.disableMangaCrossFade
set(value) { ReadMangaConfig.disableMangaCrossFade = value }
var titleBarMode
get() = ReadConfig.titleBarMode
@@ -791,105 +770,75 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
//漫画预加载数量
var mangaPreDownloadNum
get() = appCtx.getPrefInt(PreferKey.mangaPreDownloadNum, 10)
set(value) {
appCtx.putPrefInt(PreferKey.mangaPreDownloadNum, value)
}
get() = ReadMangaConfig.mangaPreDownloadNum
set(value) { ReadMangaConfig.mangaPreDownloadNum = value }
//点击翻页
var disableClickScroll
get() = appCtx.getPrefBoolean(PreferKey.disableClickScroll, false)
set(value) {
appCtx.putPrefBoolean(PreferKey.disableClickScroll, value)
}
get() = ReadMangaConfig.disableClickScroll
set(value) { ReadMangaConfig.disableClickScroll = value }
//漫画滚动速度
var mangaAutoPageSpeed
get() = appCtx.getPrefInt(PreferKey.mangaAutoPageSpeed, 3)
set(value) {
appCtx.putPrefInt(PreferKey.mangaAutoPageSpeed, value)
}
get() = ReadMangaConfig.mangaAutoPageSpeed
set(value) { ReadMangaConfig.mangaAutoPageSpeed = value }
//漫画页脚配置
var mangaFooterConfig
get() = appCtx.getPrefString(PreferKey.mangaFooterConfig, "")
set(value) {
appCtx.putPrefString(PreferKey.mangaFooterConfig, value)
}
get() = ReadMangaConfig.mangaFooterConfig
set(value) { ReadMangaConfig.mangaFooterConfig = value }
//漫画滚动方式
var mangaScrollMode: Int
get() = appCtx.getPrefInt(PreferKey.mangaScrollMode, MangaScrollMode.WEBTOON)
set(value) {
appCtx.putPrefInt(PreferKey.mangaScrollMode, value)
}
get() = ReadMangaConfig.mangaScrollMode
set(value) { ReadMangaConfig.mangaScrollMode = value }
var mangaLongClick
get() = appCtx.getPrefBoolean(PreferKey.mangaLongClick, true)
set(value) {
appCtx.putPrefBoolean(PreferKey.mangaLongClick, value)
}
get() = ReadMangaConfig.mangaLongClick
set(value) { ReadMangaConfig.mangaLongClick = value }
var mangaBackground: Int
get() = appCtx.getPrefInt(PreferKey.mangaBackground, 0xFF000000.toInt())
set(value) {
appCtx.putPrefInt(PreferKey.mangaBackground, value)
}
get() = ReadMangaConfig.mangaBackground
set(value) { ReadMangaConfig.mangaBackground = value }
//漫画滤镜
var mangaColorFilter
get() = appCtx.getPrefString(PreferKey.mangaColorFilter, "")
set(value) {
appCtx.putPrefString(PreferKey.mangaColorFilter, value)
}
get() = ReadMangaConfig.mangaColorFilter
set(value) { ReadMangaConfig.mangaColorFilter = value }