Move lockscreen tabs into the toolbar

This commit is contained in:
Jonas Lochmann 2024-10-28 01:00:00 +01:00
parent 11a47c5f30
commit 8e02eb3fb3
No known key found for this signature in database
GPG key ID: 8B8C9AEE10FA5B36
2 changed files with 104 additions and 100 deletions

View file

@ -51,6 +51,7 @@ fun ScreenScaffold(
backStack: List<BackStackItem>, backStack: List<BackStackItem>,
snackbarHostState: SnackbarHostState?, snackbarHostState: SnackbarHostState?,
content: @Composable (PaddingValues) -> Unit, content: @Composable (PaddingValues) -> Unit,
extraBars: (@Composable () -> Unit)? = null,
executeCommand: (UpdateStateCommand) -> Unit, executeCommand: (UpdateStateCommand) -> Unit,
showAuthenticationDialog: (() -> Unit)? showAuthenticationDialog: (() -> Unit)?
) { ) {
@ -58,69 +59,73 @@ fun ScreenScaffold(
Scaffold( Scaffold(
topBar = { topBar = {
TopAppBar( Column {
title = { TopAppBar(
Column { title = {
Text( Column {
title,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
if (subtitle != null) {
Text( Text(
subtitle, title,
style = MaterialTheme.typography.subtitle1,
maxLines = 1, maxLines = 1,
overflow = TextOverflow.Ellipsis overflow = TextOverflow.Ellipsis
) )
}
}
},
navigationIcon = if (screen?.state?.previous != null) ({
IconButton(onClick = { executeCommand(UpdateStateCommand.BackToPreviousScreen) }) {
Icon(Icons.Default.ArrowBack, stringResource(R.string.generic_back))
}
}) else null,
actions = {
for (icon in screen?.toolbarIcons ?: emptyList()) {
IconButton(
onClick = {
if (icon.action != null) executeCommand(icon.action)
icon.handler() if (subtitle != null) {
Text(
subtitle,
style = MaterialTheme.typography.subtitle1,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
} }
) {
Icon(icon.icon, stringResource(icon.labelResource))
} }
} },
navigationIcon = if (screen?.state?.previous != null) ({
IconButton(onClick = { executeCommand(UpdateStateCommand.BackToPreviousScreen) }) {
Icon(Icons.Default.ArrowBack, stringResource(R.string.generic_back))
}
}) else null,
actions = {
for (icon in screen?.toolbarIcons ?: emptyList()) {
IconButton(
onClick = {
if (icon.action != null) executeCommand(icon.action)
if (screen?.toolbarOptions?.isEmpty() == false) { icon.handler()
IconButton(onClick = { expandDropdown = true }) { }
Icon(Icons.Default.MoreVert, stringResource(R.string.generic_menu)) ) {
Icon(icon.icon, stringResource(icon.labelResource))
}
} }
DropdownMenu( if (screen?.toolbarOptions?.isEmpty() == false) {
expanded = expandDropdown, IconButton(onClick = { expandDropdown = true }) {
onDismissRequest = { expandDropdown = false } Icon(Icons.Default.MoreVert, stringResource(R.string.generic_menu))
) { }
for (option in screen.toolbarOptions) {
DropdownMenuItem(onClick = {
if (option.action != null) executeCommand(option.action)
option.handler() DropdownMenu(
expanded = expandDropdown,
onDismissRequest = { expandDropdown = false }
) {
for (option in screen.toolbarOptions) {
DropdownMenuItem(onClick = {
if (option.action != null) executeCommand(option.action)
expandDropdown = false option.handler()
}) {
Text(stringResource(option.labelResource)) expandDropdown = false
}) {
Text(stringResource(option.labelResource))
}
} }
} }
} }
} },
}, modifier = Modifier,
modifier = Modifier, windowInsets = WindowInsets.statusBarsIgnoringVisibility
windowInsets = WindowInsets.statusBarsIgnoringVisibility )
)
extraBars?.invoke()
}
}, },
bottomBar = { bottomBar = {
val backStackColors = ButtonDefaults.textButtonColors( val backStackColors = ButtonDefaults.textButtonColors(

View file

@ -147,63 +147,62 @@ class LockActivity : AppCompatActivity(), ActivityViewModelHolder, U2fManager.De
subtitle = subtitle, subtitle = subtitle,
backStack = emptyList(), backStack = emptyList(),
snackbarHostState = null, snackbarHostState = null,
content = { padding -> extraBars = {
Column (Modifier.fillMaxSize().padding(padding)) { TabRow(
TabRow( pager.currentPage,
pager.currentPage, indicator = { tabPositions ->
indicator = { tabPositions -> // workaround for bug
// workaround for bug TabRowDefaults.Indicator(
TabRowDefaults.Indicator( Modifier.tabIndicatorOffset(tabPositions[
Modifier.tabIndicatorOffset(tabPositions[ pager.currentPage.coerceAtMost(tabPositions.size - 1)
pager.currentPage.coerceAtMost(tabPositions.size - 1) ])
]) )
) }
} ) {
Tab(
selected = pager.currentPage == 0,
onClick = { pager.requestScrollToPage(0) }
) { ) {
Tab( Text(
selected = pager.currentPage == 0, stringResource(R.string.lock_tab_reason),
onClick = { pager.requestScrollToPage(0) } Modifier.padding(16.dp)
) { )
Text(
stringResource(R.string.lock_tab_reason),
Modifier.padding(16.dp)
)
}
Tab(
selected = pager.currentPage == 1,
onClick = { pager.requestScrollToPage(1) }
) {
Text(
stringResource(R.string.lock_tab_action),
Modifier.padding(16.dp)
)
}
if (showTasks) Tab(
selected = pager.currentPage == 2,
onClick = { pager.requestScrollToPage(2) }
) {
Text(
stringResource(R.string.lock_tab_task),
Modifier.padding(16.dp)
)
}
} }
HorizontalPager( Tab(
pager, selected = pager.currentPage == 1,
Modifier.weight(1.0F, fill = true), onClick = { pager.requestScrollToPage(1) }
pageContent = { index -> ) {
when (index) { Text(
0 -> AndroidFragment<LockReasonFragment>(Modifier.fillMaxSize()) stringResource(R.string.lock_tab_action),
1 -> AndroidFragment<LockActionFragment>(Modifier.fillMaxSize()) Modifier.padding(16.dp)
2 -> AndroidFragment<LockTaskFragment>(Modifier.fillMaxSize()) )
} }
}
) if (showTasks) Tab(
selected = pager.currentPage == 2,
onClick = { pager.requestScrollToPage(2) }
) {
Text(
stringResource(R.string.lock_tab_task),
Modifier.padding(16.dp)
)
}
} }
}, },
content = { padding ->
HorizontalPager(
pager,
Modifier.fillMaxSize().padding(padding),
pageContent = { index ->
when (index) {
0 -> AndroidFragment<LockReasonFragment>(Modifier.fillMaxSize())
1 -> AndroidFragment<LockActionFragment>(Modifier.fillMaxSize())
2 -> AndroidFragment<LockTaskFragment>(Modifier.fillMaxSize())
}
}
)
},
executeCommand = {}, executeCommand = {},
showAuthenticationDialog = showAuthenticationDialog =
if (pager.currentPage == 1 && !isAuthenticated) ({ showAuthenticationScreen() }) if (pager.currentPage == 1 && !isAuthenticated) ({ showAuthenticationScreen() })