|
@@ -78,7 +78,6 @@ import io.legado.app.ui.config.themeConfig.ThemeConfig
|
|
|
import io.legado.app.ui.widget.components.importComponents.BaseImportUiState
|
|
import io.legado.app.ui.widget.components.importComponents.BaseImportUiState
|
|
|
import io.legado.app.ui.widget.components.importComponents.ImportItemWrapper
|
|
import io.legado.app.ui.widget.components.importComponents.ImportItemWrapper
|
|
|
import io.legado.app.ui.widget.components.importComponents.ImportStatus
|
|
import io.legado.app.ui.widget.components.importComponents.ImportStatus
|
|
|
-import io.legado.app.utils.ColorUtils
|
|
|
|
|
import io.legado.app.utils.GSON
|
|
import io.legado.app.utils.GSON
|
|
|
import io.legado.app.utils.ImageSaveUtils
|
|
import io.legado.app.utils.ImageSaveUtils
|
|
|
import io.legado.app.utils.NetworkUtils
|
|
import io.legado.app.utils.NetworkUtils
|
|
@@ -3479,6 +3478,10 @@ class ReadBookViewModel(
|
|
|
}
|
|
}
|
|
|
is ConfigUpdate.AutoSuggestDayNight -> {
|
|
is ConfigUpdate.AutoSuggestDayNight -> {
|
|
|
ReadConfig.autoSuggestDayNight = update.value
|
|
ReadConfig.autoSuggestDayNight = update.value
|
|
|
|
|
+ if (update.value) {
|
|
|
|
|
+ hasDismissedDarkReminder = false
|
|
|
|
|
+ hasDismissedLightReminder = false
|
|
|
|
|
+ }
|
|
|
viewModelScope.launch {
|
|
viewModelScope.launch {
|
|
|
readSettingsRepository.setAutoSuggestDayNight(update.value)
|
|
readSettingsRepository.setAutoSuggestDayNight(update.value)
|
|
|
}
|
|
}
|
|
@@ -3892,9 +3895,23 @@ class ReadBookViewModel(
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private fun toggleDayNight() {
|
|
private fun toggleDayNight() {
|
|
|
|
|
+ lastSwitchDayNightReminderTime = System.currentTimeMillis()
|
|
|
|
|
+ hasDismissedDarkReminder = false
|
|
|
|
|
+ hasDismissedLightReminder = false
|
|
|
val nextMode = if (ReadConfig.isNightTheme) "1" else "2"
|
|
val nextMode = if (ReadConfig.isNightTheme) "1" else "2"
|
|
|
ThemeConfig.themeMode = nextMode
|
|
ThemeConfig.themeMode = nextMode
|
|
|
- _uiState.update { it.copy(styleConfig = buildStyleConfig()) }
|
|
|
|
|
|
|
+ _uiState.update {
|
|
|
|
|
+ val newActiveReminder = if (it.activeReminder?.type is ReminderType.DayNightReminder) {
|
|
|
|
|
+ null
|
|
|
|
|
+ } else {
|
|
|
|
|
+ it.activeReminder
|
|
|
|
|
+ }
|
|
|
|
|
+ it.copy(
|
|
|
|
|
+ activeReminder = newActiveReminder,
|
|
|
|
|
+ styleConfig = buildStyleConfig()
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ reminderQueue.removeAll { it.type is ReminderType.DayNightReminder }
|
|
|
_effects.tryEmit(ReadBookEffect.UpdateReadViewConfig(
|
|
_effects.tryEmit(ReadBookEffect.UpdateReadViewConfig(
|
|
|
setOf(
|
|
setOf(
|
|
|
ConfigUpdateAction.UpdateBackground,
|
|
ConfigUpdateAction.UpdateBackground,
|
|
@@ -4295,6 +4312,8 @@ class ReadBookViewModel(
|
|
|
|
|
|
|
|
private var lastSwitchDayNightReminderTime: Long = 0L
|
|
private var lastSwitchDayNightReminderTime: Long = 0L
|
|
|
private val reminderQueue = ArrayDeque<ReminderUiState>()
|
|
private val reminderQueue = ArrayDeque<ReminderUiState>()
|
|
|
|
|
+ private var hasDismissedDarkReminder = false
|
|
|
|
|
+ private var hasDismissedLightReminder = false
|
|
|
|
|
|
|
|
fun isDayNightSwitchCoolingDown(): Boolean {
|
|
fun isDayNightSwitchCoolingDown(): Boolean {
|
|
|
return System.currentTimeMillis() - lastSwitchDayNightReminderTime < REMINDER_COOLDOWN_MS
|
|
return System.currentTimeMillis() - lastSwitchDayNightReminderTime < REMINDER_COOLDOWN_MS
|
|
@@ -4319,13 +4338,13 @@ class ReadBookViewModel(
|
|
|
val isNight = ReadConfig.isNightTheme
|
|
val isNight = ReadConfig.isNightTheme
|
|
|
val styleConfig = _uiState.value.styleConfig
|
|
val styleConfig = _uiState.value.styleConfig
|
|
|
if (!isNight && lux <= DARK_LUX_THRESHOLD) {
|
|
if (!isNight && lux <= DARK_LUX_THRESHOLD) {
|
|
|
|
|
+ if (hasDismissedDarkReminder) return
|
|
|
val bgType = styleConfig.bgType
|
|
val bgType = styleConfig.bgType
|
|
|
val isLightBg = if (bgType == 0) {
|
|
val isLightBg = if (bgType == 0) {
|
|
|
val colorInt = runCatching { styleConfig.bgStr.toColorInt() }.getOrDefault(0xFFEEEEEE.toInt())
|
|
val colorInt = runCatching { styleConfig.bgStr.toColorInt() }.getOrDefault(0xFFEEEEEE.toInt())
|
|
|
isReadBgLight(colorInt)
|
|
isReadBgLight(colorInt)
|
|
|
} else {
|
|
} else {
|
|
|
val meanColor = ReadBookConfig.bgMeanColor
|
|
val meanColor = ReadBookConfig.bgMeanColor
|
|
|
- //Log.d("fansangg","meanColor = ${ColorUtils.intToString(meanColor)},isLight = ${isReadBgLight(meanColor)}")
|
|
|
|
|
if (meanColor != 0) isReadBgLight(meanColor) else true
|
|
if (meanColor != 0) isReadBgLight(meanColor) else true
|
|
|
}
|
|
}
|
|
|
if (isLightBg) {
|
|
if (isLightBg) {
|
|
@@ -4335,17 +4354,18 @@ class ReadBookViewModel(
|
|
|
message = context.getString(R.string.switch_to_dark_mode_tip),
|
|
message = context.getString(R.string.switch_to_dark_mode_tip),
|
|
|
actionText = context.getString(R.string.switch_action),
|
|
actionText = context.getString(R.string.switch_action),
|
|
|
actionIntent = ReadBookIntent.ToggleDayNight,
|
|
actionIntent = ReadBookIntent.ToggleDayNight,
|
|
|
|
|
+ type = ReminderType.DayNightReminder(targetIsNight = true),
|
|
|
)
|
|
)
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
} else if (isNight && lux >= BRIGHT_LUX_THRESHOLD) {
|
|
} else if (isNight && lux >= BRIGHT_LUX_THRESHOLD) {
|
|
|
|
|
+ if (hasDismissedLightReminder) return
|
|
|
val bgTypeNight = styleConfig.bgTypeNight
|
|
val bgTypeNight = styleConfig.bgTypeNight
|
|
|
val isDarkBg = if (bgTypeNight == 0) {
|
|
val isDarkBg = if (bgTypeNight == 0) {
|
|
|
val colorInt = runCatching { styleConfig.bgStrNight.toColorInt() }.getOrDefault(0xFF000000.toInt())
|
|
val colorInt = runCatching { styleConfig.bgStrNight.toColorInt() }.getOrDefault(0xFF000000.toInt())
|
|
|
!isReadBgLight(colorInt)
|
|
!isReadBgLight(colorInt)
|
|
|
} else {
|
|
} else {
|
|
|
val meanColor = ReadBookConfig.bgMeanColor
|
|
val meanColor = ReadBookConfig.bgMeanColor
|
|
|
- //Log.d("fansangg","meanColor = ${ColorUtils.intToString(meanColor)},isLight = ${isReadBgLight(meanColor)}")
|
|
|
|
|
if (meanColor != 0) !isReadBgLight(meanColor) else true
|
|
if (meanColor != 0) !isReadBgLight(meanColor) else true
|
|
|
}
|
|
}
|
|
|
if (isDarkBg) {
|
|
if (isDarkBg) {
|
|
@@ -4355,6 +4375,7 @@ class ReadBookViewModel(
|
|
|
message = context.getString(R.string.switch_to_light_mode_tip),
|
|
message = context.getString(R.string.switch_to_light_mode_tip),
|
|
|
actionText = context.getString(R.string.switch_action),
|
|
actionText = context.getString(R.string.switch_action),
|
|
|
actionIntent = ReadBookIntent.ToggleDayNight,
|
|
actionIntent = ReadBookIntent.ToggleDayNight,
|
|
|
|
|
+ type = ReminderType.DayNightReminder(targetIsNight = false),
|
|
|
)
|
|
)
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
@@ -4362,6 +4383,19 @@ class ReadBookViewModel(
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private fun dismissReminder() {
|
|
private fun dismissReminder() {
|
|
|
|
|
+ val currentReminder = _uiState.value.activeReminder
|
|
|
|
|
+ if (currentReminder != null) {
|
|
|
|
|
+ when (val type = currentReminder.type) {
|
|
|
|
|
+ is ReminderType.DayNightReminder -> {
|
|
|
|
|
+ if (type.targetIsNight) {
|
|
|
|
|
+ hasDismissedDarkReminder = true
|
|
|
|
|
+ } else {
|
|
|
|
|
+ hasDismissedLightReminder = true
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else -> {}
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
_uiState.update { it.copy(activeReminder = null) }
|
|
_uiState.update { it.copy(activeReminder = null) }
|
|
|
if (reminderQueue.isNotEmpty()) {
|
|
if (reminderQueue.isNotEmpty()) {
|
|
|
viewModelScope.launch {
|
|
viewModelScope.launch {
|
|
@@ -4382,7 +4416,7 @@ private const val TOOL_BUTTON_PREFS = "tool_button_config"
|
|
|
private const val TOOL_BUTTON_KEY = "tool_buttons"
|
|
private const val TOOL_BUTTON_KEY = "tool_buttons"
|
|
|
private const val DEFAULT_ENABLED_BUTTON_COUNT = 5
|
|
private const val DEFAULT_ENABLED_BUTTON_COUNT = 5
|
|
|
|
|
|
|
|
-private const val DARK_LUX_THRESHOLD = 10f
|
|
|
|
|
|
|
+private const val DARK_LUX_THRESHOLD = 8f
|
|
|
private const val BRIGHT_LUX_THRESHOLD = 100f
|
|
private const val BRIGHT_LUX_THRESHOLD = 100f
|
|
|
private const val LIGHT_LUMINANCE_THRESHOLD = 0.35
|
|
private const val LIGHT_LUMINANCE_THRESHOLD = 0.35
|
|
|
private const val REMINDER_COOLDOWN_MS = 10 * 60 * 1000L
|
|
private const val REMINDER_COOLDOWN_MS = 10 * 60 * 1000L
|