diff --git a/app/src/main/java/com/starry/greenstash/MainViewModel.kt b/app/src/main/java/com/starry/greenstash/MainViewModel.kt index f415b34..6d74509 100644 --- a/app/src/main/java/com/starry/greenstash/MainViewModel.kt +++ b/app/src/main/java/com/starry/greenstash/MainViewModel.kt @@ -41,7 +41,7 @@ import com.starry.greenstash.database.goal.GoalDao import com.starry.greenstash.other.WelcomeDataStore import com.starry.greenstash.reminder.ReminderManager import com.starry.greenstash.ui.navigation.DrawerScreens -import com.starry.greenstash.ui.navigation.Screens +import com.starry.greenstash.ui.navigation.WelcomeScreen import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay @@ -66,9 +66,9 @@ class MainViewModel @Inject constructor( private val _isLoading: MutableState = mutableStateOf(true) val isLoading: State = _isLoading - private val _startDestination: MutableState = - mutableStateOf(Screens.WelcomeScreen.route) - val startDestination: State = _startDestination + private val _startDestination: MutableState = + mutableStateOf(WelcomeScreen) + val startDestination: State = _startDestination companion object { // Must be same as the one in AndroidManifest.xml @@ -85,9 +85,9 @@ class MainViewModel @Inject constructor( viewModelScope.launch { welcomeDataStore.readOnBoardingState().collect { completed -> if (completed) { - _startDestination.value = DrawerScreens.Home.route + _startDestination.value = DrawerScreens.Home } else { - _startDestination.value = Screens.WelcomeScreen.route + _startDestination.value = WelcomeScreen } delay(120) diff --git a/app/src/main/java/com/starry/greenstash/ui/navigation/DrawerScreens.kt b/app/src/main/java/com/starry/greenstash/ui/navigation/DrawerScreens.kt index 7ce7e06..9de280c 100644 --- a/app/src/main/java/com/starry/greenstash/ui/navigation/DrawerScreens.kt +++ b/app/src/main/java/com/starry/greenstash/ui/navigation/DrawerScreens.kt @@ -26,23 +26,29 @@ package com.starry.greenstash.ui.navigation import com.starry.greenstash.R +import kotlinx.serialization.Serializable -sealed class DrawerScreens(val route: String, val nameResId: Int, val iconResId: Int) { +@Serializable +sealed class DrawerScreens( val nameResId: Int, val iconResId: Int) { companion object { fun getAllItems() = listOf(Home, Archive, Backups, Settings) } - data object Home : DrawerScreens("home", R.string.drawer_home, R.drawable.ic_nav_home) + @Serializable + data object Home : DrawerScreens( R.string.drawer_home, R.drawable.ic_nav_home) + @Serializable data object Archive : - DrawerScreens("archive", R.string.drawer_archive, R.drawable.ic_nav_archive) + DrawerScreens( R.string.drawer_archive, R.drawable.ic_nav_archive) + @Serializable data object Backups : - DrawerScreens("backups", R.string.drawer_backup, R.drawable.ic_nav_backups) + DrawerScreens( R.string.drawer_backup, R.drawable.ic_nav_backups) + @Serializable data object Settings : - DrawerScreens("settings", R.string.drawer_settings, R.drawable.ic_nav_settings) + DrawerScreens( R.string.drawer_settings, R.drawable.ic_nav_settings) } diff --git a/app/src/main/java/com/starry/greenstash/ui/navigation/NavGraph.kt b/app/src/main/java/com/starry/greenstash/ui/navigation/NavGraph.kt index 2ce7ed2..f7de861 100644 --- a/app/src/main/java/com/starry/greenstash/ui/navigation/NavGraph.kt +++ b/app/src/main/java/com/starry/greenstash/ui/navigation/NavGraph.kt @@ -50,8 +50,9 @@ import com.starry.greenstash.ui.screens.welcome.composables.WelcomeScreen @Composable fun NavGraph( navController: NavHostController, - startDestination: String + startDestination: Any ) { + NavHost( navController = navController, startDestination = startDestination, @@ -59,8 +60,7 @@ fun NavGraph( ) { /** Welcome Screen */ - composable( - route = Screens.WelcomeScreen.route, + composable( exitTransition = { exitTransition() }, popEnterTransition = { popEnterTransition() }, ) { @@ -68,8 +68,7 @@ fun NavGraph( } /** Home Screen */ - composable( - route = DrawerScreens.Home.route, + composable( enterTransition = { enterTransition() }, exitTransition = { exitTransition() }, popEnterTransition = { popEnterTransition() }, @@ -116,8 +115,7 @@ fun NavGraph( } /** Goal Achieved Screen */ - composable( - route = Screens.CongratsScreen.route, + composable( enterTransition = { enterTransition() }, exitTransition = { exitTransition() }, popEnterTransition = { popEnterTransition() }, @@ -127,8 +125,7 @@ fun NavGraph( } /** Archive Screen */ - composable( - route = DrawerScreens.Archive.route, + composable( enterTransition = { enterTransition() }, exitTransition = { exitTransition() }, popEnterTransition = { popEnterTransition() }, @@ -138,8 +135,7 @@ fun NavGraph( } /** Backup Screen */ - composable( - route = DrawerScreens.Backups.route, + composable( enterTransition = { enterTransition() }, exitTransition = { exitTransition() }, popEnterTransition = { popEnterTransition() }, @@ -149,8 +145,7 @@ fun NavGraph( } /** Settings Screen */ - composable( - route = DrawerScreens.Settings.route, + composable( enterTransition = { enterTransition() }, exitTransition = { exitTransition() }, popEnterTransition = { popEnterTransition() }, @@ -160,8 +155,7 @@ fun NavGraph( } /** Goal Ui Settings Screen */ - composable( - route = Screens.GoalCardStyle.route, + composable( enterTransition = { enterTransition() }, popExitTransition = { popExitTransition() }, ) { @@ -169,8 +163,7 @@ fun NavGraph( } /** Open Source Licenses Screen */ - composable( - route = Screens.OSLScreen.route, + composable( enterTransition = { enterTransition() }, popExitTransition = { popExitTransition() }, ) { @@ -178,8 +171,7 @@ fun NavGraph( } /** About Screen */ - composable( - route = Screens.AboutScreen.route, + composable( enterTransition = { enterTransition() }, popExitTransition = { popExitTransition() }, ) { diff --git a/app/src/main/java/com/starry/greenstash/ui/navigation/ScreenArgs.kt b/app/src/main/java/com/starry/greenstash/ui/navigation/ScreenArgs.kt deleted file mode 100644 index d15dbd7..0000000 --- a/app/src/main/java/com/starry/greenstash/ui/navigation/ScreenArgs.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.starry.greenstash.ui.navigation - -import kotlinx.serialization.Serializable - - - - -@Serializable -data class DWScreen(val goalId: String, val transactionType: String) - - -@Serializable -data class InputScreen(val goalId: String? = null) - - -@Serializable -data class GoalInfoScreen(val goalId: String) - - - diff --git a/app/src/main/java/com/starry/greenstash/ui/navigation/Screens.kt b/app/src/main/java/com/starry/greenstash/ui/navigation/Screens.kt index b796661..d8c0768 100644 --- a/app/src/main/java/com/starry/greenstash/ui/navigation/Screens.kt +++ b/app/src/main/java/com/starry/greenstash/ui/navigation/Screens.kt @@ -1,45 +1,36 @@ -/** - * MIT License - * - * Copyright (c) [2022 - Present] Stɑrry Shivɑm - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ +package com.starry.greenstash.ui.navigation +import kotlinx.serialization.Serializable -package com.starry.greenstash.ui.navigation -sealed class Screens(val route: String) { - // Settings Screens +@Serializable +data class DWScreen(val goalId: String, val transactionType: String) + + +@Serializable +data class InputScreen(val goalId: String? = null) + + +@Serializable +data class GoalInfoScreen(val goalId: String) + +@Serializable +object AboutScreen - data object GoalCardStyle : Screens("goal_card_style") +@Serializable +object OSLScreen +@Serializable +object GoalCardStyleScreen - data object AboutScreen : Screens("about_screen") +// Goal Achieved Screen +@Serializable +object CongratsScreen - data object OSLScreen : Screens("osl_screen") +// Welcome / Onboarding Screen +@Serializable +object WelcomeScreen - // Goal Achieved Screen - data object CongratsScreen : Screens("goal_achieved_screen") - // Welcome / Onboarding Screen - data object WelcomeScreen : Screens("welcome_screen") -} diff --git a/app/src/main/java/com/starry/greenstash/ui/screens/dwscreen/composables/DWScreen.kt b/app/src/main/java/com/starry/greenstash/ui/screens/dwscreen/composables/DWScreen.kt index 10e32bd..dac0307 100644 --- a/app/src/main/java/com/starry/greenstash/ui/screens/dwscreen/composables/DWScreen.kt +++ b/app/src/main/java/com/starry/greenstash/ui/screens/dwscreen/composables/DWScreen.kt @@ -84,8 +84,8 @@ import com.maxkeppeler.sheets.date_time.models.DateTimeSelection import com.starry.greenstash.R import com.starry.greenstash.database.transaction.TransactionType import com.starry.greenstash.ui.common.DateTimeCard +import com.starry.greenstash.ui.navigation.CongratsScreen import com.starry.greenstash.ui.navigation.DrawerScreens -import com.starry.greenstash.ui.navigation.Screens import com.starry.greenstash.ui.screens.dwscreen.DWViewModel import com.starry.greenstash.ui.theme.greenstashFont import com.starry.greenstash.utils.NumberUtils @@ -208,7 +208,7 @@ fun DWScreen(goalId: String, transactionTypeName: String, navController: NavCont showTransactionAddedAnim.value = true delay(1100) withContext(Dispatchers.Main) { - navController.navigate(Screens.CongratsScreen.route) + navController.navigate(CongratsScreen) } } }, onComplete = { @@ -414,8 +414,8 @@ private fun navigateToHome( showTransactionAddedAnim.value = true delay(1100) withContext(Dispatchers.Main) { - navController.popBackStack(DrawerScreens.Home.route, true) - navController.navigate(DrawerScreens.Home.route) + navController.popBackStack(DrawerScreens.Home, true) + navController.navigate(DrawerScreens.Home) } } } diff --git a/app/src/main/java/com/starry/greenstash/ui/screens/home/composables/GoalLazyItem.kt b/app/src/main/java/com/starry/greenstash/ui/screens/home/composables/GoalLazyItem.kt index 0d8e790..6e050ad 100644 --- a/app/src/main/java/com/starry/greenstash/ui/screens/home/composables/GoalLazyItem.kt +++ b/app/src/main/java/com/starry/greenstash/ui/screens/home/composables/GoalLazyItem.kt @@ -46,7 +46,6 @@ import com.starry.greenstash.database.transaction.TransactionType import com.starry.greenstash.ui.navigation.DWScreen import com.starry.greenstash.ui.navigation.GoalInfoScreen import com.starry.greenstash.ui.navigation.InputScreen -import com.starry.greenstash.ui.navigation.Screens import com.starry.greenstash.ui.screens.home.GoalCardStyle import com.starry.greenstash.ui.screens.home.HomeViewModel import com.starry.greenstash.utils.Constants diff --git a/app/src/main/java/com/starry/greenstash/ui/screens/home/composables/HomeDrawer.kt b/app/src/main/java/com/starry/greenstash/ui/screens/home/composables/HomeDrawer.kt index 21a029e..1f9e2cc 100644 --- a/app/src/main/java/com/starry/greenstash/ui/screens/home/composables/HomeDrawer.kt +++ b/app/src/main/java/com/starry/greenstash/ui/screens/home/composables/HomeDrawer.kt @@ -199,12 +199,14 @@ private fun DrawerItems( selected = item == selectedItem.value, onClick = { view.weakHapticFeedback() - selectedItem.value = item coroutineScope.launch { drawerState.close() - withContext(Dispatchers.Main) { - navController.navigate(item.route) + if (item != selectedItem.value) { + withContext(Dispatchers.Main) { + navController.navigate(item) + } } + selectedItem.value = item } }, modifier = Modifier diff --git a/app/src/main/java/com/starry/greenstash/ui/screens/home/composables/HomeScreen.kt b/app/src/main/java/com/starry/greenstash/ui/screens/home/composables/HomeScreen.kt index 130910c..de0cdac 100644 --- a/app/src/main/java/com/starry/greenstash/ui/screens/home/composables/HomeScreen.kt +++ b/app/src/main/java/com/starry/greenstash/ui/screens/home/composables/HomeScreen.kt @@ -103,7 +103,6 @@ import com.starry.greenstash.MainActivity import com.starry.greenstash.R import com.starry.greenstash.database.core.GoalWithTransactions import com.starry.greenstash.ui.navigation.InputScreen -import com.starry.greenstash.ui.navigation.Screens import com.starry.greenstash.ui.screens.home.FilterField import com.starry.greenstash.ui.screens.home.FilterSortType import com.starry.greenstash.ui.screens.home.HomeViewModel diff --git a/app/src/main/java/com/starry/greenstash/ui/screens/input/composables/InputScreen.kt b/app/src/main/java/com/starry/greenstash/ui/screens/input/composables/InputScreen.kt index 144aa0a..6d04fdb 100644 --- a/app/src/main/java/com/starry/greenstash/ui/screens/input/composables/InputScreen.kt +++ b/app/src/main/java/com/starry/greenstash/ui/screens/input/composables/InputScreen.kt @@ -474,10 +474,10 @@ fun InputScreen(editGoalId: String?, navController: NavController) { delay(1050) withContext(Dispatchers.Main) { navController.popBackStack( - DrawerScreens.Home.route, + DrawerScreens.Home, true ) - navController.navigate(DrawerScreens.Home.route) + navController.navigate(DrawerScreens.Home) } } } diff --git a/app/src/main/java/com/starry/greenstash/ui/screens/main/MainScreen.kt b/app/src/main/java/com/starry/greenstash/ui/screens/main/MainScreen.kt index 75a3475..6db4f3c 100644 --- a/app/src/main/java/com/starry/greenstash/ui/screens/main/MainScreen.kt +++ b/app/src/main/java/com/starry/greenstash/ui/screens/main/MainScreen.kt @@ -43,7 +43,6 @@ import com.starry.greenstash.MainViewModel import com.starry.greenstash.ui.navigation.GoalInfoScreen import com.starry.greenstash.ui.navigation.InputScreen import com.starry.greenstash.ui.navigation.NavGraph -import com.starry.greenstash.ui.navigation.Screens import com.starry.greenstash.ui.screens.other.AppLockedScreen import com.starry.greenstash.ui.screens.settings.ThemeMode import com.starry.greenstash.ui.theme.AdjustEdgeToEdge @@ -56,7 +55,7 @@ import com.starry.greenstash.ui.theme.AdjustEdgeToEdge fun MainScreen( activity: MainActivity, showAppContents: Boolean, - startDestination: String, + startDestination: Any, currentThemeMode: ThemeMode, onAuthRequest: () -> Unit, ) { diff --git a/app/src/main/java/com/starry/greenstash/ui/screens/other/CongratsScreen.kt b/app/src/main/java/com/starry/greenstash/ui/screens/other/CongratsScreen.kt index c3111a8..7482de9 100644 --- a/app/src/main/java/com/starry/greenstash/ui/screens/other/CongratsScreen.kt +++ b/app/src/main/java/com/starry/greenstash/ui/screens/other/CongratsScreen.kt @@ -83,8 +83,8 @@ fun CongratsScreen(navController: NavController) { }) BackHandler { - navController.popBackStack(DrawerScreens.Home.route, true) - navController.navigate(DrawerScreens.Home.route) + navController.popBackStack(DrawerScreens.Home, true) + navController.navigate(DrawerScreens.Home) } Column( @@ -148,8 +148,8 @@ fun CongratsScreen(navController: NavController) { SlideInAnimatedContainer(initialDelay = 2000) { FilledTonalButton( onClick = { - navController.popBackStack(DrawerScreens.Home.route, true) - navController.navigate(DrawerScreens.Home.route) + navController.popBackStack(DrawerScreens.Home, true) + navController.navigate(DrawerScreens.Home) }, shape = RoundedCornerShape(12.dp), modifier = Modifier diff --git a/app/src/main/java/com/starry/greenstash/ui/screens/settings/composables/SettingsScreen.kt b/app/src/main/java/com/starry/greenstash/ui/screens/settings/composables/SettingsScreen.kt index 82b3a31..409de09 100644 --- a/app/src/main/java/com/starry/greenstash/ui/screens/settings/composables/SettingsScreen.kt +++ b/app/src/main/java/com/starry/greenstash/ui/screens/settings/composables/SettingsScreen.kt @@ -93,7 +93,9 @@ import com.starry.greenstash.MainActivity import com.starry.greenstash.R import com.starry.greenstash.ui.common.CurrencyPicker import com.starry.greenstash.ui.common.CurrencyPickerData -import com.starry.greenstash.ui.navigation.Screens +import com.starry.greenstash.ui.navigation.AboutScreen +import com.starry.greenstash.ui.navigation.GoalCardStyleScreen +import com.starry.greenstash.ui.navigation.OSLScreen import com.starry.greenstash.ui.screens.home.GoalCardStyle import com.starry.greenstash.ui.screens.settings.DateStyle import com.starry.greenstash.ui.screens.settings.SettingsViewModel @@ -231,7 +233,7 @@ private fun DisplaySettings(viewModel: SettingsViewModel, navController: NavCont SettingsItem(title = stringResource(id = R.string.goal_card_setting), description = goalStyleValue, icon = Icons.Filled.Style, - onClick = { navController.navigate(Screens.GoalCardStyle.route) }) + onClick = { navController.navigate(GoalCardStyleScreen) }) if (showThemeSheet.value) { ThemePickerDialog( @@ -553,11 +555,11 @@ private fun MiscSettings(navController: NavController) { SettingsItem(title = stringResource(id = R.string.license_setting), description = stringResource(id = R.string.license_setting_desc), icon = Icons.Filled.LocalPolice, - onClick = { navController.navigate(Screens.OSLScreen.route) }) + onClick = { navController.navigate(OSLScreen) }) SettingsItem(title = stringResource(id = R.string.app_info_setting), description = stringResource(id = R.string.app_info_setting_desc), icon = Icons.Filled.Info, - onClick = { navController.navigate(Screens.AboutScreen.route) }) + onClick = { navController.navigate(AboutScreen) }) } Spacer(modifier = Modifier.height(2.dp)) // Last item padding. } diff --git a/app/src/main/java/com/starry/greenstash/ui/screens/welcome/composables/WelcomeScreen.kt b/app/src/main/java/com/starry/greenstash/ui/screens/welcome/composables/WelcomeScreen.kt index 8a1327c..97c1098 100644 --- a/app/src/main/java/com/starry/greenstash/ui/screens/welcome/composables/WelcomeScreen.kt +++ b/app/src/main/java/com/starry/greenstash/ui/screens/welcome/composables/WelcomeScreen.kt @@ -164,7 +164,7 @@ fun WelcomeScreen(navController: NavController) { view.weakHapticFeedback() viewModel.saveOnBoardingState(completed = true) navController.popBackStack() - navController.navigate(DrawerScreens.Home.route) + navController.navigate(DrawerScreens.Home) }, modifier = Modifier.width(245.dp), shape = RoundedCornerShape(16.dp)