Skip to content

Commit

Permalink
Move radio item list building for SleepTimer into a separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
esensar committed Oct 13, 2023
1 parent 4b7c435 commit f25601d
Showing 1 changed file with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,7 @@ class MainActivity : ComponentActivity() {
val lastSleepTimerSeconds by preferences.lastSleepTimerSecondsFlow.collectAsStateWithLifecycle(preferences.lastSleepTimerSeconds)
val items by remember {
derivedStateOf {
val finalItems = ArrayList(listOf(10, 30, 60, 5 * 60, 10 * 60, 30 * 60).map {
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()
buildSleepTimerRadioItemsList(lastSleepTimerSeconds)
}
}

Expand All @@ -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
private fun AppLaunched(
donateAlertDialogState: AlertDialogState = getDonateAlertDialogState(),
Expand Down

0 comments on commit f25601d

Please sign in to comment.