From 761869ec97694bab27afb0d33dd0ce0c4c41970b Mon Sep 17 00:00:00 2001 From: imrannextgeni021 Date: Fri, 11 Oct 2024 02:41:59 +0500 Subject: [PATCH 1/3] Migrated from navigating with parameters to type-safe navigation --- app/build.gradle | 2 +- .../greenstash/ui/navigation/NavGraph.kt | 49 ++++++------------- .../greenstash/ui/navigation/ScreenArgs.kt | 20 ++++++++ .../greenstash/ui/navigation/Screens.kt | 34 ++----------- .../screens/home/composables/GoalLazyItem.kt | 27 +++++----- .../ui/screens/home/composables/HomeScreen.kt | 3 +- .../greenstash/ui/screens/main/MainScreen.kt | 6 ++- 7 files changed, 61 insertions(+), 80 deletions(-) create mode 100644 app/src/main/java/com/starry/greenstash/ui/navigation/ScreenArgs.kt diff --git a/app/build.gradle b/app/build.gradle index cc02c7f9..4580e8bb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -92,7 +92,7 @@ dependencies { implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.8.6" implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.8.6" // TODO: Needs migration to type-safe navigation in v2.8.x - implementation "androidx.navigation:navigation-compose:2.7.7" + implementation "androidx.navigation:navigation-compose:2.8.2" // Jetpack compose. implementation "androidx.compose.ui:ui" implementation "androidx.compose.ui:ui-tooling-preview" 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 66535de1..2ce7ed24 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 @@ -30,10 +30,9 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.navigation.NavHostController -import androidx.navigation.NavType import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable -import androidx.navigation.navArgument +import androidx.navigation.toRoute import com.starry.greenstash.ui.screens.archive.composables.ArchiveScreen import com.starry.greenstash.ui.screens.backups.composables.BackupScreen import com.starry.greenstash.ui.screens.dwscreen.composables.DWScreen @@ -80,60 +79,40 @@ fun NavGraph( } /** Deposit Withdraw Screen */ - composable( - route = Screens.DWScreen.route, + composable( enterTransition = { enterTransition() }, exitTransition = { exitTransition() }, popEnterTransition = { popEnterTransition() }, - popExitTransition = { popExitTransition() }, - arguments = listOf( - navArgument(DW_GOAL_ID_ARG_KEY) { - type = NavType.StringType - }, - ), + popExitTransition = { popExitTransition() } ) { backStackEntry -> - val goalId = backStackEntry.arguments!!.getString(DW_GOAL_ID_ARG_KEY)!! - val transactionType = - backStackEntry.arguments!!.getString(DW_TRANSACTION_TYPE_ARG_KEY)!! + val args = backStackEntry.toRoute() DWScreen( - goalId = goalId, - transactionTypeName = transactionType, + goalId = args.goalId, + transactionTypeName = args.transactionType, navController = navController ) } /** Goal Info Screen */ - composable( - route = Screens.GoalInfoScreen.route, + composable( enterTransition = { enterTransition() }, exitTransition = { exitTransition() }, popEnterTransition = { popEnterTransition() }, - popExitTransition = { popExitTransition() }, - arguments = listOf( - navArgument(GOAL_INFO_ARG_KEY) { - type = NavType.StringType - }, - ), + popExitTransition = { popExitTransition() } ) { backStackEntry -> - val goalId = backStackEntry.arguments!!.getString(GOAL_INFO_ARG_KEY)!! - GoalInfoScreen(goalId = goalId, navController = navController) + val args = backStackEntry.toRoute() + GoalInfoScreen(goalId = args.goalId, navController = navController) } /** Input Screen */ - composable( - route = Screens.InputScreen.route, + composable( enterTransition = { enterTransition() }, exitTransition = { exitTransition() }, popEnterTransition = { popEnterTransition() }, - popExitTransition = { popExitTransition() }, - arguments = listOf(navArgument(EDIT_GOAL_ARG_KEY) { - nullable = true - defaultValue = null - type = NavType.StringType - }) + popExitTransition = { popExitTransition() } ) { backStackEntry -> - val editGoalId = backStackEntry.arguments!!.getString(EDIT_GOAL_ARG_KEY) - InputScreen(editGoalId = editGoalId, navController = navController) + val args = backStackEntry.toRoute() + InputScreen(editGoalId = args.goalId, navController = navController) } /** Goal Achieved Screen */ 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 new file mode 100644 index 00000000..d15dbd77 --- /dev/null +++ b/app/src/main/java/com/starry/greenstash/ui/navigation/ScreenArgs.kt @@ -0,0 +1,20 @@ +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 1c135a47..b7966614 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 @@ -25,45 +25,21 @@ package com.starry.greenstash.ui.navigation -const val DW_GOAL_ID_ARG_KEY = "dwGoal" -const val DW_TRANSACTION_TYPE_ARG_KEY = "dwTransactionType" -const val EDIT_GOAL_ARG_KEY = "editGoal" -const val GOAL_INFO_ARG_KEY = "goalId" - sealed class Screens(val route: String) { + // Settings Screens - // Deposit / Withdraw Screens + data object GoalCardStyle : Screens("goal_card_style") - data object DWScreen : - Screens("deposit_withdraw_screen/{$DW_GOAL_ID_ARG_KEY}/{$DW_TRANSACTION_TYPE_ARG_KEY}") { - fun withGoalId(goalId: String, trasactionType: String): String { - return route.replace("{$DW_GOAL_ID_ARG_KEY}", goalId) - .replace("{$DW_TRANSACTION_TYPE_ARG_KEY}", trasactionType) - } - } - // New Goal / Edit Goal Screen - data object InputScreen : Screens("input_screen?$EDIT_GOAL_ARG_KEY={$EDIT_GOAL_ARG_KEY}") { - fun withGoalToEdit(goalId: String): String { - return route.replace("{$EDIT_GOAL_ARG_KEY}", goalId) - } - } + data object AboutScreen : Screens("about_screen") - // Goal Info Screen - data object GoalInfoScreen : Screens("goal_info_screen/{$GOAL_INFO_ARG_KEY}") { - fun withGoalId(goalId: String): String { - return route.replace("{$GOAL_INFO_ARG_KEY}", goalId) - } - } - // Settings Screens - data object GoalCardStyle : Screens("goal_card_style") - data object AboutScreen : Screens("about_screen") data object OSLScreen : Screens("osl_screen") // Goal Achieved Screen + data object CongratsScreen : Screens("goal_achieved_screen") // Welcome / Onboarding Screen data object WelcomeScreen : Screens("welcome_screen") -} \ No newline at end of file +} 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 00ef6cc1..0d8e7907 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 @@ -43,6 +43,9 @@ import com.starry.greenstash.MainActivity import com.starry.greenstash.R import com.starry.greenstash.database.core.GoalWithTransactions 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 @@ -107,9 +110,9 @@ fun GoalLazyColumnItem( } } else { navController.navigate( - Screens.DWScreen.withGoalId( + DWScreen( goalId = item.goal.goalId.toString(), - trasactionType = TransactionType.Deposit.name + transactionType = TransactionType.Deposit.name ) ) } @@ -122,9 +125,9 @@ fun GoalLazyColumnItem( } } else { navController.navigate( - Screens.DWScreen.withGoalId( + DWScreen( goalId = item.goal.goalId.toString(), - trasactionType = TransactionType.Withdraw.name + transactionType = TransactionType.Withdraw.name ) ) } @@ -132,7 +135,7 @@ fun GoalLazyColumnItem( onInfoClicked = { localView.weakHapticFeedback() navController.navigate( - Screens.GoalInfoScreen.withGoalId( + GoalInfoScreen( goalId = item.goal.goalId.toString() ) ) @@ -140,7 +143,7 @@ fun GoalLazyColumnItem( onEditClicked = { localView.weakHapticFeedback() navController.navigate( - Screens.InputScreen.withGoalToEdit( + InputScreen( goalId = item.goal.goalId.toString() ) ) @@ -191,9 +194,9 @@ fun GoalLazyColumnItem( } } else { navController.navigate( - Screens.DWScreen.withGoalId( + DWScreen( goalId = item.goal.goalId.toString(), - trasactionType = TransactionType.Deposit.name + transactionType = TransactionType.Deposit.name ) ) } @@ -206,9 +209,9 @@ fun GoalLazyColumnItem( } } else { navController.navigate( - Screens.DWScreen.withGoalId( + DWScreen( goalId = item.goal.goalId.toString(), - trasactionType = TransactionType.Withdraw.name + transactionType = TransactionType.Withdraw.name ) ) } @@ -216,7 +219,7 @@ fun GoalLazyColumnItem( onInfoClicked = { localView.weakHapticFeedback() navController.navigate( - Screens.GoalInfoScreen.withGoalId( + GoalInfoScreen( goalId = item.goal.goalId.toString() ) ) @@ -224,7 +227,7 @@ fun GoalLazyColumnItem( onEditClicked = { localView.weakHapticFeedback() navController.navigate( - Screens.InputScreen.withGoalToEdit( + InputScreen( goalId = item.goal.goalId.toString() ) ) 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 d2bdfcc7..130910c8 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 @@ -102,6 +102,7 @@ import com.psoffritti.taptargetcompose.TextDefinition 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 @@ -418,7 +419,7 @@ private fun HomeExtendedFAB( modifier = modifier.padding(end = 10.dp, bottom = 12.dp), onClick = { view.weakHapticFeedback() - navController.navigate(Screens.InputScreen.route) + navController.navigate(InputScreen()) }, elevation = FloatingActionButtonDefaults.elevation(8.dp) ) { 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 fcdb5a7b..75a3475e 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 @@ -40,6 +40,8 @@ import androidx.navigation.NavController import androidx.navigation.compose.rememberNavController import com.starry.greenstash.MainActivity 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 @@ -98,11 +100,11 @@ private fun HandleShortcutIntent(intent: Intent, navController: NavController) { if (data != null && data.scheme == MainViewModel.LAUNCHER_SHORTCUT_SCHEME) { val goalId = intent.getLongExtra(MainViewModel.LC_SHORTCUT_GOAL_ID, -100) if (goalId != -100L) { - navController.navigate(Screens.GoalInfoScreen.withGoalId(goalId.toString())) + navController.navigate(GoalInfoScreen(goalId.toString())) return } if (intent.getBooleanExtra(MainViewModel.LC_SHORTCUT_NEW_GOAL, false)) { - navController.navigate(Screens.InputScreen.route) + navController.navigate(InputScreen) } } } \ No newline at end of file From 25d5a26ff0a7de496a8618c45d548e8d0e32cb5e Mon Sep 17 00:00:00 2001 From: imrannextgeni021 Date: Mon, 14 Oct 2024 12:51:47 +0500 Subject: [PATCH 2/3] Completely migrated to type safe navigation Handled multiple times screen navigation on tap of Home from drawer --- .../com/starry/greenstash/MainViewModel.kt | 12 ++-- .../greenstash/ui/navigation/DrawerScreens.kt | 16 +++-- .../greenstash/ui/navigation/NavGraph.kt | 30 ++++------ .../greenstash/ui/navigation/ScreenArgs.kt | 20 ------- .../greenstash/ui/navigation/Screens.kt | 59 ++++++++----------- .../screens/dwscreen/composables/DWScreen.kt | 8 +-- .../screens/home/composables/GoalLazyItem.kt | 1 - .../ui/screens/home/composables/HomeDrawer.kt | 8 ++- .../ui/screens/home/composables/HomeScreen.kt | 1 - .../screens/input/composables/InputScreen.kt | 4 +- .../greenstash/ui/screens/main/MainScreen.kt | 3 +- .../ui/screens/other/CongratsScreen.kt | 8 +-- .../settings/composables/SettingsScreen.kt | 10 ++-- .../welcome/composables/WelcomeScreen.kt | 2 +- 14 files changed, 76 insertions(+), 106 deletions(-) delete mode 100644 app/src/main/java/com/starry/greenstash/ui/navigation/ScreenArgs.kt diff --git a/app/src/main/java/com/starry/greenstash/MainViewModel.kt b/app/src/main/java/com/starry/greenstash/MainViewModel.kt index f415b340..6d745093 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 7ce7e06a..9de280c7 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 2ce7ed24..f7de861c 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 d15dbd77..00000000 --- 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 b7966614..d8c07685 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 10e32bdb..dac03079 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 0d8e7907..6e050ad1 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 21a029e2..1f9e2cca 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 130910c8..de0cdac5 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 144aa0a7..6d04fdbd 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 75a3475e..6db4f3cb 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 c3111a88..7482de91 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 82b3a310..409de092 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 8a1327c1..97c10982 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) From 15385466f4d3dbe43b414f0fae9d20a781ec779b Mon Sep 17 00:00:00 2001 From: imrannextgeni021 Date: Tue, 15 Oct 2024 01:53:35 +0500 Subject: [PATCH 3/3] Removed Any from NavGraph and implemented type safety and static type checking at compile time. Removed Gradle migration to type-safe navigation comment line. Added back Header Comment in NormalScreens file. --- app/build.gradle | 1 - .../com/starry/greenstash/MainViewModel.kt | 11 ++-- .../greenstash/ui/navigation/DrawerScreens.kt | 10 +-- .../greenstash/ui/navigation/NavGraph.kt | 24 ++++---- .../greenstash/ui/navigation/NormalScreens.kt | 61 +++++++++++++++++++ .../starry/greenstash/ui/navigation/Screen.kt | 4 ++ .../greenstash/ui/navigation/Screens.kt | 36 ----------- .../screens/dwscreen/composables/DWScreen.kt | 4 +- .../screens/home/composables/GoalLazyItem.kt | 20 +++--- .../ui/screens/home/composables/HomeScreen.kt | 4 +- .../greenstash/ui/screens/main/MainScreen.kt | 10 +-- .../settings/composables/SettingsScreen.kt | 10 ++- 12 files changed, 110 insertions(+), 85 deletions(-) create mode 100644 app/src/main/java/com/starry/greenstash/ui/navigation/NormalScreens.kt create mode 100644 app/src/main/java/com/starry/greenstash/ui/navigation/Screen.kt delete mode 100644 app/src/main/java/com/starry/greenstash/ui/navigation/Screens.kt diff --git a/app/build.gradle b/app/build.gradle index 4580e8bb..bf271b0b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -91,7 +91,6 @@ dependencies { implementation 'androidx.activity:activity-compose:1.9.2' implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.8.6" implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.8.6" - // TODO: Needs migration to type-safe navigation in v2.8.x implementation "androidx.navigation:navigation-compose:2.8.2" // Jetpack compose. implementation "androidx.compose.ui:ui" diff --git a/app/src/main/java/com/starry/greenstash/MainViewModel.kt b/app/src/main/java/com/starry/greenstash/MainViewModel.kt index 6d745093..b1b7124d 100644 --- a/app/src/main/java/com/starry/greenstash/MainViewModel.kt +++ b/app/src/main/java/com/starry/greenstash/MainViewModel.kt @@ -40,8 +40,9 @@ import androidx.lifecycle.viewModelScope 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.NormalScreens import com.starry.greenstash.ui.navigation.DrawerScreens -import com.starry.greenstash.ui.navigation.WelcomeScreen +import com.starry.greenstash.ui.navigation.Screen import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay @@ -66,9 +67,9 @@ class MainViewModel @Inject constructor( private val _isLoading: MutableState = mutableStateOf(true) val isLoading: State = _isLoading - private val _startDestination: MutableState = - mutableStateOf(WelcomeScreen) - val startDestination: State = _startDestination + private val _startDestination: MutableState = + mutableStateOf(NormalScreens.WelcomeScreen) + val startDestination: State = _startDestination companion object { // Must be same as the one in AndroidManifest.xml @@ -87,7 +88,7 @@ class MainViewModel @Inject constructor( if (completed) { _startDestination.value = DrawerScreens.Home } else { - _startDestination.value = WelcomeScreen + _startDestination.value = NormalScreens.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 9de280c7..3517c3c8 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 @@ -29,26 +29,26 @@ import com.starry.greenstash.R import kotlinx.serialization.Serializable @Serializable -sealed class DrawerScreens( val nameResId: Int, val iconResId: Int) { +sealed class DrawerScreens(val nameResId: Int, val iconResId: Int) : Screen() { companion object { fun getAllItems() = listOf(Home, Archive, Backups, Settings) } @Serializable - data object Home : DrawerScreens( R.string.drawer_home, R.drawable.ic_nav_home) + data object Home : DrawerScreens(R.string.drawer_home, R.drawable.ic_nav_home) @Serializable data object Archive : - DrawerScreens( R.string.drawer_archive, R.drawable.ic_nav_archive) + DrawerScreens(R.string.drawer_archive, R.drawable.ic_nav_archive) @Serializable data object Backups : - DrawerScreens( R.string.drawer_backup, R.drawable.ic_nav_backups) + DrawerScreens(R.string.drawer_backup, R.drawable.ic_nav_backups) @Serializable data object Settings : - DrawerScreens( 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 f7de861c..84564e57 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,7 +50,7 @@ import com.starry.greenstash.ui.screens.welcome.composables.WelcomeScreen @Composable fun NavGraph( navController: NavHostController, - startDestination: Any + startDestination: Screen ) { NavHost( @@ -60,7 +60,7 @@ fun NavGraph( ) { /** Welcome Screen */ - composable( + composable( exitTransition = { exitTransition() }, popEnterTransition = { popEnterTransition() }, ) { @@ -78,13 +78,13 @@ fun NavGraph( } /** Deposit Withdraw Screen */ - composable( + composable( enterTransition = { enterTransition() }, exitTransition = { exitTransition() }, popEnterTransition = { popEnterTransition() }, popExitTransition = { popExitTransition() } ) { backStackEntry -> - val args = backStackEntry.toRoute() + val args = backStackEntry.toRoute() DWScreen( goalId = args.goalId, transactionTypeName = args.transactionType, @@ -93,29 +93,29 @@ fun NavGraph( } /** Goal Info Screen */ - composable( + composable( enterTransition = { enterTransition() }, exitTransition = { exitTransition() }, popEnterTransition = { popEnterTransition() }, popExitTransition = { popExitTransition() } ) { backStackEntry -> - val args = backStackEntry.toRoute() + val args = backStackEntry.toRoute() GoalInfoScreen(goalId = args.goalId, navController = navController) } /** Input Screen */ - composable( + composable( enterTransition = { enterTransition() }, exitTransition = { exitTransition() }, popEnterTransition = { popEnterTransition() }, popExitTransition = { popExitTransition() } ) { backStackEntry -> - val args = backStackEntry.toRoute() + val args = backStackEntry.toRoute() InputScreen(editGoalId = args.goalId, navController = navController) } /** Goal Achieved Screen */ - composable( + composable( enterTransition = { enterTransition() }, exitTransition = { exitTransition() }, popEnterTransition = { popEnterTransition() }, @@ -155,7 +155,7 @@ fun NavGraph( } /** Goal Ui Settings Screen */ - composable( + composable( enterTransition = { enterTransition() }, popExitTransition = { popExitTransition() }, ) { @@ -163,7 +163,7 @@ fun NavGraph( } /** Open Source Licenses Screen */ - composable( + composable( enterTransition = { enterTransition() }, popExitTransition = { popExitTransition() }, ) { @@ -171,7 +171,7 @@ fun NavGraph( } /** About Screen */ - composable( + composable( enterTransition = { enterTransition() }, popExitTransition = { popExitTransition() }, ) { diff --git a/app/src/main/java/com/starry/greenstash/ui/navigation/NormalScreens.kt b/app/src/main/java/com/starry/greenstash/ui/navigation/NormalScreens.kt new file mode 100644 index 00000000..839a2f98 --- /dev/null +++ b/app/src/main/java/com/starry/greenstash/ui/navigation/NormalScreens.kt @@ -0,0 +1,61 @@ +/** + * 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 + +sealed class NormalScreens : Screen() { + + @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 + data object AboutScreen + + @Serializable + data object OSLScreen + + @Serializable + data object GoalCardStyleScreen + + + // Goal Achieved Screen + @Serializable + data object CongratsScreen + + // Welcome / Onboarding Screen + @Serializable + data object WelcomeScreen : NormalScreens() +} + + diff --git a/app/src/main/java/com/starry/greenstash/ui/navigation/Screen.kt b/app/src/main/java/com/starry/greenstash/ui/navigation/Screen.kt new file mode 100644 index 00000000..3a4a2e8c --- /dev/null +++ b/app/src/main/java/com/starry/greenstash/ui/navigation/Screen.kt @@ -0,0 +1,4 @@ +package com.starry.greenstash.ui.navigation + + +open class Screen \ No newline at end of file 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 deleted file mode 100644 index d8c07685..00000000 --- a/app/src/main/java/com/starry/greenstash/ui/navigation/Screens.kt +++ /dev/null @@ -1,36 +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) - -@Serializable -object AboutScreen - -@Serializable -object OSLScreen - -@Serializable -object GoalCardStyleScreen - - -// Goal Achieved Screen -@Serializable -object CongratsScreen - -// Welcome / Onboarding Screen -@Serializable -object WelcomeScreen - - - 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 dac03079..06c962d3 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,7 +84,7 @@ 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.NormalScreens import com.starry.greenstash.ui.navigation.DrawerScreens import com.starry.greenstash.ui.screens.dwscreen.DWViewModel import com.starry.greenstash.ui.theme.greenstashFont @@ -208,7 +208,7 @@ fun DWScreen(goalId: String, transactionTypeName: String, navController: NavCont showTransactionAddedAnim.value = true delay(1100) withContext(Dispatchers.Main) { - navController.navigate(CongratsScreen) + navController.navigate(NormalScreens.CongratsScreen) } } }, onComplete = { 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 6e050ad1..f3ca2d74 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 @@ -43,9 +43,7 @@ import com.starry.greenstash.MainActivity import com.starry.greenstash.R import com.starry.greenstash.database.core.GoalWithTransactions 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.NormalScreens import com.starry.greenstash.ui.screens.home.GoalCardStyle import com.starry.greenstash.ui.screens.home.HomeViewModel import com.starry.greenstash.utils.Constants @@ -109,7 +107,7 @@ fun GoalLazyColumnItem( } } else { navController.navigate( - DWScreen( + NormalScreens.DWScreen( goalId = item.goal.goalId.toString(), transactionType = TransactionType.Deposit.name ) @@ -124,7 +122,7 @@ fun GoalLazyColumnItem( } } else { navController.navigate( - DWScreen( + NormalScreens.DWScreen( goalId = item.goal.goalId.toString(), transactionType = TransactionType.Withdraw.name ) @@ -134,7 +132,7 @@ fun GoalLazyColumnItem( onInfoClicked = { localView.weakHapticFeedback() navController.navigate( - GoalInfoScreen( + NormalScreens.GoalInfoScreen( goalId = item.goal.goalId.toString() ) ) @@ -142,7 +140,7 @@ fun GoalLazyColumnItem( onEditClicked = { localView.weakHapticFeedback() navController.navigate( - InputScreen( + NormalScreens.InputScreen( goalId = item.goal.goalId.toString() ) ) @@ -193,7 +191,7 @@ fun GoalLazyColumnItem( } } else { navController.navigate( - DWScreen( + NormalScreens.DWScreen( goalId = item.goal.goalId.toString(), transactionType = TransactionType.Deposit.name ) @@ -208,7 +206,7 @@ fun GoalLazyColumnItem( } } else { navController.navigate( - DWScreen( + NormalScreens.DWScreen( goalId = item.goal.goalId.toString(), transactionType = TransactionType.Withdraw.name ) @@ -218,7 +216,7 @@ fun GoalLazyColumnItem( onInfoClicked = { localView.weakHapticFeedback() navController.navigate( - GoalInfoScreen( + NormalScreens.GoalInfoScreen( goalId = item.goal.goalId.toString() ) ) @@ -226,7 +224,7 @@ fun GoalLazyColumnItem( onEditClicked = { localView.weakHapticFeedback() navController.navigate( - InputScreen( + NormalScreens.InputScreen( goalId = item.goal.goalId.toString() ) ) 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 de0cdac5..9b6a0c10 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 @@ -102,7 +102,7 @@ import com.psoffritti.taptargetcompose.TextDefinition 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.NormalScreens import com.starry.greenstash.ui.screens.home.FilterField import com.starry.greenstash.ui.screens.home.FilterSortType import com.starry.greenstash.ui.screens.home.HomeViewModel @@ -418,7 +418,7 @@ private fun HomeExtendedFAB( modifier = modifier.padding(end = 10.dp, bottom = 12.dp), onClick = { view.weakHapticFeedback() - navController.navigate(InputScreen()) + navController.navigate(NormalScreens.InputScreen()) }, elevation = FloatingActionButtonDefaults.elevation(8.dp) ) { 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 6db4f3cb..d6573422 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 @@ -40,9 +40,9 @@ import androidx.navigation.NavController import androidx.navigation.compose.rememberNavController import com.starry.greenstash.MainActivity 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.NormalScreens import com.starry.greenstash.ui.navigation.NavGraph +import com.starry.greenstash.ui.navigation.Screen import com.starry.greenstash.ui.screens.other.AppLockedScreen import com.starry.greenstash.ui.screens.settings.ThemeMode import com.starry.greenstash.ui.theme.AdjustEdgeToEdge @@ -55,7 +55,7 @@ import com.starry.greenstash.ui.theme.AdjustEdgeToEdge fun MainScreen( activity: MainActivity, showAppContents: Boolean, - startDestination: Any, + startDestination: Screen, currentThemeMode: ThemeMode, onAuthRequest: () -> Unit, ) { @@ -99,11 +99,11 @@ private fun HandleShortcutIntent(intent: Intent, navController: NavController) { if (data != null && data.scheme == MainViewModel.LAUNCHER_SHORTCUT_SCHEME) { val goalId = intent.getLongExtra(MainViewModel.LC_SHORTCUT_GOAL_ID, -100) if (goalId != -100L) { - navController.navigate(GoalInfoScreen(goalId.toString())) + navController.navigate(NormalScreens.GoalInfoScreen(goalId.toString())) return } if (intent.getBooleanExtra(MainViewModel.LC_SHORTCUT_NEW_GOAL, false)) { - navController.navigate(InputScreen) + navController.navigate(NormalScreens.InputScreen) } } } \ No newline at end of file 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 409de092..753819a1 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,9 +93,7 @@ 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.AboutScreen -import com.starry.greenstash.ui.navigation.GoalCardStyleScreen -import com.starry.greenstash.ui.navigation.OSLScreen +import com.starry.greenstash.ui.navigation.NormalScreens import com.starry.greenstash.ui.screens.home.GoalCardStyle import com.starry.greenstash.ui.screens.settings.DateStyle import com.starry.greenstash.ui.screens.settings.SettingsViewModel @@ -233,7 +231,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(GoalCardStyleScreen) }) + onClick = { navController.navigate(NormalScreens.GoalCardStyleScreen) }) if (showThemeSheet.value) { ThemePickerDialog( @@ -555,11 +553,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(OSLScreen) }) + onClick = { navController.navigate(NormalScreens.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(AboutScreen) }) + onClick = { navController.navigate(NormalScreens.AboutScreen) }) } Spacer(modifier = Modifier.height(2.dp)) // Last item padding. }