mirror of
https://github.com/SimpleMobileTools/Simple-Flashlight.git
synced 2025-06-05 21:59:19 +02:00
Move radio item list building for SleepTimer into a separate function
This commit is contained in:
@ -172,17 +172,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
val lastSleepTimerSeconds by preferences.lastSleepTimerSecondsFlow.collectAsStateWithLifecycle(preferences.lastSleepTimerSeconds)
|
val lastSleepTimerSeconds by preferences.lastSleepTimerSecondsFlow.collectAsStateWithLifecycle(preferences.lastSleepTimerSeconds)
|
||||||
val items by remember {
|
val items by remember {
|
||||||
derivedStateOf {
|
derivedStateOf {
|
||||||
val finalItems = ArrayList(listOf(10, 30, 60, 5 * 60, 10 * 60, 30 * 60).map {
|
buildSleepTimerRadioItemsList(lastSleepTimerSeconds)
|
||||||
RadioItem(it, secondsToString(it))
|
|
||||||
})
|
|
||||||
|
|
||||||
if (finalItems.none { it.id == lastSleepTimerSeconds }) {
|
|
||||||
finalItems.add(RadioItem(lastSleepTimerSeconds, secondsToString(lastSleepTimerSeconds)))
|
|
||||||
}
|
|
||||||
|
|
||||||
finalItems.sortBy { it.id }
|
|
||||||
finalItems.add(RadioItem(-1, getString(com.simplemobiletools.commons.R.string.custom)))
|
|
||||||
finalItems.toImmutableList()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,6 +190,21 @@ class MainActivity : ComponentActivity() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun buildSleepTimerRadioItemsList(
|
||||||
|
lastSleepTimerSeconds: Int
|
||||||
|
) = buildList<RadioItem> {
|
||||||
|
addAll(listOf(10, 30, 60, 5 * 60, 10 * 60, 30 * 60).map {
|
||||||
|
RadioItem(it, secondsToString(it))
|
||||||
|
})
|
||||||
|
|
||||||
|
if (none { it.id == lastSleepTimerSeconds }) {
|
||||||
|
add(RadioItem(lastSleepTimerSeconds, secondsToString(lastSleepTimerSeconds)))
|
||||||
|
}
|
||||||
|
|
||||||
|
sortBy { it.id }
|
||||||
|
add(RadioItem(-1, getString(com.simplemobiletools.commons.R.string.custom)))
|
||||||
|
}.toImmutableList()
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun AppLaunched(
|
private fun AppLaunched(
|
||||||
donateAlertDialogState: AlertDialogState = getDonateAlertDialogState(),
|
donateAlertDialogState: AlertDialogState = getDonateAlertDialogState(),
|
||||||
|
Reference in New Issue
Block a user