Skip to content

Commit

Permalink
fix: Wrong avatar after user name change
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyDL-Infomaniak committed Feb 20, 2025
1 parent b77ba3c commit e215cb4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/src/main/java/com/infomaniak/mail/views/AvatarView.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Infomaniak Mail - Android
* Copyright (C) 2022-2024 Infomaniak Network SA
* Copyright (C) 2022-2025 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -196,6 +196,7 @@ class AvatarView @JvmOverloads constructor(
) {
when (avatarDisplayType) {
AvatarDisplayType.UNKNOWN_CORRESPONDENT -> loadUnknownUserAvatar()
AvatarDisplayType.USER_AVATAR -> loadUserAvatar(correspondent!!, bimi)
AvatarDisplayType.CUSTOM_AVATAR,
AvatarDisplayType.INITIALS -> loadAvatarUsingDictionary(correspondent!!, contacts, bimi)
AvatarDisplayType.BIMI -> loadBimiAvatar(bimi!!, correspondent!!)
Expand All @@ -205,6 +206,7 @@ class AvatarView @JvmOverloads constructor(
private fun getAvatarDisplayType(correspondent: Correspondent?, bimi: Bimi?, isBimiEnabled: Boolean): AvatarDisplayType {
return when {
correspondent == null -> AvatarDisplayType.UNKNOWN_CORRESPONDENT
correspondent.isMe() -> AvatarDisplayType.USER_AVATAR
correspondent.hasMergedContactAvatar(contactsFromViewModel) -> AvatarDisplayType.CUSTOM_AVATAR
bimi?.isDisplayable(isBimiEnabled) == true -> AvatarDisplayType.BIMI
else -> AvatarDisplayType.INITIALS
Expand All @@ -228,6 +230,11 @@ class AvatarView @JvmOverloads constructor(
binding.avatarImage.baseLoadAvatar(correspondent = mergedContact ?: correspondent)
}

private fun loadUserAvatar(correspondent: Correspondent, bimi: Bimi?) {
state.update(correspondent, bimi)
binding.avatarImage.baseLoadAvatar(correspondent)
}

private fun ImageView.baseLoadAvatar(correspondent: Correspondent) {
if (correspondent.shouldDisplayUserAvatar()) {
this@AvatarView.loadAvatar(AccountUtils.currentUser!!)
Expand Down Expand Up @@ -255,6 +262,7 @@ class AvatarView @JvmOverloads constructor(
enum class AvatarDisplayType {
UNKNOWN_CORRESPONDENT,
CUSTOM_AVATAR,
USER_AVATAR,
BIMI,
INITIALS,
}
Expand Down

0 comments on commit e215cb4

Please sign in to comment.