From b11eced4f14b179ab0cacd7a4c3bfdf93b228fdb Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 28 Aug 2020 11:12:29 +0200 Subject: [PATCH] Fix a refresh problem on the user avatar --- .../app/core/preference/UserAvatarPreference.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/core/preference/UserAvatarPreference.kt b/vector/src/main/java/im/vector/app/core/preference/UserAvatarPreference.kt index e3b4430fe0..3bb50c6284 100755 --- a/vector/src/main/java/im/vector/app/core/preference/UserAvatarPreference.kt +++ b/vector/src/main/java/im/vector/app/core/preference/UserAvatarPreference.kt @@ -26,6 +26,7 @@ import im.vector.app.R import im.vector.app.core.extensions.vectorComponent import im.vector.app.features.home.AvatarRenderer import org.matrix.android.sdk.api.session.user.model.User +import org.matrix.android.sdk.api.util.MatrixItem import org.matrix.android.sdk.api.util.toMatrixItem class UserAvatarPreference : Preference { @@ -34,6 +35,8 @@ class UserAvatarPreference : Preference { private var avatarRenderer: AvatarRenderer = context.vectorComponent().avatarRenderer() + private var userItem: MatrixItem.UserItem? = null + constructor(context: Context) : super(context) constructor(context: Context, attrs: AttributeSet) : super(context, attrs) @@ -50,9 +53,16 @@ class UserAvatarPreference : Preference { super.onBindViewHolder(holder) mAvatarView = holder.itemView.findViewById(R.id.settings_avatar) mLoadingProgressBar = holder.itemView.findViewById(R.id.avatar_update_progress_bar) + refreshUi() } fun refreshAvatar(user: User) { - mAvatarView?.let { avatarRenderer.render(user.toMatrixItem(), it) } + userItem = user.toMatrixItem() + refreshUi() + } + + private fun refreshUi() { + val safeUserItem = userItem ?: return + mAvatarView?.let { avatarRenderer.render(safeUserItem, it) } } }