diff --git a/NavigationCodelab/app/src/main/java/com/example/compose/rally/RallyActivity.kt b/NavigationCodelab/app/src/main/java/com/example/compose/rally/RallyActivity.kt index c0c94c4..e46c310 100644 --- a/NavigationCodelab/app/src/main/java/com/example/compose/rally/RallyActivity.kt +++ b/NavigationCodelab/app/src/main/java/com/example/compose/rally/RallyActivity.kt @@ -31,6 +31,7 @@ import androidx.navigation.compose.composable import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController import com.example.compose.rally.ui.accounts.AccountsScreen +import com.example.compose.rally.ui.accounts.SingleAccountScreen import com.example.compose.rally.ui.bills.BillsScreen import com.example.compose.rally.ui.components.RallyTabRow import com.example.compose.rally.ui.overview.OverviewScreen @@ -82,15 +83,30 @@ fun RallyApp() { }, onClickSeeAllBills = { navController.navigateSingleTopTo(Bills.route) + }, + onAccountClick = { accountType -> + navController.navigateToSingAccount(accountType) } ) } composable(route = Accounts.route) { - AccountsScreen() + AccountsScreen( + onAccountClick = { accountType -> + navController.navigateToSingAccount(accountType) + } + ) } composable(route = Bills.route) { BillsScreen() } + composable( + route = SingleAccount.routeWithArgs, + arguments = SingleAccount.arguments + ) { navBackStackEntry -> + val accountType = + navBackStackEntry.arguments?.getString(SingleAccount.accountTypeArg) + SingleAccountScreen(accountType = accountType) + } } } } @@ -106,4 +122,8 @@ fun NavHostController.navigateSingleTopTo(route: String) = } launchSingleTop = true restoreState = true - } \ No newline at end of file + } + +fun NavHostController.navigateToSingAccount(accountType:String) { + this.navigateSingleTopTo("${SingleAccount.route}/$accountType") +} \ No newline at end of file diff --git a/NavigationCodelab/app/src/main/java/com/example/compose/rally/RallyDestinations.kt b/NavigationCodelab/app/src/main/java/com/example/compose/rally/RallyDestinations.kt index 667553d..ee89eba 100644 --- a/NavigationCodelab/app/src/main/java/com/example/compose/rally/RallyDestinations.kt +++ b/NavigationCodelab/app/src/main/java/com/example/compose/rally/RallyDestinations.kt @@ -21,12 +21,9 @@ import androidx.compose.material.icons.filled.AttachMoney import androidx.compose.material.icons.filled.Money import androidx.compose.material.icons.filled.MoneyOff import androidx.compose.material.icons.filled.PieChart -import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.vector.ImageVector -import com.example.compose.rally.ui.accounts.AccountsScreen -import com.example.compose.rally.ui.accounts.SingleAccountScreen -import com.example.compose.rally.ui.bills.BillsScreen -import com.example.compose.rally.ui.overview.OverviewScreen +import androidx.navigation.NavType +import androidx.navigation.navArgument /** * Contract for information needed on every Rally navigation destination @@ -60,6 +57,10 @@ object SingleAccount : RallyDestination { override val icon = Icons.Filled.Money override val route = "single_account" const val accountTypeArg = "account_type" + val routeWithArgs = "${route}/{${accountTypeArg}}" + val arguments = listOf( + navArgument(accountTypeArg) { type = NavType.StringType } + ) } // Screens to be displayed in the top RallyTabRow