Skip to content

Commit

Permalink
fixes #2363 : snackbar error messages on registration and password ch…
Browse files Browse the repository at this point in the history
…ange
  • Loading branch information
srishti-R committed Oct 14, 2023
1 parent 7267667 commit 2816b19
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class RegistrationFragment : BaseFragment() {

is RegistrationUiState.Error -> {
hideProgress()
showError(state.exception)
showError(getString(state.exception))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class RegistrationVerificationFragment : BaseFragment() {

is RegistrationUiState.Error -> {
hideProgress()
showError(state.exception)
showError(getString(state.exception))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class UpdatePasswordFragment : BaseFragment(), TextWatcher, OnFocusChangeListene

is RegistrationUiState.Error -> {
hideProgress()
showError(state.exception)
showError(getString(state.exception))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.mifos.mobile.utils

sealed class RegistrationUiState {
data class Error(val exception: String) : RegistrationUiState()
data class Error(val exception: Int) : RegistrationUiState()
object Success : RegistrationUiState()
object Loading : RegistrationUiState()
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import org.mifos.mobile.R
import org.mifos.mobile.repositories.UserAuthRepository
import org.mifos.mobile.utils.RegistrationUiState
import javax.inject.Inject
Expand Down Expand Up @@ -67,8 +68,7 @@ class RegistrationViewModel @Inject constructor(private val userAuthRepositoryIm
if (response?.isSuccessful == true) {
_registrationUiState.value = RegistrationUiState.Success
} else {
_registrationUiState.value =
response?.errorBody()?.string()?.let { RegistrationUiState.Error(it) }
_registrationUiState.value = RegistrationUiState.Error(R.string.could_not_register_user_error)
}
}
}
Expand All @@ -81,8 +81,7 @@ class RegistrationViewModel @Inject constructor(private val userAuthRepositoryIm
_registrationVerificationUiState.value =
RegistrationUiState.Success
} else {
_registrationVerificationUiState.value =
response?.errorBody()?.string()?.let { RegistrationUiState.Error(it) }
_registrationVerificationUiState.value = RegistrationUiState.Error(R.string.could_not_register_user_error)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import org.mifos.mobile.R
import org.mifos.mobile.repositories.ClientRepository
import org.mifos.mobile.repositories.UserAuthRepository
import org.mifos.mobile.utils.RegistrationUiState
Expand Down Expand Up @@ -35,20 +36,16 @@ class UpdatePasswordViewModel @Inject constructor(
viewModelScope.launch {
_updatePasswordUiState.value = RegistrationUiState.Loading
val response = userAuthRepositoryImp.updateAccountPassword(newPassword, confirmPassword)

try {
if (response?.isSuccessful == true) {
_updatePasswordUiState.value = RegistrationUiState.Success
clientRepositoryImp.updateAuthenticationToken(newPassword)
} else {
_updatePasswordUiState.value =
response?.errorBody()?.string()?.let { RegistrationUiState.Error(it) }
_updatePasswordUiState.value = RegistrationUiState.Error(R.string.could_not_update_password_error)
}
} catch (e: Throwable) {
_updatePasswordUiState.value =
response?.errorBody()?.string()?.let { RegistrationUiState.Error(it) }
_updatePasswordUiState.value = RegistrationUiState.Error(R.string.could_not_update_password_error)
}
}
}

}
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -646,5 +646,6 @@
</string-array>
<string name="app_info">App Info</string>
<string name="login_failed">Login Failed, Please Try Again Later.</string>

<string name="could_not_update_password_error">We were unable to update password.</string>
<string name="could_not_register_user_error">We were unable to register the user.</string>
</resources>

0 comments on commit 2816b19

Please sign in to comment.