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