From 54e23a2c55a1cb8bde237bb8d54d9d1a33735060 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Thu, 3 Mar 2022 16:15:44 +0000 Subject: [PATCH] giving avatar/display name error dialogs human readable error messages - reuses the ErrorDialog logic which translates exceptions to human readable strings --- changelog.d/5418.feature | 1 + .../settings/VectorSettingsBaseFragment.kt | 18 ------------------ .../settings/VectorSettingsGeneralFragment.kt | 18 +++++++++++++----- 3 files changed, 14 insertions(+), 23 deletions(-) create mode 100644 changelog.d/5418.feature 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) } ) }