Prechádzať zdrojové kódy

Navigation class added

minhaj 1 mesiac pred
rodič
commit
bb9bd94bce

+ 0 - 14
app/src/main/java/com/fastest/pass/MainActivity.kt

@@ -1,23 +1,9 @@
 package com.fastest.pass
 
 import android.os.Bundle
-import android.view.View
-import androidx.activity.ComponentActivity
-import androidx.activity.compose.setContent
-import androidx.activity.enableEdgeToEdge
-import androidx.compose.foundation.layout.fillMaxSize
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.remember
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.tooling.preview.Preview
-import androidx.compose.ui.viewinterop.AndroidView
 import androidx.fragment.app.FragmentActivity
-import androidx.fragment.app.FragmentContainerView
 import androidx.navigation.NavController
-import androidx.navigation.compose.rememberNavController
 import androidx.navigation.fragment.NavHostFragment
-import com.fastest.pass.splash.presentation.components.SplashScreen
-import com.fastest.pass.ui.theme.FastestPassTheme
 import dagger.hilt.android.AndroidEntryPoint
 
 @AndroidEntryPoint

+ 20 - 0
app/src/main/java/com/fastest/pass/splash/di/SplashModule.kt

@@ -0,0 +1,20 @@
+package com.fastest.pass.splash.di
+
+import com.fastest.pass.splash.utils.SplashNavigation
+import dagger.Module
+import dagger.Provides
+import dagger.hilt.InstallIn
+import dagger.hilt.components.SingletonComponent
+import javax.inject.Singleton
+
+@Module
+@InstallIn(SingletonComponent::class)
+object SplashModule {
+
+    @Provides
+    @Singleton
+    fun provideNavigation(): SplashNavigation {
+        return SplashNavigation()
+    }
+
+}

+ 10 - 0
app/src/main/java/com/fastest/pass/splash/presentation/ui/SplashFragment.kt

@@ -10,12 +10,22 @@ import com.fastest.pass.splash.presentation.components.SplashScreen
 import com.fastest.pass.splash.presentation.viewmodels.SplashViewModel
 import dagger.hilt.android.AndroidEntryPoint
 import androidx.fragment.app.viewModels
+import com.fastest.pass.splash.utils.SplashNavigation
+import javax.inject.Inject
 
 @AndroidEntryPoint
 class SplashFragment : Fragment() {
 
     val viewModel: SplashViewModel by viewModels()
 
+    @Inject
+    lateinit var navigation : SplashNavigation
+
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+        navigation.navigate(this)
+    }
+
     override fun onCreateView(
         inflater: LayoutInflater, container: ViewGroup?,
         savedInstanceState: Bundle?

+ 10 - 0
app/src/main/java/com/fastest/pass/splash/presentation/viewmodels/SplashViewModel.kt

@@ -5,8 +5,10 @@ import androidx.lifecycle.MutableLiveData
 import androidx.lifecycle.ViewModel
 import androidx.lifecycle.viewModelScope
 import com.fastest.pass.splash.domain.usecase.SplashUseCase
+import com.fastest.pass.splash.utils.SplashRoute
 import dagger.hilt.android.lifecycle.HiltViewModel
 import kotlinx.coroutines.delay
+import kotlinx.coroutines.flow.MutableStateFlow
 import kotlinx.coroutines.launch
 import javax.inject.Inject
 
@@ -16,10 +18,18 @@ class SplashViewModel @Inject constructor(var splashUseCase: SplashUseCase) : Vi
     private val _navigateToLogin = MutableLiveData<Boolean>(false)
     val navigateToLogin: LiveData<Boolean> = _navigateToLogin
 
+
+    private val _router = MutableStateFlow<SplashRoute>(SplashRoute.NoneScreen)
+    val router :MutableStateFlow<SplashRoute> = _router
+
     fun checkAuthentication() {
         viewModelScope.launch {
             delay(2000)
             _navigateToLogin.value = true
         }
     }
+
+    fun navigateTo(splashRoute: SplashRoute) {
+        _router.value = splashRoute
+    }
 }

+ 14 - 0
app/src/main/java/com/fastest/pass/splash/utils/SplashNavigation.kt

@@ -0,0 +1,14 @@
+package com.fastest.pass.splash.utils
+
+import androidx.lifecycle.lifecycleScope
+import com.fastest.pass.splash.presentation.ui.SplashFragment
+
+class SplashNavigation {
+
+    fun navigate(splashFragment: SplashFragment){
+        splashFragment.lifecycleScope.launchWhenStarted {
+//            splashFragment.viewModel.route
+        }
+    }
+
+}

+ 6 - 0
app/src/main/java/com/fastest/pass/splash/utils/SplashRoute.kt

@@ -0,0 +1,6 @@
+package com.fastest.pass.splash.utils
+
+sealed class SplashRoute {
+    object OpenLogin : SplashRoute()
+    object NoneScreen : SplashRoute()
+}