diff --git a/app/src/main/java/io/timelimit/android/ui/ScreenScaffold.kt b/app/src/main/java/io/timelimit/android/ui/ScreenScaffold.kt index 583136f..28139c0 100644 --- a/app/src/main/java/io/timelimit/android/ui/ScreenScaffold.kt +++ b/app/src/main/java/io/timelimit/android/ui/ScreenScaffold.kt @@ -51,6 +51,7 @@ fun ScreenScaffold( backStack: List, 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( diff --git a/app/src/main/java/io/timelimit/android/ui/lock/LockActivity.kt b/app/src/main/java/io/timelimit/android/ui/lock/LockActivity.kt index 634c77d..07861ff 100644 --- a/app/src/main/java/io/timelimit/android/ui/lock/LockActivity.kt +++ b/app/src/main/java/io/timelimit/android/ui/lock/LockActivity.kt @@ -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(Modifier.fillMaxSize()) - 1 -> AndroidFragment(Modifier.fillMaxSize()) - 2 -> AndroidFragment(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(Modifier.fillMaxSize()) + 1 -> AndroidFragment(Modifier.fillMaxSize()) + 2 -> AndroidFragment(Modifier.fillMaxSize()) + } + } + ) + }, executeCommand = {}, showAuthenticationDialog = if (pager.currentPage == 1 && !isAuthenticated) ({ showAuthenticationScreen() })