Fix a refresh problem on the user avatar

This commit is contained in:
Benoit Marty 2020-08-28 11:12:29 +02:00
parent 66dfcbc2f8
commit b11eced4f1

View file

@ -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) }
}
}