-
Notifications
You must be signed in to change notification settings - Fork 0
[Modify] 스플래시에서 uiState와 uiEvent를 활용해서 분기처리하기 #284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
aadce8e
delete: 스플래시 2초 지연 없앰. uiState에 따라 분기처리
HI-JIN2 9d653e0
modify: intro에서 토큰 존재 여부 / 토큰 유효 여부에 따라 분기처리
HI-JIN2 6d2d257
chore: TokenInterceptor에서 불필요해 보이는 곳 주석처리
HI-JIN2 40c44c8
chore: 네이밍 수정
HI-JIN2 0b3eba8
chore: UiEvent, UiState (cherry pick)
HI-JIN2 520fefd
chore: NoValidToken은 Error
HI-JIN2 babbf1c
chore: 404 500 로그 살려
HI-JIN2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/eatssu/android/domain/usecase/auth/GetIsAccessTokenValidUseCase.kt
This file contains hidden or 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,13 @@ | ||
| package com.eatssu.android.domain.usecase.auth | ||
|
|
||
| import com.eatssu.android.data.dto.response.BaseResponse | ||
| import com.eatssu.android.domain.repository.UserRepository | ||
| import kotlinx.coroutines.flow.Flow | ||
| import javax.inject.Inject | ||
|
|
||
| class GetIsAccessTokenValidUseCase @Inject constructor( | ||
| private val userRepository: UserRepository, | ||
| ) { | ||
| suspend operator fun invoke(): Flow<BaseResponse<Boolean>> = | ||
| userRepository.checkUserNameValidation("qkqh") //todo api 만들어지면 수정 | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/eatssu/android/presentation/UiEvent.kt
This file contains hidden or 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,10 @@ | ||
| package com.eatssu.android.presentation | ||
|
|
||
|
|
||
| /** | ||
| * 각 Screen에 공통적인 이벤트 타입입니다. | ||
| * 이벤트 타입을 추가하고 싶다면 UiEvent를 상속받아 사용하세요. | ||
| */ | ||
| interface UiEvent { | ||
| data class ShowToast(val message: String) : UiEvent | ||
| } |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/eatssu/android/presentation/UiState.kt
This file contains hidden or 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,13 @@ | ||
| package com.eatssu.android.presentation | ||
|
|
||
| sealed interface UiState<out T> { | ||
| object Init : UiState<Nothing> | ||
|
|
||
| object Loading : UiState<Nothing> | ||
|
|
||
| data class Success<out T>( | ||
| val data: T? = null, | ||
| ) : UiState<T> | ||
|
|
||
| object Error : UiState<Nothing> | ||
| } |
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -3,41 +3,70 @@ package com.eatssu.android.presentation.login | |
| import androidx.lifecycle.ViewModel | ||
| import androidx.lifecycle.viewModelScope | ||
| import com.eatssu.android.domain.usecase.auth.GetAccessTokenUseCase | ||
| import com.eatssu.android.domain.usecase.auth.GetIsAccessTokenValidUseCase | ||
| import com.eatssu.android.presentation.UiEvent | ||
| import com.eatssu.android.presentation.UiState | ||
| import dagger.hilt.android.lifecycle.HiltViewModel | ||
| import kotlinx.coroutines.flow.MutableSharedFlow | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import kotlinx.coroutines.flow.SharedFlow | ||
| import kotlinx.coroutines.flow.StateFlow | ||
| import kotlinx.coroutines.flow.asStateFlow | ||
| import kotlinx.coroutines.flow.update | ||
| import kotlinx.coroutines.launch | ||
| import javax.inject.Inject | ||
|
|
||
| @HiltViewModel | ||
| class IntroViewModel @Inject constructor( | ||
| private val getAccessTokenUseCase: GetAccessTokenUseCase | ||
| private val getAccessTokenUseCase: GetAccessTokenUseCase, | ||
| private val getIsAccessTokenValidUseCase: GetIsAccessTokenValidUseCase | ||
| ) : ViewModel() { | ||
|
|
||
| private val _uiState: MutableStateFlow<IntroState> = MutableStateFlow(IntroState()) | ||
| val uiState: StateFlow<IntroState> = _uiState.asStateFlow() | ||
| private val _uiState: MutableStateFlow<UiState<IntroState>> = MutableStateFlow(UiState.Init) | ||
| val uiState: StateFlow<UiState<IntroState>> = _uiState.asStateFlow() | ||
|
|
||
| private val _uiEvent = MutableSharedFlow<UiEvent>() | ||
| val uiEvent: SharedFlow<UiEvent> = _uiEvent | ||
|
|
||
| init { | ||
| autoLogin() | ||
| } | ||
|
|
||
| fun autoLogin() { | ||
| private fun autoLogin() { | ||
| viewModelScope.launch { | ||
| if (getAccessTokenUseCase().isEmpty()) { | ||
| _uiState.update { it.copy(isAutoLogined = false) } | ||
| } else { | ||
| _uiState.update { it.copy(isAutoLogined = true) } | ||
| _uiState.value = UiState.Loading | ||
|
|
||
| try { | ||
| // 토큰 존재 여부 확인 | ||
| if (getAccessTokenUseCase().isEmpty()) { | ||
| _uiState.value = UiState.Error | ||
| _uiEvent.emit(UiEvent.ShowToast("로그인이 필요합니다")) | ||
| return@launch | ||
| } | ||
|
|
||
| checkValid() | ||
|
|
||
| } catch (e: Exception) { | ||
| _uiState.value = UiState.Error | ||
| _uiEvent.emit(UiEvent.ShowToast("오류가 발생했습니다: ${e.message}")) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun checkValid() { | ||
| viewModelScope.launch { | ||
| getIsAccessTokenValidUseCase() | ||
| .collect { | ||
| if (it.result == true) { //토큰이 있고 유효함 | ||
| _uiState.value = UiState.Success(IntroState.ValidToken) | ||
| } else { //토큰이 있어도 유효하지 않음 | ||
| _uiState.value = UiState.Error | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 여기 Error 로 두는 것 좋은 것 같아요~ |
||
| _uiEvent.emit(UiEvent.ShowToast("로그인이 필요합니다")) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| data class IntroState( | ||
| var toastMessage: String = "", | ||
| var loading: Boolean = true, | ||
| var error: Boolean = false, | ||
| var isAutoLogined: Boolean = false, | ||
| ) | ||
| sealed class IntroState { | ||
| object ValidToken : IntroState() | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use-case currently calls 'checkUserNameValidation', which does not align with token validation. Update the repository method to reflect token validation once the proper API is available.