giving avatar/display name error dialogs human readable error messages (#5419)

- reuses the ErrorDialog logic which translates exceptions to human readable strings
This commit is contained in:
Benoit Marty 2022-03-03 18:29:39 +01:00 committed by GitHub
commit 1690a0b2cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 23 deletions

1
changelog.d/5418.feature Normal file
View file

@ -0,0 +1 @@
Improves settings error dialog messaging when changing avatar or display name fails

View file

@ -148,24 +148,6 @@ abstract class VectorSettingsBaseFragment : PreferenceFragmentCompat(), Maverick
}
}
/**
* A request has been processed.
* Display a toast if there is a an error message
*
* @param errorMessage the error message
*/
protected fun onCommonDone(errorMessage: String?) {
if (!isAdded) {
return
}
activity?.runOnUiThread {
if (errorMessage != null && errorMessage.isNotBlank()) {
displayErrorDialog(errorMessage)
}
hideLoadingView()
}
}
protected fun displayErrorDialog(throwable: Throwable) {
displayErrorDialog(errorFormatter.toHumanReadable(throwable))
}

View file

@ -329,7 +329,14 @@ class VectorSettingsGeneralFragment @Inject constructor(
session.updateAvatar(session.myUserId, uri, getFilenameFromUri(context, uri) ?: UUID.randomUUID().toString())
}
if (!isAdded) return@launch
onCommonDone(result.fold({ null }, { it.localizedMessage }))
result.fold(
onSuccess = { hideLoadingView() },
onFailure = {
hideLoadingView()
displayErrorDialog(it)
}
)
}
}
@ -466,14 +473,15 @@ class VectorSettingsGeneralFragment @Inject constructor(
val result = runCatching { session.setDisplayName(session.myUserId, value) }
if (!isAdded) return@launch
result.fold(
{
onSuccess = {
// refresh the settings value
mDisplayNamePreference.summary = value
mDisplayNamePreference.text = value
onCommonDone(null)
hideLoadingView()
},
{
onCommonDone(it.localizedMessage)
onFailure = {
hideLoadingView()
displayErrorDialog(it)
}
)
}