Skip to content

Commit

Permalink
feat: splash 화면 추가 #56
Browse files Browse the repository at this point in the history
  • Loading branch information
easyhz committed Aug 12, 2024
1 parent 267413e commit 89dc7d6
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.easyhz.noffice.domain.home.usecase.splash

import com.easyhz.noffice.core.common.base.BaseUseCase
import com.easyhz.noffice.core.model.splash.EnterScreenType
import com.easyhz.noffice.data.auth.repository.token.TokenRepository
import com.easyhz.noffice.data.member.repository.user.UserRepository
import javax.inject.Inject

class GetSplashInfoUseCase @Inject constructor(
private val tokenRepository: TokenRepository,
private val userRepository: UserRepository
): BaseUseCase<Unit, EnterScreenType>() {
override suspend fun invoke(param: Unit): Result<EnterScreenType> = runCatching {
userRepository.getIsFirstRun().getOrElse {
return@runCatching EnterScreenType.ONBOARDING
}

tokenRepository.getAccessToken().getOrElse {
return@runCatching EnterScreenType.LOGIN
}

return Result.success(EnterScreenType.HOME)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.easyhz.noffice.feature.home.contract.splash

import com.easyhz.noffice.core.common.base.UiIntent

sealed class SplashIntent: UiIntent()
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.easyhz.noffice.feature.home.contract.splash

import com.easyhz.noffice.core.common.base.UiSideEffect

sealed class SplashSideEffect: UiSideEffect() {
data object NavigateToHome: SplashSideEffect()
data object NavigateToOnboarding: SplashSideEffect()
data object NavigateToLogin: SplashSideEffect()
data object NavigateToDeepLink: SplashSideEffect()

// FIXME 약관 창 가야 하는지 질문
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.easyhz.noffice.feature.home.contract.splash

import com.easyhz.noffice.core.common.base.UiState

data object SplashState : UiState()
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.easyhz.noffice.feature.home.screen.splash

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.hilt.navigation.compose.hiltViewModel
import com.easyhz.noffice.core.common.util.collectInSideEffectWithLifecycle
import com.easyhz.noffice.core.design_system.R
import com.easyhz.noffice.core.design_system.component.scaffold.NofficeBasicScaffold
import com.easyhz.noffice.core.design_system.theme.Grey900
import com.easyhz.noffice.feature.home.contract.splash.SplashSideEffect

@Composable
fun SplashScreen(
modifier: Modifier = Modifier,
viewModel: SplashViewModel = hiltViewModel()
) {
NofficeBasicScaffold(
containerColor = Grey900,
statusBarColor = Grey900,
navigationBarColor = Grey900,
) { _ ->
Box(
modifier = modifier
.fillMaxSize()
.background(Grey900),
contentAlignment = Alignment.Center
) {
Image(
painter = painterResource(id = R.drawable.ic_splash_logo),
contentDescription = "splash"
)
}
}

viewModel.sideEffect.collectInSideEffectWithLifecycle { sideEffect ->
when(sideEffect) {
is SplashSideEffect.NavigateToOnboarding -> { }
is SplashSideEffect.NavigateToLogin -> { }
is SplashSideEffect.NavigateToHome -> { }
is SplashSideEffect.NavigateToDeepLink -> { }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.easyhz.noffice.feature.home.screen.splash

import androidx.lifecycle.viewModelScope
import com.easyhz.noffice.core.common.base.BaseViewModel
import com.easyhz.noffice.core.model.splash.EnterScreenType
import com.easyhz.noffice.domain.home.usecase.splash.GetSplashInfoUseCase
import com.easyhz.noffice.feature.home.contract.splash.SplashIntent
import com.easyhz.noffice.feature.home.contract.splash.SplashSideEffect
import com.easyhz.noffice.feature.home.contract.splash.SplashState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class SplashViewModel @Inject constructor(
private val getSplashInfoUseCase: GetSplashInfoUseCase
):BaseViewModel<SplashState, SplashIntent, SplashSideEffect>(
initialState = SplashState
) {
override fun handleIntent(intent: SplashIntent) { }

init {
getSplashInfo()
}

private fun getSplashInfo() = viewModelScope.launch {
getSplashInfoUseCase.invoke(Unit).onSuccess {
when(it) {
EnterScreenType.ONBOARDING -> { navigateToOnboarding() }
EnterScreenType.LOGIN -> { navigateToLogin() }
EnterScreenType.HOME -> { navigateToHome() }
}
}
}

private fun navigateToOnboarding() {
postSideEffect { SplashSideEffect.NavigateToOnboarding }
}

private fun navigateToLogin() {
postSideEffect { SplashSideEffect.NavigateToLogin }
}

private fun navigateToHome() {
postSideEffect { SplashSideEffect.NavigateToHome }
}

private fun navigateToDeepLink() {
postSideEffect { SplashSideEffect.NavigateToDeepLink }
}
}

0 comments on commit 89dc7d6

Please sign in to comment.