diff --git a/app/src/main/java/org/android/go/sopt/presentation/login/LoginActivity.kt b/app/src/main/java/org/android/go/sopt/presentation/login/LoginActivity.kt index 5f09c22..a8d7593 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/login/LoginActivity.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/login/LoginActivity.kt @@ -14,8 +14,9 @@ import org.android.go.sopt.util.binding.BindingActivity import org.android.go.sopt.util.extension.setOnSingleClickListener import org.android.go.sopt.util.extension.showSnackbar import org.android.go.sopt.util.extension.showToast -import org.android.go.sopt.util.state.LocalUiState.Failure -import org.android.go.sopt.util.state.LocalUiState.Success +import org.android.go.sopt.util.state.RemoteUiState.Error +import org.android.go.sopt.util.state.RemoteUiState.Failure +import org.android.go.sopt.util.state.RemoteUiState.Success @AndroidEntryPoint class LoginActivity : BindingActivity(R.layout.activity_login) { @@ -47,6 +48,7 @@ class LoginActivity : BindingActivity(R.layout.activity_lo when (state) { is Success -> navigateToMainScreen() is Failure -> showSnackbar(binding.root, getString(R.string.wrong_input_msg)) + is Error -> showSnackbar(binding.root, getString(R.string.unknown_error_msg)) } } } diff --git a/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt b/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt index e49b601..fcaa003 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt @@ -9,9 +9,10 @@ import kotlinx.coroutines.launch import org.android.go.sopt.data.entity.remote.request.RequestPostSignInDto import org.android.go.sopt.domain.model.User import org.android.go.sopt.domain.repository.AuthRepository -import org.android.go.sopt.util.state.LocalUiState -import org.android.go.sopt.util.state.LocalUiState.Failure -import org.android.go.sopt.util.state.LocalUiState.Success +import org.android.go.sopt.util.state.RemoteUiState +import org.android.go.sopt.util.state.RemoteUiState.Error +import org.android.go.sopt.util.state.RemoteUiState.Failure +import org.android.go.sopt.util.state.RemoteUiState.Success import retrofit2.HttpException import timber.log.Timber import javax.inject.Inject @@ -20,8 +21,8 @@ import javax.inject.Inject class LoginViewModel @Inject constructor( private val authRepository: AuthRepository, ) : ViewModel() { - private val _loginState = MutableLiveData() - val loginState: LiveData + private val _loginState = MutableLiveData() + val loginState: LiveData get() = _loginState val _id = MutableLiveData("") @@ -38,7 +39,7 @@ class LoginViewModel @Inject constructor( private fun setupAutoLogin() { if (authRepository.getAutoLogin() && authRepository.getSignedUpUser() != null) { - _loginState.value = Success + _loginState.value = RemoteUiState.Success } } @@ -71,9 +72,17 @@ class LoginViewModel @Inject constructor( } .onFailure { t -> if (t is HttpException) { + when (t.code()) { + CODE_INVALID_INPUT -> _loginState.value = Failure(CODE_INVALID_INPUT) + else -> _loginState.value = Error + } Timber.e("POST SIGNIN FAIL ${t.code()} : ${t.message()}") } } } } + + companion object { + const val CODE_INVALID_INPUT = 400 + } } diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/follower/FollowerFragment.kt b/app/src/main/java/org/android/go/sopt/presentation/main/follower/FollowerFragment.kt index 1f54fa3..d63d7c6 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/main/follower/FollowerFragment.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/main/follower/FollowerFragment.kt @@ -10,6 +10,7 @@ import org.android.go.sopt.R import org.android.go.sopt.databinding.FragmentFollowerBinding import org.android.go.sopt.presentation.main.follower.FollowerAdapter.Companion.VIEW_TYPE_HEADER import org.android.go.sopt.util.binding.BindingFragment +import org.android.go.sopt.util.extension.showSnackbar import org.android.go.sopt.util.state.RemoteUiState.Error import org.android.go.sopt.util.state.RemoteUiState.Failure import org.android.go.sopt.util.state.RemoteUiState.Success @@ -51,8 +52,8 @@ class FollowerFragment : BindingFragment(R.layout.fragm viewModel.getFollowerListState.observe(viewLifecycleOwner) { state -> when (state) { is Success -> followerAdapter?.submitList(viewModel.followerList) - is Failure -> {} - is Error -> {} + is Failure -> requireContext().showSnackbar(binding.root, getString(R.string.follower_get_follower_list_null_msg)) + is Error -> requireContext().showSnackbar(binding.root, getString(R.string.unknown_error_msg)) } } } diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/follower/FollowerViewModel.kt b/app/src/main/java/org/android/go/sopt/presentation/main/follower/FollowerViewModel.kt index 7c9690a..2a36681 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/main/follower/FollowerViewModel.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/main/follower/FollowerViewModel.kt @@ -10,6 +10,7 @@ import org.android.go.sopt.domain.model.Follower import org.android.go.sopt.domain.repository.FollowerRepository import org.android.go.sopt.util.state.RemoteUiState import org.android.go.sopt.util.state.RemoteUiState.Error +import org.android.go.sopt.util.state.RemoteUiState.Failure import org.android.go.sopt.util.state.RemoteUiState.Success import retrofit2.HttpException import timber.log.Timber @@ -36,14 +37,17 @@ class FollowerViewModel @Inject constructor( viewModelScope.launch { followerRepository.getFollowerList(1) .onSuccess { response -> - // TODO: followerList null 처리 + if (response.isEmpty()) { + _getFollowerListState.value = Failure(null) + return@onSuccess + } + _followerList.value = response _getFollowerListState.value = Success Timber.d("GET FOLLOWER LIST SUCCESS : $response") } .onFailure { t -> if (t is HttpException) { - // TODO : failure 예외 처리 _getFollowerListState.value = Error Timber.e("GET FOLLOWER LIST FAIL : ${t.message}") } diff --git a/app/src/main/res/layout/item_follower.xml b/app/src/main/res/layout/item_follower.xml index a384a83..8c2fad0 100644 --- a/app/src/main/res/layout/item_follower.xml +++ b/app/src/main/res/layout/item_follower.xml @@ -14,6 +14,7 @@ android:id="@+id/layout_item_follower" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginTop="10dp" android:layout_marginBottom="30dp"> Followers + 팔로워가 존재하지 않습니다. 이름 : %s