Skip to content

Commit

Permalink
feat: 앱 실행 데이터 작업 중에 SplashScreen을 계속 보이도록 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
yangsooplus committed Jan 2, 2024
1 parent 60675d5 commit 5f5b40e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.susu.feature.navigator.initialization

enum class InitialRoute {
SIGNUP_VOTE, LOGIN, RECEIVED
}
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
@@ -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, MainContract.MainEffect>(MainContract.MainState.Loading)

0 comments on commit 5f5b40e

Please sign in to comment.