refactor: move NavGraph to navigation package and add auth flow
This commit is contained in:
parent
6c52d6c008
commit
46b65e4b99
|
|
@ -1,37 +0,0 @@
|
||||||
package com.syaroful.agrilinkvocpro.core.route
|
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.navigation.compose.NavHost
|
|
||||||
import androidx.navigation.compose.composable
|
|
||||||
import androidx.navigation.compose.rememberNavController
|
|
||||||
import com.syaroful.agrilinkvocpro.ui.screen.home.HomeScreen
|
|
||||||
import com.syaroful.agrilinkvocpro.ui.screen.home.HomeViewModel
|
|
||||||
import com.syaroful.agrilinkvocpro.ui.screen.profile.ProfileScreen
|
|
||||||
|
|
||||||
sealed class Screen(val route: String) {
|
|
||||||
object Home : Screen("home")
|
|
||||||
object Profile : Screen("profile")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun SetupNavigation(
|
|
||||||
homeViewModel: HomeViewModel,
|
|
||||||
onLaunchFeature: (String) -> Unit
|
|
||||||
) {
|
|
||||||
val navController = rememberNavController()
|
|
||||||
NavHost(navController, startDestination = "home") {
|
|
||||||
composable("home") {
|
|
||||||
HomeScreen(
|
|
||||||
navController = navController,
|
|
||||||
onFeatureClick = { moduleName ->
|
|
||||||
homeViewModel.onFeatureClicked(moduleName, onLaunchFeature)
|
|
||||||
},
|
|
||||||
dialogState = homeViewModel.currentModuleToDownload,
|
|
||||||
homeViewModel = homeViewModel
|
|
||||||
)
|
|
||||||
}
|
|
||||||
composable("profile"){
|
|
||||||
ProfileScreen()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,90 @@
|
||||||
|
package com.syaroful.agrilinkvocpro.navigation
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.navigation.compose.NavHost
|
||||||
|
import androidx.navigation.compose.composable
|
||||||
|
import androidx.navigation.compose.rememberNavController
|
||||||
|
import com.syaroful.agrilinkvocpro.data.UserPreferences
|
||||||
|
import com.syaroful.agrilinkvocpro.ui.screen.detail.DetailScreen
|
||||||
|
import com.syaroful.agrilinkvocpro.ui.screen.home.DynamicModuleViewModel
|
||||||
|
import com.syaroful.agrilinkvocpro.ui.screen.home.HomeScreen
|
||||||
|
import com.syaroful.agrilinkvocpro.ui.screen.login.LoginScreen
|
||||||
|
import com.syaroful.agrilinkvocpro.ui.screen.login.LoginViewModel
|
||||||
|
import com.syaroful.agrilinkvocpro.ui.screen.profile.ProfileScreen
|
||||||
|
import com.syaroful.agrilinkvocpro.ui.screen.register.RegisterScreen
|
||||||
|
import com.syaroful.agrilinkvocpro.ui.screen.splash.SplashScreen
|
||||||
|
import org.koin.androidx.compose.koinViewModel
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SetupNavigation(
|
||||||
|
userPreferences: UserPreferences,
|
||||||
|
dynamicModuleViewModel: DynamicModuleViewModel,
|
||||||
|
onLaunchFeature: (String) -> Unit
|
||||||
|
) {
|
||||||
|
|
||||||
|
val loginViewModel: LoginViewModel = koinViewModel()
|
||||||
|
|
||||||
|
val navController = rememberNavController()
|
||||||
|
NavHost(navController, startDestination = "splash") {
|
||||||
|
composable("splash") {
|
||||||
|
SplashScreen(
|
||||||
|
userPreferences = userPreferences,
|
||||||
|
onNavigate = { destination ->
|
||||||
|
navController.navigate(destination) {
|
||||||
|
popUpTo("splash") { inclusive = true }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
composable("login") {
|
||||||
|
LoginScreen(
|
||||||
|
loginViewModel = loginViewModel,
|
||||||
|
onLoginSuccess = {
|
||||||
|
navController.navigate("home") {
|
||||||
|
popUpTo("login") { inclusive = true }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onNavigateToRegister = {
|
||||||
|
navController.navigate("register") {
|
||||||
|
popUpTo("login") { inclusive = true }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
composable("register") {
|
||||||
|
RegisterScreen(
|
||||||
|
onLoginSuccess = {
|
||||||
|
navController.navigate("login") {
|
||||||
|
popUpTo("login") { inclusive = true }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onNavigateToLogin = {
|
||||||
|
navController.navigate("login") {
|
||||||
|
popUpTo("login") { inclusive = true }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
composable("home") {
|
||||||
|
HomeScreen(
|
||||||
|
navController = navController,
|
||||||
|
onFeatureClick = { moduleName ->
|
||||||
|
dynamicModuleViewModel.onFeatureClicked(moduleName, onLaunchFeature)
|
||||||
|
},
|
||||||
|
dynamicModuleViewModel = dynamicModuleViewModel
|
||||||
|
)
|
||||||
|
}
|
||||||
|
composable("profile") {
|
||||||
|
ProfileScreen(
|
||||||
|
onNavigateToLogin = {
|
||||||
|
navController.navigate("splash") {
|
||||||
|
popUpTo("splash") { inclusive = true }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
composable("detail-screen") {
|
||||||
|
DetailScreen()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user