perf: 冷却判断挪到onResume以减少传感器注册 (#1633)
This commit is contained in:
@@ -249,7 +249,7 @@ fun ReadBookRouteScreen(
|
||||
|
||||
val observer = LifecycleEventObserver { _, event ->
|
||||
if (event == Lifecycle.Event.ON_RESUME) {
|
||||
if (!ReadConfig.autoSuggestDayNight) return@LifecycleEventObserver
|
||||
if (!ReadConfig.autoSuggestDayNight || viewModel.isDayNightSwitchCoolingDown()) return@LifecycleEventObserver
|
||||
if (lightSensor != null) {
|
||||
listener = object : SensorEventListener {
|
||||
override fun onSensorChanged(sensorEvent: SensorEvent?) {
|
||||
|
||||
@@ -4023,6 +4023,10 @@ class ReadBookViewModel(
|
||||
private var lastSwitchDayNightReminderTime: Long = 0L
|
||||
private val reminderQueue = ArrayDeque<ReminderUiState>()
|
||||
|
||||
fun isDayNightSwitchCoolingDown(): Boolean {
|
||||
return System.currentTimeMillis() - lastSwitchDayNightReminderTime < REMINDER_COOLDOWN_MS
|
||||
}
|
||||
|
||||
private fun showReminder(reminder: ReminderUiState) {
|
||||
if (_uiState.value.activeReminder == null && reminderQueue.isEmpty()) {
|
||||
_uiState.update { it.copy(activeReminder = reminder) }
|
||||
@@ -4038,9 +4042,7 @@ class ReadBookViewModel(
|
||||
}
|
||||
|
||||
private fun checkSwitchDayNight(lux: Float) {
|
||||
if (!ReadConfig.autoSuggestDayNight) return
|
||||
if (System.currentTimeMillis() - lastSwitchDayNightReminderTime < REMINDER_COOLDOWN_MS) return
|
||||
|
||||
if (!ReadConfig.autoSuggestDayNight || isDayNightSwitchCoolingDown()) return
|
||||
val isNight = ReadConfig.isNightTheme
|
||||
val styleConfig = _uiState.value.styleConfig
|
||||
if (!isNight && lux <= DARK_LUX_THRESHOLD) {
|
||||
|
||||
Reference in New Issue
Block a user