diff --git a/presentation/src/main/java/co/orange/presentation/auth/login/LoginActivity.kt b/presentation/src/main/java/co/orange/presentation/auth/login/LoginActivity.kt index 4ea953b3..b2d6d67c 100644 --- a/presentation/src/main/java/co/orange/presentation/auth/login/LoginActivity.kt +++ b/presentation/src/main/java/co/orange/presentation/auth/login/LoginActivity.kt @@ -9,7 +9,6 @@ import co.orange.core.base.BaseActivity import co.orange.core.extension.setOnSingleClickListener import co.orange.core.extension.stringOf import co.orange.core.extension.toast -import co.orange.core.state.UiState import co.orange.presentation.auth.phone.PhoneActivity import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.flow.distinctUntilChanged @@ -27,7 +26,7 @@ class LoginActivity : BaseActivity(R.layout.activity_login initLoginBtnListener() observeAppLoginAvailable() - observeChangeTokenState() + observeChangeTokenResult() } private fun initLoginBtnListener() { @@ -42,19 +41,16 @@ class LoginActivity : BaseActivity(R.layout.activity_login }.launchIn(lifecycleScope) } - private fun observeChangeTokenState() { - viewModel.changeTokenState.flowWithLifecycle(lifecycle).distinctUntilChanged() - .onEach { state -> - when (state) { - is UiState.Success -> { - Intent(this, PhoneActivity::class.java).apply { - startActivity(this) - } - finish() + private fun observeChangeTokenResult() { + viewModel.changeTokenResult.flowWithLifecycle(lifecycle).distinctUntilChanged() + .onEach { isSuccess -> + if (isSuccess) { + Intent(this, PhoneActivity::class.java).apply { + startActivity(this) } - - is UiState.Failure -> toast(stringOf(R.string.error_msg)) - else -> return@onEach + finish() + } else { + toast(stringOf(R.string.error_msg)) } }.launchIn(lifecycleScope) } diff --git a/presentation/src/main/java/co/orange/presentation/auth/login/LoginViewModel.kt b/presentation/src/main/java/co/orange/presentation/auth/login/LoginViewModel.kt index 91b4de22..a90b84fe 100644 --- a/presentation/src/main/java/co/orange/presentation/auth/login/LoginViewModel.kt +++ b/presentation/src/main/java/co/orange/presentation/auth/login/LoginViewModel.kt @@ -3,7 +3,7 @@ package co.orange.presentation.auth.login import android.content.Context import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import co.orange.core.state.UiState +import co.orange.domain.entity.request.AuthRequestModel import co.orange.domain.repository.AuthRepository import co.orange.domain.repository.UserRepository import com.kakao.sdk.auth.model.OAuthToken @@ -11,7 +11,9 @@ import com.kakao.sdk.common.model.ClientError import com.kakao.sdk.common.model.ClientErrorCause import com.kakao.sdk.user.UserApiClient 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.launch import javax.inject.Inject @@ -26,8 +28,8 @@ class LoginViewModel private val _isAppLoginAvailable = MutableStateFlow(true) val isAppLoginAvailable: StateFlow = _isAppLoginAvailable - private val _changeTokenState = MutableStateFlow>(UiState.Empty) - val changeTokenState: StateFlow> = _changeTokenState + private val _changeTokenResult = MutableSharedFlow() + val changeTokenResult: SharedFlow = _changeTokenResult private var appLoginCallback: (OAuthToken?, Throwable?) -> Unit = { token, error -> if (error != null) { @@ -64,13 +66,12 @@ class LoginViewModel authRepository.postOauthDataToGetToken(AuthRequestModel(accessToken, KAKAO)) .onSuccess { with(userRepository) { - setTokens(it.accessToken, it.refreshToken) - setUserRole(it.userRoleString) + setTokens(it.accesstoken, it.refreshtoken) } - _changeTokenState.value = UiState.Success(it.userRoleString) + _changeTokenResult.emit(true) } .onFailure { - _changeTokenState.value = UiState.Failure(it.message.toString()) + _changeTokenResult.emit(false) } } }