diff --git a/changelog.d/5418.feature b/changelog.d/5418.feature new file mode 100644 index 0000000000..5e1efc8718 --- /dev/null +++ b/changelog.d/5418.feature @@ -0,0 +1 @@ +Improves settings error dialog messaging when changing avatar or display name fails \ No newline at end of file diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsBaseFragment.kt b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsBaseFragment.kt index dae234eecc..176909b48d 100644 --- a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsBaseFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsBaseFragment.kt @@ -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)) } diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsGeneralFragment.kt b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsGeneralFragment.kt index 767e555ede..ffb9fc4af4 100644 --- a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsGeneralFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsGeneralFragment.kt @@ -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) } ) }