mirror of
https://github.com/SimpleMobileTools/Simple-Flashlight.git
synced 2025-06-05 21:59:19 +02:00
Move action building to a separate function
This commit is contained in:
parent
ee9a539cf5
commit
c644def18e
@ -33,6 +33,7 @@ import com.simplemobiletools.commons.compose.settings.scaffold.topAppBarPaddings
|
|||||||
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
||||||
import com.simplemobiletools.flashlight.R
|
import com.simplemobiletools.flashlight.R
|
||||||
import com.simplemobiletools.flashlight.views.SleepTimer
|
import com.simplemobiletools.flashlight.views.SleepTimer
|
||||||
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ -68,17 +69,7 @@ internal fun MainScreen(
|
|||||||
TopAppBar(
|
TopAppBar(
|
||||||
title = {},
|
title = {},
|
||||||
actions = {
|
actions = {
|
||||||
val actionMenus = remember {
|
val actionMenus = remember { buildActionMenu(showMoreApps, openSettings, openAbout, openSleepTimer, moreAppsFromUs) }
|
||||||
val settings =
|
|
||||||
ActionItem(R.string.settings, icon = Icons.Filled.Settings, doAction = openSettings, overflowMode = OverflowMode.NEVER_OVERFLOW)
|
|
||||||
val about = ActionItem(R.string.about, icon = Icons.Outlined.Info, doAction = openAbout, overflowMode = OverflowMode.NEVER_OVERFLOW)
|
|
||||||
val sleepTimer = ActionItem(R.string.sleep_timer, doAction = openSleepTimer, overflowMode = OverflowMode.ALWAYS_OVERFLOW)
|
|
||||||
val list = mutableListOf(settings, about, sleepTimer)
|
|
||||||
if (showMoreApps) {
|
|
||||||
list += ActionItem(R.string.more_apps_from_us, doAction = moreAppsFromUs, overflowMode = OverflowMode.ALWAYS_OVERFLOW)
|
|
||||||
}
|
|
||||||
list.toImmutableList()
|
|
||||||
}
|
|
||||||
var isMenuVisible by remember { mutableStateOf(false) }
|
var isMenuVisible by remember { mutableStateOf(false) }
|
||||||
ActionMenu(
|
ActionMenu(
|
||||||
items = actionMenus,
|
items = actionMenus,
|
||||||
@ -204,6 +195,24 @@ internal fun MainScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun buildActionMenu(
|
||||||
|
showMoreApps: Boolean,
|
||||||
|
openSettings: () -> Unit,
|
||||||
|
openAbout: () -> Unit,
|
||||||
|
openSleepTimer: () -> Unit,
|
||||||
|
moreAppsFromUs: () -> Unit,
|
||||||
|
): ImmutableList<ActionItem> {
|
||||||
|
val settings =
|
||||||
|
ActionItem(R.string.settings, icon = Icons.Filled.Settings, doAction = openSettings, overflowMode = OverflowMode.NEVER_OVERFLOW)
|
||||||
|
val about = ActionItem(R.string.about, icon = Icons.Outlined.Info, doAction = openAbout, overflowMode = OverflowMode.NEVER_OVERFLOW)
|
||||||
|
val sleepTimer = ActionItem(R.string.sleep_timer, doAction = openSleepTimer, overflowMode = OverflowMode.ALWAYS_OVERFLOW)
|
||||||
|
val list = mutableListOf(settings, about, sleepTimer)
|
||||||
|
if (showMoreApps) {
|
||||||
|
list += ActionItem(R.string.more_apps_from_us, doAction = moreAppsFromUs, overflowMode = OverflowMode.ALWAYS_OVERFLOW)
|
||||||
|
}
|
||||||
|
return list.toImmutableList()
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@MyDevices
|
@MyDevices
|
||||||
internal fun MainScreenPreview() {
|
internal fun MainScreenPreview() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user