feat(settings): implement secure lock screen settings behaviour
Closes: #166
This commit is contained in:
@@ -83,6 +83,7 @@ import kotlin.random.Random
|
||||
@Composable
|
||||
fun SharedTransitionScope.AlwaysOnDisplay(
|
||||
timerState: TimerState,
|
||||
secureAod: Boolean,
|
||||
progress: () -> Float,
|
||||
setTimerFrequency: (Float) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
@@ -100,8 +101,10 @@ fun SharedTransitionScope.AlwaysOnDisplay(
|
||||
DisposableEffect(Unit) {
|
||||
setTimerFrequency(1f)
|
||||
window.addFlags(
|
||||
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
|
||||
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
|
||||
if (secureAod) {
|
||||
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
|
||||
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
|
||||
} else WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
|
||||
)
|
||||
activity?.setShowWhenLocked(true)
|
||||
insetsController.apply {
|
||||
@@ -273,6 +276,7 @@ private fun AlwaysOnDisplayPreview() {
|
||||
SharedTransitionLayout {
|
||||
AlwaysOnDisplay(
|
||||
timerState = timerState,
|
||||
secureAod = true,
|
||||
progress = progress,
|
||||
setTimerFrequency = {}
|
||||
)
|
||||
|
||||
@@ -88,6 +88,7 @@ import androidx.window.core.layout.WindowSizeClass
|
||||
import org.nsh07.pomodoro.billing.TomatoPlusPaywallDialog
|
||||
import org.nsh07.pomodoro.service.TimerService
|
||||
import org.nsh07.pomodoro.ui.settingsScreen.SettingsScreenRoot
|
||||
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsViewModel
|
||||
import org.nsh07.pomodoro.ui.statsScreen.StatsScreenRoot
|
||||
import org.nsh07.pomodoro.ui.timerScreen.AlarmDialog
|
||||
import org.nsh07.pomodoro.ui.timerScreen.TimerScreen
|
||||
@@ -101,11 +102,13 @@ fun AppScreen(
|
||||
isPlus: Boolean,
|
||||
setTimerFrequency: (Float) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
timerViewModel: TimerViewModel = viewModel(factory = TimerViewModel.Factory)
|
||||
timerViewModel: TimerViewModel = viewModel(factory = TimerViewModel.Factory),
|
||||
settingsViewModel: SettingsViewModel = viewModel(factory = SettingsViewModel.Factory)
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
||||
val uiState by timerViewModel.timerState.collectAsStateWithLifecycle()
|
||||
val settingsState by settingsViewModel.settingsState.collectAsStateWithLifecycle()
|
||||
val progress by timerViewModel.progress.collectAsStateWithLifecycle()
|
||||
|
||||
val layoutDirection = LocalLayoutDirection.current
|
||||
@@ -278,6 +281,7 @@ fun AppScreen(
|
||||
entry<Screen.AOD> {
|
||||
AlwaysOnDisplay(
|
||||
timerState = uiState,
|
||||
secureAod = settingsState.secureAod,
|
||||
progress = { progress },
|
||||
setTimerFrequency = setTimerFrequency,
|
||||
modifier = if (isAODEnabled) Modifier.clickable {
|
||||
|
||||
@@ -131,7 +131,7 @@ fun TimerSettings(
|
||||
settingsState.dndEnabled,
|
||||
settingsState.aodEnabled,
|
||||
settingsState.autostartNextSession,
|
||||
settingsState.lockScreenInAod,
|
||||
settingsState.secureAod,
|
||||
isPlus,
|
||||
serviceRunning
|
||||
) {
|
||||
@@ -177,12 +177,12 @@ fun TimerSettings(
|
||||
onClick = { onAction(SettingsAction.SaveAodEnabled(it)) }
|
||||
),
|
||||
SettingsSwitchItem(
|
||||
checked = settingsState.lockScreenInAod && isPlus,
|
||||
checked = settingsState.secureAod && isPlus,
|
||||
enabled = isPlus,
|
||||
icon = R.drawable.mobile_lock_portrait,
|
||||
label = R.string.secure_aod,
|
||||
description = R.string.secure_aod_desc,
|
||||
onClick = { onAction(SettingsAction.SaveLockScreenInAod(it)) }
|
||||
onClick = { onAction(SettingsAction.SaveSecureAod(it)) }
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -29,7 +29,7 @@ sealed interface SettingsAction {
|
||||
data class SaveMediaVolumeForAlarm(val enabled: Boolean) : SettingsAction
|
||||
data class SaveSingleProgressBar(val enabled: Boolean) : SettingsAction
|
||||
data class SaveAutostartNextSession(val enabled: Boolean) : SettingsAction
|
||||
data class SaveLockScreenInAod(val enabled: Boolean) : SettingsAction
|
||||
data class SaveSecureAod(val enabled: Boolean) : SettingsAction
|
||||
data class SaveAlarmSound(val uri: Uri?) : SettingsAction
|
||||
data class SaveTheme(val theme: String) : SettingsAction
|
||||
data class SaveColorScheme(val color: Color) : SettingsAction
|
||||
|
||||
@@ -34,7 +34,7 @@ data class SettingsState(
|
||||
val mediaVolumeForAlarm: Boolean = false,
|
||||
val singleProgressBar: Boolean = false,
|
||||
val autostartNextSession: Boolean = false,
|
||||
val lockScreenInAod: Boolean = true,
|
||||
val secureAod: Boolean = true,
|
||||
|
||||
val focusTime: Long = 25 * 60 * 1000L,
|
||||
val shortBreakTime: Long = 5 * 60 * 1000L,
|
||||
|
||||
@@ -115,7 +115,7 @@ class SettingsViewModel(
|
||||
is SettingsAction.SaveMediaVolumeForAlarm -> saveMediaVolumeForAlarm(action.enabled)
|
||||
is SettingsAction.SaveSingleProgressBar -> saveSingleProgressBar(action.enabled)
|
||||
is SettingsAction.SaveAutostartNextSession -> saveAutostartNextSession(action.enabled)
|
||||
is SettingsAction.SaveLockScreenInAod -> saveLockScreenInAod(action.enabled)
|
||||
is SettingsAction.SaveSecureAod -> saveSecureAod(action.enabled)
|
||||
is SettingsAction.SaveColorScheme -> saveColorScheme(action.color)
|
||||
is SettingsAction.SaveTheme -> saveTheme(action.theme)
|
||||
is SettingsAction.SaveBlackTheme -> saveBlackTheme(action.enabled)
|
||||
@@ -303,14 +303,14 @@ class SettingsViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveLockScreenInAod(lockScreenInAod: Boolean) {
|
||||
private fun saveSecureAod(secureAod: Boolean) {
|
||||
viewModelScope.launch {
|
||||
_settingsState.update { currentState ->
|
||||
currentState.copy(lockScreenInAod = lockScreenInAod)
|
||||
currentState.copy(secureAod = secureAod)
|
||||
}
|
||||
preferenceRepository.saveBooleanPreference(
|
||||
"lock_screen_in_aod",
|
||||
lockScreenInAod
|
||||
"secure_aod",
|
||||
secureAod
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -388,8 +388,8 @@ class SettingsViewModel(
|
||||
"autostart_next_session",
|
||||
settingsState.autostartNextSession
|
||||
)
|
||||
val lockScreenInAod = preferenceRepository.getBooleanPreference("lock_screen_in_aod")
|
||||
?: preferenceRepository.saveBooleanPreference("lock_screen_in_aod", true)
|
||||
val secureAod = preferenceRepository.getBooleanPreference("secure_aod")
|
||||
?: preferenceRepository.saveBooleanPreference("secure_aod", true)
|
||||
|
||||
_settingsState.update { currentState ->
|
||||
currentState.copy(
|
||||
@@ -408,7 +408,7 @@ class SettingsViewModel(
|
||||
mediaVolumeForAlarm = mediaVolumeForAlarm,
|
||||
singleProgressBar = singleProgressBar,
|
||||
autostartNextSession = autostartNextSession,
|
||||
lockScreenInAod = lockScreenInAod
|
||||
secureAod = secureAod
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user