giving avatar/display name error dialogs human readable error messages

- reuses the ErrorDialog logic which translates exceptions to human readable strings
This commit is contained in:
Adam Brown 2022-03-03 16:15:44 +00:00
parent 7a1322baf7
commit 54e23a2c55
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) { protected fun displayErrorDialog(throwable: Throwable) {
displayErrorDialog(errorFormatter.toHumanReadable(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()) session.updateAvatar(session.myUserId, uri, getFilenameFromUri(context, uri) ?: UUID.randomUUID().toString())
} }
if (!isAdded) return@launch 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) } val result = runCatching { session.setDisplayName(session.myUserId, value) }
if (!isAdded) return@launch if (!isAdded) return@launch
result.fold( result.fold(
{ onSuccess = {
// refresh the settings value // refresh the settings value
mDisplayNamePreference.summary = value mDisplayNamePreference.summary = value
mDisplayNamePreference.text = value mDisplayNamePreference.text = value
onCommonDone(null) hideLoadingView()
}, },
{ onFailure = {
onCommonDone(it.localizedMessage) hideLoadingView()
displayErrorDialog(it)
} }
) )
} }