Skip to content

Commit

Permalink
[feature/droidknights#300] Apply type on navigation route
Browse files Browse the repository at this point in the history
  • Loading branch information
l2hyunwoo committed May 30, 2024
1 parent 6e2c53d commit addac41
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import com.droidknights.app.core.navigation.Bookmark
import com.droidknights.app.feature.bookmark.BookmarkRoute

fun NavController.navigateBookmark(navOptions: NavOptions) {
navigate(BookmarkRoute.ROUTE, navOptions)
navigate(Bookmark, navOptions)
}

fun NavGraphBuilder.bookmarkNavGraph(
onShowErrorSnackBar: (throwable: Throwable?) -> Unit,
) {
composable(route = BookmarkRoute.ROUTE) {
composable<Bookmark> {
BookmarkRoute(onShowErrorSnackBar)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@ package com.droidknights.app.feature.contributor.navigation
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import com.droidknights.app.core.navigation.Contributor
import com.droidknights.app.feature.contributor.ContributorRoute

fun NavController.navigateContributor() {
this.navigate(ContributorRoute.ROUTE)
this.navigate(Contributor)
}

fun NavGraphBuilder.contributorNavGraph(
onBackClick: () -> Unit,
onShowErrorSnackBar: (throwable: Throwable?) -> Unit,
) {
composable(route = ContributorRoute.ROUTE) {
composable<Contributor> {
ContributorRoute(
onBackClick = onBackClick,
onShowErrorSnackBar = onShowErrorSnackBar
)
}
}

object ContributorRoute {

const val ROUTE = "contributor"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import com.droidknights.app.core.navigation.Home
import com.droidknights.app.feature.home.HomeRoute

fun NavController.navigateHome(navOptions: NavOptions) {
navigate(HomeRoute.ROUTE, navOptions)
navigate(Home, navOptions)
}

fun NavGraphBuilder.homeNavGraph(
Expand All @@ -17,7 +18,7 @@ fun NavGraphBuilder.homeNavGraph(
onContributorClick: () -> Unit,
onShowErrorSnackBar: (throwable: Throwable?) -> Unit,
) {
composable(route = HomeRoute.ROUTE) {
composable<Home> {
HomeRoute(padding, onSessionClick, onContributorClick, onShowErrorSnackBar)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,40 @@ package com.droidknights.app.feature.session.navigation

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import androidx.navigation.toRoute
import com.droidknights.app.core.model.Session
import com.droidknights.app.core.navigation.SessionDetail
import com.droidknights.app.feature.session.SessionDetailScreen
import com.droidknights.app.feature.session.SessionScreen
import com.droidknights.app.core.navigation.Session as SessionRoute

fun NavController.navigateSession() {
navigate(SessionRoute.ROUTE)
navigate(SessionRoute)
}

fun NavController.navigateSessionDetail(sessionId: String) {
navigate(SessionRoute.detailRoute(sessionId))
navigate(SessionDetail(sessionId))
}

fun NavGraphBuilder.sessionNavGraph(
onBackClick: () -> Unit,
onSessionClick: (Session) -> Unit,
onShowErrorSnackBar: (throwable: Throwable?) -> Unit,
) {
composable(SessionRoute.ROUTE) {
composable<SessionRoute> {
SessionScreen(
onBackClick = onBackClick,
onSessionClick = onSessionClick,
onShowErrorSnackBar = onShowErrorSnackBar
)
}

composable(
route = SessionRoute.detailRoute("{id}"),
arguments = listOf(
navArgument("id") {
type = NavType.StringType
}
)
) { navBackStackEntry ->
val sessionId = navBackStackEntry.arguments?.getString("id") ?: ""
composable<SessionDetail> { navBackStackEntry ->
val sessionId = navBackStackEntry.toRoute<SessionDetail>().sessionId
SessionDetailScreen(
sessionId = sessionId,
onBackClick = onBackClick
)
}
}

object SessionRoute {

const val ROUTE: String = "session"

fun detailRoute(sessionId: String): String = "$ROUTE/$sessionId"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import com.droidknights.app.core.navigation.Setting
import com.droidknights.app.feature.setting.SettingScreen

fun NavController.navigateSetting(navOptions: NavOptions) {
navigate(SettingRoute.ROUTE_SETTING, navOptions)
navigate(Setting, navOptions)
}

fun NavGraphBuilder.settingNavGraph(
padding: PaddingValues,
onChangeDarkTheme: (Boolean) -> Unit
) {
composable(route = SettingRoute.ROUTE_SETTING) {
composable<Setting> {
SettingScreen(padding, onChangeDarkTheme)
}
}
Expand Down

0 comments on commit addac41

Please sign in to comment.