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

View file

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