From 5f5b40e7a645b20605f5bd7766b3f84f4a115208 Mon Sep 17 00:00:00 2001 From: yangsooplus Date: Tue, 2 Jan 2024 13:52:58 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=95=B1=20=EC=8B=A4=ED=96=89=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=9E=91=EC=97=85=20=EC=A4=91?= =?UTF-8?q?=EC=97=90=20SplashScreen=EC=9D=84=20=EA=B3=84=EC=86=8D=20?= =?UTF-8?q?=EB=B3=B4=EC=9D=B4=EB=8F=84=EB=A1=9D=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../susu/feature/navigator/MainActivity.kt | 32 +++++++++++++++++++ .../navigator/initialization/InitialRoute.kt | 5 +++ .../navigator/initialization/MainContract.kt | 12 +++++++ .../navigator/initialization/MainViewModel.kt | 8 +++++ 4 files changed, 57 insertions(+) create mode 100644 feature/navigator/src/main/java/com/susu/feature/navigator/initialization/InitialRoute.kt create mode 100644 feature/navigator/src/main/java/com/susu/feature/navigator/initialization/MainContract.kt create mode 100644 feature/navigator/src/main/java/com/susu/feature/navigator/initialization/MainViewModel.kt diff --git a/feature/navigator/src/main/java/com/susu/feature/navigator/MainActivity.kt b/feature/navigator/src/main/java/com/susu/feature/navigator/MainActivity.kt index 9a567788..22afb869 100644 --- a/feature/navigator/src/main/java/com/susu/feature/navigator/MainActivity.kt +++ b/feature/navigator/src/main/java/com/susu/feature/navigator/MainActivity.kt @@ -3,24 +3,56 @@ package com.susu.feature.navigator import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent +import androidx.activity.viewModels import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.WindowInsetsSides import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.only import androidx.compose.foundation.layout.systemBars import androidx.compose.foundation.layout.windowInsetsPadding +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.core.view.WindowCompat +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.lifecycleScope +import androidx.lifecycle.repeatOnLifecycle import com.susu.core.designsystem.theme.SusuTheme +import com.susu.feature.navigator.initialization.MainContract +import com.susu.feature.navigator.initialization.MainViewModel import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.launch @AndroidEntryPoint class MainActivity : ComponentActivity() { + + private val viewModel: MainViewModel by viewModels() + override fun onCreate(savedInstanceState: Bundle?) { val splashScreen = installSplashScreen() super.onCreate(savedInstanceState) + var uiState: MainContract.MainState by mutableStateOf(MainContract.MainState.Loading) + + // Update the uiState + lifecycleScope.launch { + lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) { + viewModel.uiState.collect { + uiState = it + } + } + } + + splashScreen.setKeepOnScreenCondition { + when (uiState) { + MainContract.MainState.Loading -> true + is MainContract.MainState.Initialized -> false + } + } + WindowCompat.setDecorFitsSystemWindows(window, false) setContent { diff --git a/feature/navigator/src/main/java/com/susu/feature/navigator/initialization/InitialRoute.kt b/feature/navigator/src/main/java/com/susu/feature/navigator/initialization/InitialRoute.kt new file mode 100644 index 00000000..99c32429 --- /dev/null +++ b/feature/navigator/src/main/java/com/susu/feature/navigator/initialization/InitialRoute.kt @@ -0,0 +1,5 @@ +package com.susu.feature.navigator.initialization + +enum class InitialRoute { + SIGNUP_VOTE, LOGIN, RECEIVED +} diff --git a/feature/navigator/src/main/java/com/susu/feature/navigator/initialization/MainContract.kt b/feature/navigator/src/main/java/com/susu/feature/navigator/initialization/MainContract.kt new file mode 100644 index 00000000..61c6662b --- /dev/null +++ b/feature/navigator/src/main/java/com/susu/feature/navigator/initialization/MainContract.kt @@ -0,0 +1,12 @@ +package com.susu.feature.navigator.initialization + +import com.susu.core.ui.base.SideEffect +import com.susu.core.ui.base.UiState + +sealed interface MainContract { + object MainEffect : SideEffect + sealed class MainState : UiState { + data object Loading : MainState() + data class Initialized(val initialRoute: InitialRoute) : MainState() + } +} diff --git a/feature/navigator/src/main/java/com/susu/feature/navigator/initialization/MainViewModel.kt b/feature/navigator/src/main/java/com/susu/feature/navigator/initialization/MainViewModel.kt new file mode 100644 index 00000000..2cad8a43 --- /dev/null +++ b/feature/navigator/src/main/java/com/susu/feature/navigator/initialization/MainViewModel.kt @@ -0,0 +1,8 @@ +package com.susu.feature.navigator.initialization + +import com.susu.core.ui.base.BaseViewModel +import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject + +@HiltViewModel +class MainViewModel @Inject constructor() : BaseViewModel(MainContract.MainState.Loading)