Code review: use isInvalidPassword() extension everywhere. Also be robust if the Fragment is destroyed
This commit is contained in:
parent
dbabe0232f
commit
85493b7532
|
@ -34,5 +34,6 @@ fun Throwable.shouldBeRetried(): Boolean {
|
|||
|
||||
fun Throwable.isInvalidPassword(): Boolean {
|
||||
return this is Failure.ServerError
|
||||
&& error.code == MatrixError.M_FORBIDDEN
|
||||
&& error.message == "Invalid password"
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package im.vector.riotx.core.error
|
|||
|
||||
import im.vector.matrix.android.api.failure.Failure
|
||||
import im.vector.matrix.android.api.failure.MatrixError
|
||||
import im.vector.matrix.android.api.failure.isInvalidPassword
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.resources.StringProvider
|
||||
import java.net.HttpURLConnection
|
||||
|
@ -54,8 +55,7 @@ class DefaultErrorFormatter @Inject constructor(
|
|||
// Special case for terms and conditions
|
||||
stringProvider.getString(R.string.error_terms_not_accepted)
|
||||
}
|
||||
throwable.error.code == MatrixError.M_FORBIDDEN
|
||||
&& throwable.error.message == "Invalid password" -> {
|
||||
throwable.isInvalidPassword() -> {
|
||||
stringProvider.getString(R.string.auth_invalid_login_param)
|
||||
}
|
||||
throwable.error.code == MatrixError.M_USER_IN_USE -> {
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.airbnb.mvrx.Success
|
|||
import com.jakewharton.rxbinding3.widget.textChanges
|
||||
import im.vector.matrix.android.api.failure.Failure
|
||||
import im.vector.matrix.android.api.failure.MatrixError
|
||||
import im.vector.matrix.android.api.failure.isInvalidPassword
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.extensions.hideKeyboard
|
||||
import im.vector.riotx.core.extensions.showPassword
|
||||
|
@ -209,10 +210,7 @@ class LoginFragment @Inject constructor() : AbstractLoginFragment() {
|
|||
} else {
|
||||
// Trick to display the error without text.
|
||||
loginFieldTil.error = " "
|
||||
if (error is Failure.ServerError
|
||||
&& error.error.code == MatrixError.M_FORBIDDEN
|
||||
&& error.error.message == "Invalid password"
|
||||
&& spaceInPassword()) {
|
||||
if (error.isInvalidPassword() && spaceInPassword()) {
|
||||
passwordFieldTil.error = getString(R.string.auth_invalid_login_param_space_in_password)
|
||||
} else {
|
||||
passwordFieldTil.error = errorFormatter.toHumanReadable(error)
|
||||
|
|
|
@ -775,12 +775,18 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {
|
|||
showPasswordLoadingView(true)
|
||||
session.changePassword(oldPwd, newPwd, object : MatrixCallback<Unit> {
|
||||
override fun onSuccess(data: Unit) {
|
||||
if (!isAdded) {
|
||||
return
|
||||
}
|
||||
showPasswordLoadingView(false)
|
||||
dialog.dismiss()
|
||||
activity.toast(R.string.settings_password_updated)
|
||||
}
|
||||
|
||||
override fun onFailure(failure: Throwable) {
|
||||
if (!isAdded) {
|
||||
return
|
||||
}
|
||||
showPasswordLoadingView(false)
|
||||
if (failure.isInvalidPassword()) {
|
||||
activity.toast(R.string.settings_fail_to_update_password_invalid_current_password)
|
||||
|
|
Loading…
Reference in New Issue