From 7b3a82cc30798ea87d518157b2493bddb08b1430 Mon Sep 17 00:00:00 2001 From: tdpeuter Date: Tue, 25 Apr 2023 09:43:10 +0200 Subject: [PATCH 01/10] New DrawerScreen for TimerOverView --- .../java/be/ugent/sel/studeez/StudeezApp.kt | 3 +- .../composable/DrawerScreenComposable.kt | 51 +++++++++++++++++++ .../timer_overview/TimerOverviewScreen.kt | 23 +++------ 3 files changed, 59 insertions(+), 18 deletions(-) create mode 100644 app/src/main/java/be/ugent/sel/studeez/common/composable/DrawerScreenComposable.kt diff --git a/app/src/main/java/be/ugent/sel/studeez/StudeezApp.kt b/app/src/main/java/be/ugent/sel/studeez/StudeezApp.kt index a6830a5..c9b0963 100644 --- a/app/src/main/java/be/ugent/sel/studeez/StudeezApp.kt +++ b/app/src/main/java/be/ugent/sel/studeez/StudeezApp.kt @@ -141,8 +141,7 @@ fun StudeezNavGraph( open, openAndPopUp, viewModel = hiltViewModel(), - drawerViewModel = drawerViewModel, - navBarViewModel = navBarViewModel, + drawerViewModel = drawerViewModel ) } diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/DrawerScreenComposable.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/DrawerScreenComposable.kt new file mode 100644 index 0000000..e6f55f7 --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/DrawerScreenComposable.kt @@ -0,0 +1,51 @@ +package be.ugent.sel.studeez.common.composable + +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.RowScope +import androidx.compose.material.* +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Menu +import androidx.compose.runtime.Composable +import androidx.compose.runtime.rememberCoroutineScope +import be.ugent.sel.studeez.common.composable.drawer.Drawer +import be.ugent.sel.studeez.common.composable.drawer.DrawerActions +import be.ugent.sel.studeez.resources +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.launch +import be.ugent.sel.studeez.R.string as AppText + +@Composable +fun DrawerScreenTemplate( + title: String, + drawerActions: DrawerActions, + action: @Composable RowScope.() -> Unit = {}, + content: @Composable (PaddingValues) -> Unit +) { + val scaffoldState: ScaffoldState = rememberScaffoldState() + val coroutineScope: CoroutineScope = rememberCoroutineScope() + + Scaffold( + scaffoldState = scaffoldState, + + topBar = { TopAppBar( + title = { Text(text = title) }, + navigationIcon = { + IconButton(onClick = { + coroutineScope.launch { scaffoldState.drawerState.open() } + }) { + Icon( + imageVector = Icons.Default.Menu, + contentDescription = resources().getString(AppText.menu) + ) + } + }, + actions = action + )}, + + drawerContent = { + Drawer(drawerActions) + } + ) { + content(it) + } +} \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt index fafdf02..9537965 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt @@ -10,10 +10,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import be.ugent.sel.studeez.R -import be.ugent.sel.studeez.common.composable.BasicButton -import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate -import be.ugent.sel.studeez.common.composable.StealthButton -import be.ugent.sel.studeez.common.composable.TimerEntry +import be.ugent.sel.studeez.common.composable.* import be.ugent.sel.studeez.common.composable.drawer.DrawerActions import be.ugent.sel.studeez.common.composable.drawer.DrawerViewModel import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions @@ -48,30 +45,25 @@ fun TimerOverviewRoute( open: (String) -> Unit, openAndPopUp: (String, String) -> Unit, viewModel: TimerOverviewViewModel, - drawerViewModel: DrawerViewModel, - navBarViewModel: NavigationBarViewModel, + drawerViewModel: DrawerViewModel ) { TimerOverviewScreen( timerOverviewActions = getTimerOverviewActions(viewModel), - drawerActions = getDrawerActions(drawerViewModel, open, openAndPopUp), - navigationBarActions = getNavigationBarActions(navBarViewModel, open), + drawerActions = getDrawerActions(drawerViewModel, open, openAndPopUp) ) } @Composable fun TimerOverviewScreen( timerOverviewActions: TimerOverviewActions, - drawerActions: DrawerActions, - navigationBarActions: NavigationBarActions, + drawerActions: DrawerActions ) { val timers = timerOverviewActions.getUserTimers().collectAsState(initial = emptyList()) - // TODO moet geen primary screen zijn: geen navbar nodig - PrimaryScreenTemplate( + DrawerScreenTemplate( title = resources().getString(R.string.timers), - drawerActions = drawerActions, - navigationBarActions = navigationBarActions, + drawerActions = drawerActions ) { Column { LazyColumn( @@ -112,7 +104,6 @@ fun TimerOverviewPreview() { { flowOf() }, { listOf(customTimer, customTimer) }, {}), - drawerActions = DrawerActions({}, {}, {}, {}, {}), - navigationBarActions = NavigationBarActions({}, {}, {}, {}) + drawerActions = DrawerActions({}, {}, {}, {}, {}) ) } From e73cc798f0764802a4cd30265deab2387634033d Mon Sep 17 00:00:00 2001 From: tdpeuter Date: Tue, 25 Apr 2023 19:27:14 +0200 Subject: [PATCH 02/10] #42 highlight selected screen --- .../composable/PrimaryScreenComposable.kt | 2 +- .../navbar/NavigationBarComposable.kt | 32 ++++++++++++------- .../navbar/NavigationBarViewModel.kt | 15 +++++++++ .../sel/studeez/screens/home/HomeScreen.kt | 2 +- .../studeez/screens/profile/ProfileScreen.kt | 2 +- .../timer_selection/TimerSelectionScreen.kt | 2 +- 6 files changed, 39 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/PrimaryScreenComposable.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/PrimaryScreenComposable.kt index 5af2788..773c546 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/PrimaryScreenComposable.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/PrimaryScreenComposable.kt @@ -77,7 +77,7 @@ fun PrimaryScreenPreview() { PrimaryScreenTemplate( "Preview screen", DrawerActions({}, {}, {}, {}, {}), - NavigationBarActions({}, {}, {}, {}), + NavigationBarActions({ false }, {}, {}, {}, {}), { IconButton(onClick = { /*TODO*/ }) { Icon( diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarComposable.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarComposable.kt index 21311ef..27fb605 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarComposable.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarComposable.kt @@ -17,6 +17,7 @@ import be.ugent.sel.studeez.ui.theme.StudeezTheme import be.ugent.sel.studeez.R.string as AppText data class NavigationBarActions( + val selectedTab: (Int) -> Boolean, val onHomeClick: () -> Unit, val onTasksClick: () -> Unit, val onSessionsClick: () -> Unit, @@ -28,10 +29,19 @@ fun getNavigationBarActions( open: (String) -> Unit, ): NavigationBarActions { return NavigationBarActions( - onHomeClick = { navigationBarViewModel.onHomeClick(open) }, - onTasksClick = { navigationBarViewModel.onTasksClick(open) }, - onSessionsClick = { navigationBarViewModel.onSessionsClick(open) }, - onProfileClick = { navigationBarViewModel.onProfileClick(open) }, + selectedTab = { navigationBarViewModel.isSelected(it) }, + onHomeClick = { + navigationBarViewModel.onHomeClick(open) + }, + onTasksClick = { + navigationBarViewModel.onTasksClick(open) + }, + onSessionsClick = { + navigationBarViewModel.onSessionsClick(open) + }, + onProfileClick = { + navigationBarViewModel.onProfileClick(open) + }, ) } @@ -39,16 +49,14 @@ fun getNavigationBarActions( fun NavigationBar( navigationBarActions: NavigationBarActions, ) { - // TODO Pass functions and new screens. - // TODO Pass which screen is selected. - // TODO Disabled -> HIGH/MEDIUM_EMPHASIS if the page is implemented BottomNavigation( elevation = 10.dp ) { + BottomNavigationItem( icon = { Icon(imageVector = Icons.Default.List, resources().getString(AppText.home)) }, label = { Text(text = resources().getString(AppText.home)) }, - selected = false, // TODO + selected = navigationBarActions.selectedTab(0), onClick = navigationBarActions.onHomeClick ) @@ -59,7 +67,7 @@ fun NavigationBar( ) }, label = { Text(text = resources().getString(AppText.tasks)) }, - selected = false, // TODO + selected = navigationBarActions.selectedTab(1), onClick = navigationBarActions.onTasksClick ) @@ -73,7 +81,7 @@ fun NavigationBar( ) }, label = { Text(text = resources().getString(AppText.sessions)) }, - selected = false, // TODO + selected = navigationBarActions.selectedTab(2), onClick = navigationBarActions.onSessionsClick ) @@ -84,7 +92,7 @@ fun NavigationBar( ) }, label = { Text(text = resources().getString(AppText.profile)) }, - selected = false, // TODO + selected = navigationBarActions.selectedTab(3), onClick = navigationBarActions.onProfileClick ) @@ -95,6 +103,6 @@ fun NavigationBar( @Composable fun NavigationBarPreview() { StudeezTheme { - NavigationBar(NavigationBarActions({}, {}, {}, {})) + NavigationBar(NavigationBarActions({ false }, {}, {}, {}, {})) } } \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarViewModel.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarViewModel.kt index 1e4bd0d..58a75ef 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarViewModel.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarViewModel.kt @@ -7,26 +7,41 @@ import be.ugent.sel.studeez.navigation.StudeezDestinations.PROFILE_SCREEN import be.ugent.sel.studeez.screens.StudeezViewModel import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject +import javax.inject.Singleton @HiltViewModel class NavigationBarViewModel @Inject constructor( private val accountDAO: AccountDAO, + var selectedTab: SelectedTabState, logService: LogService ) : StudeezViewModel(logService) { + fun isSelected(index: Int): Boolean { + return index == selectedTab.selectedTab + } + fun onHomeClick(open: (String) -> Unit) { + selectedTab.selectedTab = 0 open(HOME_SCREEN) } fun onTasksClick(open: (String) -> Unit) { // TODO + selectedTab.selectedTab = 1 } fun onSessionsClick(open: (String) -> Unit) { // TODO + selectedTab.selectedTab = 2 } fun onProfileClick(open: (String) -> Unit) { + selectedTab.selectedTab = 3 open(PROFILE_SCREEN) } +} + +@Singleton +class SelectedTabState @Inject constructor() { + var selectedTab: Int = 0 } \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/home/HomeScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/home/HomeScreen.kt index e318655..ba322d9 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/home/HomeScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/home/HomeScreen.kt @@ -69,6 +69,6 @@ fun HomeScreenPreview() { HomeScreen( onStartSessionClick = {}, drawerActions = DrawerActions({}, {}, {}, {}, {}), - navigationBarActions = NavigationBarActions({}, {}, {}, {}) + navigationBarActions = NavigationBarActions({ false }, {}, {}, {}, {}) ) } diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileScreen.kt index a12dd08..af72010 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileScreen.kt @@ -90,6 +90,6 @@ fun ProfileScreenPreview() { ProfileScreen( profileActions = ProfileActions({ null }, {}), drawerActions = DrawerActions({}, {}, {}, {}, {}), - navigationBarActions = NavigationBarActions({}, {}, {}, {}) + navigationBarActions = NavigationBarActions({ false }, {}, {}, {}, {}) ) } \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt index 47e7f91..007a656 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt @@ -86,6 +86,6 @@ fun TimerSelectionPreview() { TimerSelectionScreen( timerSelectionActions = TimerSelectionActions({ flowOf() }, {}), drawerActions = DrawerActions({}, {}, {}, {}, {}), - navigationBarActions = NavigationBarActions({}, {}, {}, {}), + navigationBarActions = NavigationBarActions({ false }, {}, {}, {}, {}), ) } \ No newline at end of file From 05860345b6393ee7baf66167088898029dac80d0 Mon Sep 17 00:00:00 2001 From: tdpeuter Date: Tue, 25 Apr 2023 21:17:57 +0200 Subject: [PATCH 03/10] less hardcoding --- .../composable/navbar/NavigationBarComposable.kt | 14 +++++++++----- .../composable/navbar/NavigationBarViewModel.kt | 14 +++++++------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarComposable.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarComposable.kt index 27fb605..e9b2b0e 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarComposable.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarComposable.kt @@ -12,12 +12,14 @@ import androidx.compose.material.icons.outlined.DateRange import androidx.compose.runtime.Composable import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import be.ugent.sel.studeez.navigation.StudeezDestinations.HOME_SCREEN +import be.ugent.sel.studeez.navigation.StudeezDestinations.PROFILE_SCREEN import be.ugent.sel.studeez.resources import be.ugent.sel.studeez.ui.theme.StudeezTheme import be.ugent.sel.studeez.R.string as AppText data class NavigationBarActions( - val selectedTab: (Int) -> Boolean, + val selectedTab: (String) -> Boolean, val onHomeClick: () -> Unit, val onTasksClick: () -> Unit, val onSessionsClick: () -> Unit, @@ -56,7 +58,7 @@ fun NavigationBar( BottomNavigationItem( icon = { Icon(imageVector = Icons.Default.List, resources().getString(AppText.home)) }, label = { Text(text = resources().getString(AppText.home)) }, - selected = navigationBarActions.selectedTab(0), + selected = navigationBarActions.selectedTab(HOME_SCREEN), onClick = navigationBarActions.onHomeClick ) @@ -67,7 +69,8 @@ fun NavigationBar( ) }, label = { Text(text = resources().getString(AppText.tasks)) }, - selected = navigationBarActions.selectedTab(1), + // TODO selected = navigationBarActions.selectedTab(TASKS_SCREEN), + selected = false, onClick = navigationBarActions.onTasksClick ) @@ -81,7 +84,8 @@ fun NavigationBar( ) }, label = { Text(text = resources().getString(AppText.sessions)) }, - selected = navigationBarActions.selectedTab(2), + // TODO selected = navigationBarActions.selectedTab(SESSIONS_SCREEN), + selected = false, onClick = navigationBarActions.onSessionsClick ) @@ -92,7 +96,7 @@ fun NavigationBar( ) }, label = { Text(text = resources().getString(AppText.profile)) }, - selected = navigationBarActions.selectedTab(3), + selected = navigationBarActions.selectedTab(PROFILE_SCREEN), onClick = navigationBarActions.onProfileClick ) diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarViewModel.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarViewModel.kt index 58a75ef..cadec72 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarViewModel.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarViewModel.kt @@ -16,32 +16,32 @@ class NavigationBarViewModel @Inject constructor( logService: LogService ) : StudeezViewModel(logService) { - fun isSelected(index: Int): Boolean { - return index == selectedTab.selectedTab + fun isSelected(screen: String): Boolean { + return screen == selectedTab.selectedTab } fun onHomeClick(open: (String) -> Unit) { - selectedTab.selectedTab = 0 + selectedTab.selectedTab = HOME_SCREEN open(HOME_SCREEN) } fun onTasksClick(open: (String) -> Unit) { // TODO - selectedTab.selectedTab = 1 + // selectedTab.selectedTab = TASKS_SCREEN } fun onSessionsClick(open: (String) -> Unit) { // TODO - selectedTab.selectedTab = 2 + // selectedTab.selectedTab = SESSIONS_SCREEN } fun onProfileClick(open: (String) -> Unit) { - selectedTab.selectedTab = 3 + selectedTab.selectedTab = PROFILE_SCREEN open(PROFILE_SCREEN) } } @Singleton class SelectedTabState @Inject constructor() { - var selectedTab: Int = 0 + var selectedTab: String = HOME_SCREEN } \ No newline at end of file From ce3261df076a065dad7999a21cb8c6c49020a11c Mon Sep 17 00:00:00 2001 From: tdpeuter Date: Wed, 26 Apr 2023 10:29:14 +0200 Subject: [PATCH 04/10] Add DrawerScreen preview --- .../common/composable/DrawerScreenComposable.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/DrawerScreenComposable.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/DrawerScreenComposable.kt index e6f55f7..3f43f3e 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/DrawerScreenComposable.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/DrawerScreenComposable.kt @@ -7,9 +7,11 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Menu import androidx.compose.runtime.Composable import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.tooling.preview.Preview import be.ugent.sel.studeez.common.composable.drawer.Drawer import be.ugent.sel.studeez.common.composable.drawer.DrawerActions import be.ugent.sel.studeez.resources +import be.ugent.sel.studeez.ui.theme.StudeezTheme import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import be.ugent.sel.studeez.R.string as AppText @@ -48,4 +50,15 @@ fun DrawerScreenTemplate( ) { content(it) } +} + +@Preview +@Composable +fun DrawerScreenPreview() { + StudeezTheme { DrawerScreenTemplate( + title = "Drawer screen preview", + drawerActions =DrawerActions({}, {}, {}, {}, {}) + ) { + Text(text = "Preview content") + } } } \ No newline at end of file From d268fcd389ae90738087bbc83e5a6540884f3202 Mon Sep 17 00:00:00 2001 From: tdpeuter Date: Wed, 26 Apr 2023 10:33:35 +0200 Subject: [PATCH 05/10] Rename action to barAction --- .../studeez/common/composable/DrawerScreenComposable.kt | 4 ++-- .../studeez/common/composable/PrimaryScreenComposable.kt | 4 ++-- .../studeez/common/composable/SecondaryScreenComposable.kt | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/DrawerScreenComposable.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/DrawerScreenComposable.kt index 3f43f3e..b0b1829 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/DrawerScreenComposable.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/DrawerScreenComposable.kt @@ -20,7 +20,7 @@ import be.ugent.sel.studeez.R.string as AppText fun DrawerScreenTemplate( title: String, drawerActions: DrawerActions, - action: @Composable RowScope.() -> Unit = {}, + barAction: @Composable RowScope.() -> Unit = {}, content: @Composable (PaddingValues) -> Unit ) { val scaffoldState: ScaffoldState = rememberScaffoldState() @@ -41,7 +41,7 @@ fun DrawerScreenTemplate( ) } }, - actions = action + actions = barAction )}, drawerContent = { diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/PrimaryScreenComposable.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/PrimaryScreenComposable.kt index 773c546..f83e8d7 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/PrimaryScreenComposable.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/PrimaryScreenComposable.kt @@ -31,7 +31,7 @@ fun PrimaryScreenTemplate( title: String, drawerActions: DrawerActions, navigationBarActions: NavigationBarActions, - action: @Composable RowScope.() -> Unit = {}, + barAction: @Composable RowScope.() -> Unit = {}, content: @Composable (PaddingValues) -> Unit ) { val scaffoldState: ScaffoldState = rememberScaffoldState() @@ -53,7 +53,7 @@ fun PrimaryScreenTemplate( ) } }, - actions = action + actions = barAction ) }, diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/SecondaryScreenComposable.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/SecondaryScreenComposable.kt index 5470566..5999072 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/SecondaryScreenComposable.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/SecondaryScreenComposable.kt @@ -1,6 +1,7 @@ package be.ugent.sel.studeez.common.composable import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.RowScope import androidx.compose.material.* import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowBack @@ -10,13 +11,12 @@ import be.ugent.sel.studeez.R import be.ugent.sel.studeez.resources import be.ugent.sel.studeez.ui.theme.StudeezTheme -// TODO Add option for button in top right corner as extra button - @Composable // Does not contain floatingActionButton and bottom bar, used in all the other screens fun SecondaryScreenTemplate( title: String, popUp: () -> Unit, + barAction: @Composable RowScope.() -> Unit = {}, content: @Composable (PaddingValues) -> Unit ) { Scaffold( @@ -30,7 +30,8 @@ fun SecondaryScreenTemplate( contentDescription = resources().getString(R.string.go_back) ) } - } + }, + actions = barAction ) }, ) { paddingValues -> content(paddingValues) From 27526151b0cb0fc6cfbdc43bde6f88bad7571623 Mon Sep 17 00:00:00 2001 From: tdpeuter Date: Wed, 26 Apr 2023 11:20:57 +0200 Subject: [PATCH 06/10] Cleanup show current tab --- .../java/be/ugent/sel/studeez/StudeezApp.kt | 23 +++++++++--------- .../composable/PrimaryScreenComposable.kt | 11 ++------- .../navbar/NavigationBarComposable.kt | 24 ++++++++++++------- .../navbar/NavigationBarViewModel.kt | 15 ------------ .../sel/studeez/screens/home/HomeScreen.kt | 5 ++-- .../studeez/screens/profile/ProfileScreen.kt | 14 ++++------- .../timer_selection/TimerSelectionScreen.kt | 3 ++- 7 files changed, 38 insertions(+), 57 deletions(-) diff --git a/app/src/main/java/be/ugent/sel/studeez/StudeezApp.kt b/app/src/main/java/be/ugent/sel/studeez/StudeezApp.kt index c9b0963..0744b42 100644 --- a/app/src/main/java/be/ugent/sel/studeez/StudeezApp.kt +++ b/app/src/main/java/be/ugent/sel/studeez/StudeezApp.kt @@ -2,17 +2,8 @@ package be.ugent.sel.studeez import android.content.res.Resources import androidx.compose.foundation.layout.padding -import androidx.compose.material.MaterialTheme -import androidx.compose.material.Scaffold -import androidx.compose.material.ScaffoldState -import androidx.compose.material.Snackbar -import androidx.compose.material.SnackbarHost -import androidx.compose.material.Surface -import androidx.compose.material.rememberScaffoldState -import androidx.compose.runtime.Composable -import androidx.compose.runtime.ReadOnlyComposable -import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.material.* +import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalContext @@ -21,6 +12,7 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavHostController import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable +import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController import be.ugent.sel.studeez.common.composable.drawer.DrawerViewModel import be.ugent.sel.studeez.common.composable.navbar.NavigationBarViewModel @@ -89,6 +81,8 @@ fun StudeezNavGraph( val drawerViewModel: DrawerViewModel = hiltViewModel() val navBarViewModel: NavigationBarViewModel = hiltViewModel() + val backStackEntry by appState.navController.currentBackStackEntryAsState() + NavHost( navController = appState.navController, startDestination = StudeezDestinations.SPLASH_SCREEN, @@ -106,6 +100,9 @@ fun StudeezNavGraph( appState.navigateAndPopUp(route, popUp) } + val getCurrentScreen: () -> String? = { + backStackEntry?.destination?.route + } composable(StudeezDestinations.SPLASH_SCREEN) { SplashRoute(openAndPopUp, viewModel = hiltViewModel()) @@ -123,6 +120,7 @@ fun StudeezNavGraph( HomeRoute( open, openAndPopUp, + getCurrentScreen, viewModel = hiltViewModel(), drawerViewModel = drawerViewModel, navBarViewModel = navBarViewModel, @@ -133,7 +131,7 @@ fun StudeezNavGraph( // TODO Sessions screen composable(StudeezDestinations.PROFILE_SCREEN) { - ProfileRoute(open, openAndPopUp, viewModel = hiltViewModel()) + ProfileRoute(open, openAndPopUp, getCurrentScreen, viewModel = hiltViewModel()) } composable(StudeezDestinations.TIMER_OVERVIEW_SCREEN) { @@ -161,6 +159,7 @@ fun StudeezNavGraph( TimerSelectionRoute( open, openAndPopUp, + getCurrentScreen, viewModel = hiltViewModel(), drawerViewModel = drawerViewModel, navBarViewModel = navBarViewModel, diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/PrimaryScreenComposable.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/PrimaryScreenComposable.kt index f83e8d7..79dec41 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/PrimaryScreenComposable.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/PrimaryScreenComposable.kt @@ -2,26 +2,19 @@ package be.ugent.sel.studeez.common.composable import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.RowScope -import androidx.compose.material.FabPosition -import androidx.compose.material.Icon -import androidx.compose.material.IconButton -import androidx.compose.material.Scaffold -import androidx.compose.material.ScaffoldState -import androidx.compose.material.Text -import androidx.compose.material.TopAppBar +import androidx.compose.material.* import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Edit import androidx.compose.material.icons.filled.Menu -import androidx.compose.material.rememberScaffoldState import androidx.compose.runtime.Composable import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.tooling.preview.Preview import be.ugent.sel.studeez.R -import be.ugent.sel.studeez.resources import be.ugent.sel.studeez.common.composable.drawer.Drawer import be.ugent.sel.studeez.common.composable.drawer.DrawerActions import be.ugent.sel.studeez.common.composable.navbar.NavigationBar import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions +import be.ugent.sel.studeez.resources import be.ugent.sel.studeez.ui.theme.StudeezTheme import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarComposable.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarComposable.kt index e9b2b0e..cdfd2d1 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarComposable.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarComposable.kt @@ -1,5 +1,6 @@ package be.ugent.sel.studeez.common.composable.navbar +import android.util.Log import androidx.compose.material.BottomNavigation import androidx.compose.material.BottomNavigationItem import androidx.compose.material.Icon @@ -19,7 +20,7 @@ import be.ugent.sel.studeez.ui.theme.StudeezTheme import be.ugent.sel.studeez.R.string as AppText data class NavigationBarActions( - val selectedTab: (String) -> Boolean, + val isSelectedTab: (String) -> Boolean, val onHomeClick: () -> Unit, val onTasksClick: () -> Unit, val onSessionsClick: () -> Unit, @@ -29,9 +30,13 @@ data class NavigationBarActions( fun getNavigationBarActions( navigationBarViewModel: NavigationBarViewModel, open: (String) -> Unit, + getCurrentScreen: () -> String? ): NavigationBarActions { return NavigationBarActions( - selectedTab = { navigationBarViewModel.isSelected(it) }, + isSelectedTab = { screen -> + Log.v("TEMP", getCurrentScreen().toString()) // TODO Remove + screen == getCurrentScreen() + }, onHomeClick = { navigationBarViewModel.onHomeClick(open) }, @@ -49,16 +54,15 @@ fun getNavigationBarActions( @Composable fun NavigationBar( - navigationBarActions: NavigationBarActions, + navigationBarActions: NavigationBarActions ) { BottomNavigation( elevation = 10.dp ) { - BottomNavigationItem( icon = { Icon(imageVector = Icons.Default.List, resources().getString(AppText.home)) }, label = { Text(text = resources().getString(AppText.home)) }, - selected = navigationBarActions.selectedTab(HOME_SCREEN), + selected = navigationBarActions.isSelectedTab(HOME_SCREEN), onClick = navigationBarActions.onHomeClick ) @@ -69,7 +73,7 @@ fun NavigationBar( ) }, label = { Text(text = resources().getString(AppText.tasks)) }, - // TODO selected = navigationBarActions.selectedTab(TASKS_SCREEN), + // TODO selected = navigationBarActions.isSelectedTab(TASKS_SCREEN), selected = false, onClick = navigationBarActions.onTasksClick ) @@ -84,7 +88,7 @@ fun NavigationBar( ) }, label = { Text(text = resources().getString(AppText.sessions)) }, - // TODO selected = navigationBarActions.selectedTab(SESSIONS_SCREEN), + // TODO selected = navigationBarActions.isSelectedTab(SESSIONS_SCREEN), selected = false, onClick = navigationBarActions.onSessionsClick ) @@ -96,7 +100,7 @@ fun NavigationBar( ) }, label = { Text(text = resources().getString(AppText.profile)) }, - selected = navigationBarActions.selectedTab(PROFILE_SCREEN), + selected = navigationBarActions.isSelectedTab(PROFILE_SCREEN), onClick = navigationBarActions.onProfileClick ) @@ -107,6 +111,8 @@ fun NavigationBar( @Composable fun NavigationBarPreview() { StudeezTheme { - NavigationBar(NavigationBarActions({ false }, {}, {}, {}, {})) + NavigationBar( + navigationBarActions = NavigationBarActions({ false }, {}, {}, {}, {}), + ) } } \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarViewModel.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarViewModel.kt index cadec72..1e4bd0d 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarViewModel.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarViewModel.kt @@ -7,41 +7,26 @@ import be.ugent.sel.studeez.navigation.StudeezDestinations.PROFILE_SCREEN import be.ugent.sel.studeez.screens.StudeezViewModel import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject -import javax.inject.Singleton @HiltViewModel class NavigationBarViewModel @Inject constructor( private val accountDAO: AccountDAO, - var selectedTab: SelectedTabState, logService: LogService ) : StudeezViewModel(logService) { - fun isSelected(screen: String): Boolean { - return screen == selectedTab.selectedTab - } - fun onHomeClick(open: (String) -> Unit) { - selectedTab.selectedTab = HOME_SCREEN open(HOME_SCREEN) } fun onTasksClick(open: (String) -> Unit) { // TODO - // selectedTab.selectedTab = TASKS_SCREEN } fun onSessionsClick(open: (String) -> Unit) { // TODO - // selectedTab.selectedTab = SESSIONS_SCREEN } fun onProfileClick(open: (String) -> Unit) { - selectedTab.selectedTab = PROFILE_SCREEN open(PROFILE_SCREEN) } -} - -@Singleton -class SelectedTabState @Inject constructor() { - var selectedTab: String = HOME_SCREEN } \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/home/HomeScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/home/HomeScreen.kt index ba322d9..0ea8e16 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/home/HomeScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/home/HomeScreen.kt @@ -23,6 +23,7 @@ import be.ugent.sel.studeez.resources fun HomeRoute( open: (String) -> Unit, openAndPopUp: (String, String) -> Unit, + getCurrentScreen: () -> String?, viewModel: HomeViewModel, drawerViewModel: DrawerViewModel, navBarViewModel: NavigationBarViewModel, @@ -30,7 +31,7 @@ fun HomeRoute( HomeScreen( onStartSessionClick = { viewModel.onStartSessionClick(open) }, drawerActions = getDrawerActions(drawerViewModel, open, openAndPopUp), - navigationBarActions = getNavigationBarActions(navBarViewModel, open), + navigationBarActions = getNavigationBarActions(navBarViewModel, open, getCurrentScreen), ) } @@ -45,7 +46,7 @@ fun HomeScreen( title = resources().getString(R.string.home), drawerActions = drawerActions, navigationBarActions = navigationBarActions, - action = { FriendsAction() } + barAction = { FriendsAction() } ) { BasicButton(R.string.start_session, Modifier.basicButton()) { onStartSessionClick() diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileScreen.kt index af72010..d68f05e 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileScreen.kt @@ -4,22 +4,17 @@ import androidx.compose.material.Icon import androidx.compose.material.IconButton import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Edit -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue +import androidx.compose.runtime.* import androidx.compose.ui.tooling.preview.Preview import androidx.hilt.navigation.compose.hiltViewModel import be.ugent.sel.studeez.R import be.ugent.sel.studeez.common.composable.Headline import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate -import be.ugent.sel.studeez.resources import be.ugent.sel.studeez.common.composable.drawer.DrawerActions import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions +import be.ugent.sel.studeez.resources import kotlinx.coroutines.CoroutineScope import be.ugent.sel.studeez.R.string as AppText @@ -42,12 +37,13 @@ fun getProfileActions( fun ProfileRoute( open: (String) -> Unit, openAndPopUp: (String, String) -> Unit, + getCurrentScreen: () -> String?, viewModel: ProfileViewModel, ) { ProfileScreen( profileActions = getProfileActions(viewModel, open), drawerActions = getDrawerActions(hiltViewModel(), open, openAndPopUp), - navigationBarActions = getNavigationBarActions(hiltViewModel(), open), + navigationBarActions = getNavigationBarActions(hiltViewModel(), open, getCurrentScreen), ) } @@ -65,7 +61,7 @@ fun ProfileScreen( title = resources().getString(AppText.profile), drawerActions = drawerActions, navigationBarActions = navigationBarActions, - action = { EditAction(onClick = profileActions.onEditProfileClick) } + barAction = { EditAction(onClick = profileActions.onEditProfileClick) } ) { Headline(text = (username ?: resources().getString(R.string.no_username))) } diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt index 007a656..54fac0d 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt @@ -41,6 +41,7 @@ fun getTimerSelectionActions( fun TimerSelectionRoute( open: (String) -> Unit, openAndPopUp: (String, String) -> Unit, + getCurrentScreen: () -> String?, viewModel: TimerSelectionViewModel, drawerViewModel: DrawerViewModel, navBarViewModel: NavigationBarViewModel, @@ -48,7 +49,7 @@ fun TimerSelectionRoute( TimerSelectionScreen( timerSelectionActions = getTimerSelectionActions(viewModel, open), drawerActions = getDrawerActions(drawerViewModel, open, openAndPopUp), - navigationBarActions = getNavigationBarActions(navBarViewModel, open), + navigationBarActions = getNavigationBarActions(navBarViewModel, open, getCurrentScreen), ) } From e898b6753d56984cfe8c41daa1a156f16d3a7104 Mon Sep 17 00:00:00 2001 From: tdpeuter Date: Wed, 26 Apr 2023 11:36:54 +0200 Subject: [PATCH 07/10] Remove log --- .../studeez/common/composable/navbar/NavigationBarComposable.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarComposable.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarComposable.kt index cdfd2d1..7a3da18 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarComposable.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/navbar/NavigationBarComposable.kt @@ -34,7 +34,6 @@ fun getNavigationBarActions( ): NavigationBarActions { return NavigationBarActions( isSelectedTab = { screen -> - Log.v("TEMP", getCurrentScreen().toString()) // TODO Remove screen == getCurrentScreen() }, onHomeClick = { From 18a055c5991e65febf3be5f15e9d2400346cd5e3 Mon Sep 17 00:00:00 2001 From: tdpeuter Date: Thu, 27 Apr 2023 23:15:25 +0200 Subject: [PATCH 08/10] TimerSelection is now secondary --- .../java/be/ugent/sel/studeez/StudeezApp.kt | 1 + .../timer_selection/TimerSelectionScreen.kt | 21 +++++++------------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/be/ugent/sel/studeez/StudeezApp.kt b/app/src/main/java/be/ugent/sel/studeez/StudeezApp.kt index 0744b42..bd915a3 100644 --- a/app/src/main/java/be/ugent/sel/studeez/StudeezApp.kt +++ b/app/src/main/java/be/ugent/sel/studeez/StudeezApp.kt @@ -159,6 +159,7 @@ fun StudeezNavGraph( TimerSelectionRoute( open, openAndPopUp, + goBack, getCurrentScreen, viewModel = hiltViewModel(), drawerViewModel = drawerViewModel, diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt index 54fac0d..b6e4711 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt @@ -8,15 +8,11 @@ import androidx.compose.runtime.collectAsState import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import be.ugent.sel.studeez.R -import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate +import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate import be.ugent.sel.studeez.common.composable.StealthButton import be.ugent.sel.studeez.common.composable.TimerEntry -import be.ugent.sel.studeez.common.composable.drawer.DrawerActions import be.ugent.sel.studeez.common.composable.drawer.DrawerViewModel -import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions -import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions import be.ugent.sel.studeez.common.composable.navbar.NavigationBarViewModel -import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo import be.ugent.sel.studeez.resources import kotlinx.coroutines.flow.Flow @@ -41,6 +37,7 @@ fun getTimerSelectionActions( fun TimerSelectionRoute( open: (String) -> Unit, openAndPopUp: (String, String) -> Unit, + popUp: () -> Unit, getCurrentScreen: () -> String?, viewModel: TimerSelectionViewModel, drawerViewModel: DrawerViewModel, @@ -48,22 +45,19 @@ fun TimerSelectionRoute( ) { TimerSelectionScreen( timerSelectionActions = getTimerSelectionActions(viewModel, open), - drawerActions = getDrawerActions(drawerViewModel, open, openAndPopUp), - navigationBarActions = getNavigationBarActions(navBarViewModel, open, getCurrentScreen), + popUp = popUp ) } @Composable fun TimerSelectionScreen( timerSelectionActions: TimerSelectionActions, - drawerActions: DrawerActions, - navigationBarActions: NavigationBarActions, + popUp: () -> Unit ) { val timers = timerSelectionActions.getAllTimers().collectAsState(initial = emptyList()) - PrimaryScreenTemplate( + SecondaryScreenTemplate( title = resources().getString(R.string.timers), - drawerActions = drawerActions, - navigationBarActions = navigationBarActions, + popUp = popUp ) { LazyColumn(verticalArrangement = Arrangement.spacedBy(7.dp)) { // All timers @@ -86,7 +80,6 @@ fun TimerSelectionScreen( fun TimerSelectionPreview() { TimerSelectionScreen( timerSelectionActions = TimerSelectionActions({ flowOf() }, {}), - drawerActions = DrawerActions({}, {}, {}, {}, {}), - navigationBarActions = NavigationBarActions({ false }, {}, {}, {}, {}), + popUp = {} ) } \ No newline at end of file From cf91d727a0adb6b953f7abe82b2ffe5532e2b50d Mon Sep 17 00:00:00 2001 From: tdpeuter Date: Fri, 28 Apr 2023 00:15:09 +0200 Subject: [PATCH 09/10] Minor styling of timerentries --- .../common/composable/ButtonComposable.kt | 15 ++---- .../studeez/common/composable/TimerEntry.kt | 47 ++++++++++++------- .../timer_overview/TimerOverviewScreen.kt | 14 ++---- .../timer_selection/TimerSelectionScreen.kt | 19 ++++---- 4 files changed, 48 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/ButtonComposable.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/ButtonComposable.kt index b2568aa..3fa9bd2 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/ButtonComposable.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/ButtonComposable.kt @@ -3,15 +3,9 @@ package be.ugent.sel.studeez.common.composable import androidx.annotation.StringRes import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.Button -import androidx.compose.material.ButtonColors -import androidx.compose.material.ButtonDefaults -import androidx.compose.material.MaterialTheme -import androidx.compose.material.Text -import androidx.compose.material.TextButton +import androidx.compose.material.* import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp @@ -21,7 +15,6 @@ import be.ugent.sel.studeez.common.ext.basicButton import be.ugent.sel.studeez.common.ext.card @Composable - fun BasicTextButton(@StringRes text: Int, modifier: Modifier, action: () -> Unit) { TextButton(onClick = action, modifier = modifier) { Text(text = stringResource(text)) } } @@ -64,10 +57,10 @@ fun StealthButton( onClick = onClick, modifier = Modifier.card(), colors = ButtonDefaults.buttonColors( - backgroundColor = Color.Transparent, - contentColor = Color.DarkGray, + backgroundColor = MaterialTheme.colors.surface, + contentColor = MaterialTheme.colors.onSurface ), - border = BorderStroke(3.dp, Color.DarkGray), + border = BorderStroke(1.dp, MaterialTheme.colors.onSurface) ) } diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/TimerEntry.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/TimerEntry.kt index bfa2711..7dc105b 100644 --- a/app/src/main/java/be/ugent/sel/studeez/common/composable/TimerEntry.kt +++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/TimerEntry.kt @@ -1,10 +1,6 @@ package be.ugent.sel.studeez.common.composable -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.* import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment @@ -20,24 +16,39 @@ import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo @Composable fun TimerEntry( timerInfo: TimerInfo, - button: @Composable () -> Unit, + rightButton: @Composable () -> Unit = {}, + leftButton: @Composable () -> Unit = {} ) { Row( - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.SpaceBetween + modifier = Modifier.fillMaxWidth() ) { - Column( - Modifier.padding(horizontal = 10.dp) + Row( + modifier = Modifier.weight(1f) ) { - Text( - text = timerInfo.name, fontWeight = FontWeight.Bold, fontSize = 20.sp - ) - Text( - text = timerInfo.description, fontWeight = FontWeight.Light, fontSize = 15.sp - ) + Box(modifier = Modifier.align(alignment = Alignment.CenterVertically)) { + leftButton() + } + + Column( + Modifier.padding( + horizontal = 20.dp, + vertical = 11.dp + ) + ) { + Text( + text = timerInfo.name, + fontWeight = FontWeight.Medium, + fontSize = 20.sp + ) + Text( + text = timerInfo.description, fontWeight = FontWeight.Light, fontSize = 14.sp + ) + } + } + + Box(modifier = Modifier.align(alignment = Alignment.CenterVertically)) { + rightButton() } - button() } } diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt index 9537965..ca38ba9 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt @@ -1,6 +1,5 @@ package be.ugent.sel.studeez.screens.timer_overview -import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items @@ -8,15 +7,14 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp import be.ugent.sel.studeez.R -import be.ugent.sel.studeez.common.composable.* +import be.ugent.sel.studeez.common.composable.BasicButton +import be.ugent.sel.studeez.common.composable.DrawerScreenTemplate +import be.ugent.sel.studeez.common.composable.StealthButton +import be.ugent.sel.studeez.common.composable.TimerEntry import be.ugent.sel.studeez.common.composable.drawer.DrawerActions import be.ugent.sel.studeez.common.composable.drawer.DrawerViewModel import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions -import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions -import be.ugent.sel.studeez.common.composable.navbar.NavigationBarViewModel -import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions import be.ugent.sel.studeez.common.ext.basicButton import be.ugent.sel.studeez.data.local.models.timer_info.CustomTimerInfo import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo @@ -66,9 +64,7 @@ fun TimerOverviewScreen( drawerActions = drawerActions ) { Column { - LazyColumn( - verticalArrangement = Arrangement.spacedBy(7.dp) - ) { + LazyColumn { // Default Timers, cannot be edited items(timerOverviewActions.getDefaultTimers()) { TimerEntry(timerInfo = it) {} diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt index b6e4711..2e52b0b 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt @@ -1,12 +1,12 @@ package be.ugent.sel.studeez.screens.timer_selection -import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items +import androidx.compose.material.Text +import androidx.compose.material.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp import be.ugent.sel.studeez.R import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate import be.ugent.sel.studeez.common.composable.StealthButton @@ -59,17 +59,18 @@ fun TimerSelectionScreen( title = resources().getString(R.string.timers), popUp = popUp ) { - LazyColumn(verticalArrangement = Arrangement.spacedBy(7.dp)) { + LazyColumn { // All timers items(timers.value) { timerInfo -> TimerEntry( timerInfo = timerInfo, - ) { - StealthButton( - text = R.string.start, - onClick = { timerSelectionActions.startSession(timerInfo) } - ) - } + leftButton = { + StealthButton( + text = R.string.start, + onClick = { timerSelectionActions.startSession(timerInfo) } + ) + } + ) } } } From 010c7cff5408968882c71fdc617ba7a239d0c2e2 Mon Sep 17 00:00:00 2001 From: brreynie Date: Fri, 28 Apr 2023 12:13:06 +0200 Subject: [PATCH 10/10] extract navbar and draweractions to StudeezNavGraph --- .../java/be/ugent/sel/studeez/StudeezApp.kt | 89 ++++++++++++------- .../sel/studeez/screens/home/HomeScreen.kt | 15 +--- .../studeez/screens/profile/ProfileScreen.kt | 18 ++-- .../studeez/screens/splash/SplashScreen.kt | 1 - .../timer_overview/TimerOverviewScreen.kt | 8 +- .../timer_selection/TimerSelectionScreen.kt | 8 -- 6 files changed, 72 insertions(+), 67 deletions(-) diff --git a/app/src/main/java/be/ugent/sel/studeez/StudeezApp.kt b/app/src/main/java/be/ugent/sel/studeez/StudeezApp.kt index bd915a3..28e3785 100644 --- a/app/src/main/java/be/ugent/sel/studeez/StudeezApp.kt +++ b/app/src/main/java/be/ugent/sel/studeez/StudeezApp.kt @@ -2,8 +2,18 @@ package be.ugent.sel.studeez import android.content.res.Resources import androidx.compose.foundation.layout.padding -import androidx.compose.material.* -import androidx.compose.runtime.* +import androidx.compose.material.MaterialTheme +import androidx.compose.material.Scaffold +import androidx.compose.material.ScaffoldState +import androidx.compose.material.Snackbar +import androidx.compose.material.SnackbarHost +import androidx.compose.material.Surface +import androidx.compose.material.rememberScaffoldState +import androidx.compose.runtime.Composable +import androidx.compose.runtime.ReadOnlyComposable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalContext @@ -14,8 +24,12 @@ import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController +import be.ugent.sel.studeez.common.composable.drawer.DrawerActions import be.ugent.sel.studeez.common.composable.drawer.DrawerViewModel +import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions +import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions import be.ugent.sel.studeez.common.composable.navbar.NavigationBarViewModel +import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions import be.ugent.sel.studeez.common.snackbar.SnackbarManager import be.ugent.sel.studeez.navigation.StudeezDestinations import be.ugent.sel.studeez.screens.home.HomeRoute @@ -82,48 +96,51 @@ fun StudeezNavGraph( val navBarViewModel: NavigationBarViewModel = hiltViewModel() val backStackEntry by appState.navController.currentBackStackEntryAsState() + val getCurrentScreen: () -> String? = { backStackEntry?.destination?.route } + + val goBack: () -> Unit = { appState.popUp() } + val open: (String) -> Unit = { appState.navigate(it) } + val openAndPopUp: (String, String) -> Unit = + { route, popUp -> appState.navigateAndPopUp(route, popUp) } + + val drawerActions: DrawerActions = getDrawerActions(drawerViewModel, open, openAndPopUp) + val navigationBarActions: NavigationBarActions = + getNavigationBarActions(navBarViewModel, open, getCurrentScreen) NavHost( navController = appState.navController, startDestination = StudeezDestinations.SPLASH_SCREEN, modifier = modifier, ) { - val goBack: () -> Unit = { - appState.popUp() - } - val open: (String) -> Unit = { route -> - appState.navigate(route) - } - - val openAndPopUp: (String, String) -> Unit = { route, popUp -> - appState.navigateAndPopUp(route, popUp) - } - - val getCurrentScreen: () -> String? = { - backStackEntry?.destination?.route - } composable(StudeezDestinations.SPLASH_SCREEN) { - SplashRoute(openAndPopUp, viewModel = hiltViewModel()) + SplashRoute( + openAndPopUp, + viewModel = hiltViewModel(), + ) } composable(StudeezDestinations.LOGIN_SCREEN) { - LoginRoute(openAndPopUp, viewModel = hiltViewModel()) + LoginRoute( + openAndPopUp, + viewModel = hiltViewModel(), + ) } composable(StudeezDestinations.SIGN_UP_SCREEN) { - SignUpRoute(openAndPopUp, viewModel = hiltViewModel()) + SignUpRoute( + openAndPopUp, + viewModel = hiltViewModel(), + ) } composable(StudeezDestinations.HOME_SCREEN) { HomeRoute( open, - openAndPopUp, - getCurrentScreen, viewModel = hiltViewModel(), - drawerViewModel = drawerViewModel, - navBarViewModel = navBarViewModel, + drawerActions = drawerActions, + navigationBarActions = navigationBarActions, ) } @@ -131,20 +148,26 @@ fun StudeezNavGraph( // TODO Sessions screen composable(StudeezDestinations.PROFILE_SCREEN) { - ProfileRoute(open, openAndPopUp, getCurrentScreen, viewModel = hiltViewModel()) + ProfileRoute( + open, + viewModel = hiltViewModel(), + drawerActions = drawerActions, + navigationBarActions = navigationBarActions, + ) } composable(StudeezDestinations.TIMER_OVERVIEW_SCREEN) { TimerOverviewRoute( - open, - openAndPopUp, viewModel = hiltViewModel(), - drawerViewModel = drawerViewModel + drawerActions = drawerActions, ) } composable(StudeezDestinations.SESSION_SCREEN) { - SessionRoute(open, viewModel = hiltViewModel()) + SessionRoute( + open, + viewModel = hiltViewModel() + ) } // TODO Timers screen @@ -152,18 +175,18 @@ fun StudeezNavGraph( // Edit screens composable(StudeezDestinations.EDIT_PROFILE_SCREEN) { - EditProfileRoute(goBack, openAndPopUp, viewModel = hiltViewModel()) + EditProfileRoute( + goBack, + openAndPopUp, + viewModel = hiltViewModel(), + ) } composable(StudeezDestinations.TIMER_SELECTION_SCREEN) { TimerSelectionRoute( open, - openAndPopUp, goBack, - getCurrentScreen, viewModel = hiltViewModel(), - drawerViewModel = drawerViewModel, - navBarViewModel = navBarViewModel, ) } } diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/home/HomeScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/home/HomeScreen.kt index 0ea8e16..1f760e5 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/home/HomeScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/home/HomeScreen.kt @@ -11,27 +11,21 @@ import be.ugent.sel.studeez.R import be.ugent.sel.studeez.common.composable.BasicButton import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate import be.ugent.sel.studeez.common.composable.drawer.DrawerActions -import be.ugent.sel.studeez.common.composable.drawer.DrawerViewModel -import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions -import be.ugent.sel.studeez.common.composable.navbar.NavigationBarViewModel -import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions import be.ugent.sel.studeez.common.ext.basicButton import be.ugent.sel.studeez.resources @Composable fun HomeRoute( open: (String) -> Unit, - openAndPopUp: (String, String) -> Unit, - getCurrentScreen: () -> String?, viewModel: HomeViewModel, - drawerViewModel: DrawerViewModel, - navBarViewModel: NavigationBarViewModel, + drawerActions: DrawerActions, + navigationBarActions: NavigationBarActions, ) { HomeScreen( onStartSessionClick = { viewModel.onStartSessionClick(open) }, - drawerActions = getDrawerActions(drawerViewModel, open, openAndPopUp), - navigationBarActions = getNavigationBarActions(navBarViewModel, open, getCurrentScreen), + drawerActions = drawerActions, + navigationBarActions = navigationBarActions, ) } @@ -41,7 +35,6 @@ fun HomeScreen( drawerActions: DrawerActions, navigationBarActions: NavigationBarActions, ) { - PrimaryScreenTemplate( title = resources().getString(R.string.home), drawerActions = drawerActions, diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileScreen.kt index d68f05e..0b4a67f 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileScreen.kt @@ -4,16 +4,18 @@ import androidx.compose.material.Icon import androidx.compose.material.IconButton import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Edit -import androidx.compose.runtime.* +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.tooling.preview.Preview -import androidx.hilt.navigation.compose.hiltViewModel import be.ugent.sel.studeez.R import be.ugent.sel.studeez.common.composable.Headline import be.ugent.sel.studeez.common.composable.PrimaryScreenTemplate import be.ugent.sel.studeez.common.composable.drawer.DrawerActions -import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions import be.ugent.sel.studeez.common.composable.navbar.NavigationBarActions -import be.ugent.sel.studeez.common.composable.navbar.getNavigationBarActions import be.ugent.sel.studeez.resources import kotlinx.coroutines.CoroutineScope import be.ugent.sel.studeez.R.string as AppText @@ -36,14 +38,14 @@ fun getProfileActions( @Composable fun ProfileRoute( open: (String) -> Unit, - openAndPopUp: (String, String) -> Unit, - getCurrentScreen: () -> String?, viewModel: ProfileViewModel, + drawerActions: DrawerActions, + navigationBarActions: NavigationBarActions, ) { ProfileScreen( profileActions = getProfileActions(viewModel, open), - drawerActions = getDrawerActions(hiltViewModel(), open, openAndPopUp), - navigationBarActions = getNavigationBarActions(hiltViewModel(), open, getCurrentScreen), + drawerActions = drawerActions, + navigationBarActions = navigationBarActions, ) } diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/splash/SplashScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/splash/SplashScreen.kt index a5b0e81..e70c67b 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/splash/SplashScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/splash/SplashScreen.kt @@ -1,6 +1,5 @@ package be.ugent.sel.studeez.screens.splash -import android.window.SplashScreen import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt index ca38ba9..9489a30 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt @@ -13,8 +13,6 @@ import be.ugent.sel.studeez.common.composable.DrawerScreenTemplate import be.ugent.sel.studeez.common.composable.StealthButton import be.ugent.sel.studeez.common.composable.TimerEntry import be.ugent.sel.studeez.common.composable.drawer.DrawerActions -import be.ugent.sel.studeez.common.composable.drawer.DrawerViewModel -import be.ugent.sel.studeez.common.composable.drawer.getDrawerActions import be.ugent.sel.studeez.common.ext.basicButton import be.ugent.sel.studeez.data.local.models.timer_info.CustomTimerInfo import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo @@ -40,14 +38,12 @@ fun getTimerOverviewActions( @Composable fun TimerOverviewRoute( - open: (String) -> Unit, - openAndPopUp: (String, String) -> Unit, viewModel: TimerOverviewViewModel, - drawerViewModel: DrawerViewModel + drawerActions: DrawerActions, ) { TimerOverviewScreen( timerOverviewActions = getTimerOverviewActions(viewModel), - drawerActions = getDrawerActions(drawerViewModel, open, openAndPopUp) + drawerActions = drawerActions, ) } diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt index 2e52b0b..ac46b5c 100644 --- a/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt +++ b/app/src/main/java/be/ugent/sel/studeez/screens/timer_selection/TimerSelectionScreen.kt @@ -2,8 +2,6 @@ package be.ugent.sel.studeez.screens.timer_selection import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items -import androidx.compose.material.Text -import androidx.compose.material.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.ui.tooling.preview.Preview @@ -11,8 +9,6 @@ import be.ugent.sel.studeez.R import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate import be.ugent.sel.studeez.common.composable.StealthButton import be.ugent.sel.studeez.common.composable.TimerEntry -import be.ugent.sel.studeez.common.composable.drawer.DrawerViewModel -import be.ugent.sel.studeez.common.composable.navbar.NavigationBarViewModel import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo import be.ugent.sel.studeez.resources import kotlinx.coroutines.flow.Flow @@ -36,12 +32,8 @@ fun getTimerSelectionActions( @Composable fun TimerSelectionRoute( open: (String) -> Unit, - openAndPopUp: (String, String) -> Unit, popUp: () -> Unit, - getCurrentScreen: () -> String?, viewModel: TimerSelectionViewModel, - drawerViewModel: DrawerViewModel, - navBarViewModel: NavigationBarViewModel, ) { TimerSelectionScreen( timerSelectionActions = getTimerSelectionActions(viewModel, open),