-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
.../home/src/main/java/com/easyhz/noffice/domain/home/usecase/splash/GetSplashInfoUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
feature/home/src/main/java/com/easyhz/noffice/feature/home/contract/splash/SplashIntent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
12 changes: 12 additions & 0 deletions
12
...re/home/src/main/java/com/easyhz/noffice/feature/home/contract/splash/SplashSideEffect.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 약관 창 가야 하는지 질문 | ||
} |
5 changes: 5 additions & 0 deletions
5
feature/home/src/main/java/com/easyhz/noffice/feature/home/contract/splash/SplashState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
49 changes: 49 additions & 0 deletions
49
feature/home/src/main/java/com/easyhz/noffice/feature/home/screen/splash/SplashScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -> { } | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
feature/home/src/main/java/com/easyhz/noffice/feature/home/screen/splash/SplashViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} | ||
} |