mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 17:35:54 +03:00
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:
parent
7a1322baf7
commit
54e23a2c55
3 changed files with 14 additions and 23 deletions
1
changelog.d/5418.feature
Normal file
1
changelog.d/5418.feature
Normal file
|
@ -0,0 +1 @@
|
|||
Improves settings error dialog messaging when changing avatar or display name fails
|
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue