From 35fed2676a5c3935710ed99125db8b54b94e3f00 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 23 Jun 2020 11:21:00 +0200 Subject: [PATCH] Cleanup after Onuray's review and improve wording when removing display name --- matrix-sdk-android/src/main/res/values/strings.xml | 4 ++-- .../features/settings/VectorSettingsGeneralFragment.kt | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/matrix-sdk-android/src/main/res/values/strings.xml b/matrix-sdk-android/src/main/res/values/strings.xml index fe62a19b8e..4e8e5abc96 100644 --- a/matrix-sdk-android/src/main/res/values/strings.xml +++ b/matrix-sdk-android/src/main/res/values/strings.xml @@ -33,8 +33,8 @@ You set your display name to %1$s %1$s changed their display name from %2$s to %3$s You changed your display name from %1$s to %2$s - %1$s removed their display name (%2$s) - You removed your display name (%1$s) + %1$s removed their display name (it was %2$s) + You removed your display name (it was %1$s) %1$s changed the topic to: %2$s You changed the topic to: %1$s %1$s changed the room name to: %2$s diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsGeneralFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsGeneralFragment.kt index d20f6c0684..6d73abf873 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsGeneralFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsGeneralFragment.kt @@ -122,7 +122,9 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() { it.summary = session.getUser(session.myUserId)?.displayName ?: "" it.text = it.summary.toString() it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> - onDisplayNameClick(newValue?.let { (it as String).trim() }) + newValue + ?.let { value -> (value as? String)?.trim() } + ?.let { value -> onDisplayNameChanged(value) } false } } @@ -857,20 +859,21 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() { /** * Update the displayname. */ - private fun onDisplayNameClick(value: String?) { - value ?: return + private fun onDisplayNameChanged(value: String) { val currentDisplayName = session.getUser(session.myUserId)?.displayName ?: "" if (currentDisplayName != value) { displayLoadingView() session.setDisplayName(session.myUserId, value, object : MatrixCallback { override fun onSuccess(data: Unit) { + if (!isAdded) return // refresh the settings value mDisplayNamePreference.summary = value onCommonDone(null) } override fun onFailure(failure: Throwable) { + if (!isAdded) return onCommonDone(failure.localizedMessage) } })