Skip to content

Commit

Permalink
Merge pull request #3003 from nextcloud/backport/3002/stable-17.0
Browse files Browse the repository at this point in the history
[stable-17.0] fix conversation avatars for NC26
  • Loading branch information
mahibi authored May 5, 2023
2 parents b08beea + 2825c47 commit e3aca72
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class ConversationItem(
ConversationType.ROOM_GROUP_CALL,
ConversationType.FORMER_ONE_TO_ONE,
ConversationType.ROOM_PUBLIC_CALL ->
holder.binding.dialogAvatar.loadConversationAvatar(user, model, false)
holder.binding.dialogAvatar.loadConversationAvatar(user, model, false, viewThemeUtils)

else -> holder.binding.dialogAvatar.visibility = View.GONE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ class ConversationInfoActivity :
}

Conversation.ConversationType.ROOM_GROUP_CALL, Conversation.ConversationType.ROOM_PUBLIC_CALL -> {
binding.avatarImage.loadConversationAvatar(conversationUser, conversation!!, false)
binding.avatarImage.loadConversationAvatar(conversationUser, conversation!!, false, viewThemeUtils)
}

Conversation.ConversationType.ROOM_SYSTEM -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ class ConversationInfoEditActivity :
}

Conversation.ConversationType.ROOM_GROUP_CALL, Conversation.ConversationType.ROOM_PUBLIC_CALL -> {
binding.avatarImage.loadConversationAvatar(conversationUser, conversation!!, false)
binding.avatarImage.loadConversationAvatar(conversationUser, conversation!!, false, viewThemeUtils)
}

Conversation.ConversationType.ROOM_SYSTEM -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ private const val TAG = "ImageViewExtensions"
fun ImageView.loadConversationAvatar(
user: User,
conversation: Conversation,
ignoreCache: Boolean
ignoreCache: Boolean,
viewThemeUtils: ViewThemeUtils?
): io.reactivex.disposables
.Disposable {
val imageRequestUri = ApiUtils.getUrlForConversationAvatarWithVersion(
Expand All @@ -66,6 +67,18 @@ fun ImageView.loadConversationAvatar(
conversation.avatarVersion
)

if (conversation.avatarVersion.isNullOrEmpty() && viewThemeUtils != null) {
when (conversation.type) {
Conversation.ConversationType.ROOM_GROUP_CALL ->
return loadDefaultGroupCallAvatar(viewThemeUtils)

Conversation.ConversationType.ROOM_PUBLIC_CALL ->
return loadDefaultPublicCallAvatar(viewThemeUtils)

else -> {}
}
}

// these placeholders are only used when the request fails completely. The server also return default avatars
// when no own images are set. (although these default avatars can not be themed for the android app..)
val errorPlaceholder =
Expand Down Expand Up @@ -263,6 +276,15 @@ fun ImageView.loadDefaultGroupCallAvatar(viewThemeUtils: ViewThemeUtils): io.rea
return loadUserAvatar(data)
}

fun ImageView.loadDefaultPublicCallAvatar(viewThemeUtils: ViewThemeUtils): io.reactivex.disposables.Disposable {
val data: Any = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
viewThemeUtils.talk.themePlaceholderAvatar(this, R.drawable.ic_avatar_link) as Any
} else {
R.drawable.ic_circular_link
}
return loadUserAvatar(data)
}

fun ImageView.loadMailAvatar(viewThemeUtils: ViewThemeUtils): io.reactivex.disposables.Disposable {
val data: Any = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
viewThemeUtils.talk.themePlaceholderAvatar(this, R.drawable.ic_avatar_mail) as Any
Expand Down
31 changes: 31 additions & 0 deletions app/src/main/res/drawable/ic_avatar_link.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!--
~ Nextcloud Talk application
~
~ @author Andy Scherzinger
~ Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
~
~ 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
~ the Free Software Foundation, either version 3 of the License, or
~ at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#ffffff"
android:fillType="nonZero"
android:pathData="M13,5.921L9.818,9.105C9.111,9.812 8.781,10.723 8.83,11.562C8.88,12.401 9.263,13.146 9.818,13.701L11.23,12.285C10.663,11.717 10.686,11.065 11.232,10.519L14.414,7.337C14.939,6.812 15.664,6.814 16.186,7.335C16.668,7.891 16.713,8.574 16.182,9.105L15.362,9.925C15.917,10.71 16.007,11.291 15.955,12.16L17.596,10.519C18.833,9.282 18.833,7.154 17.596,5.917C16.36,4.681 14.254,4.706 13,5.921ZM13.707,9.806L12.293,11.224L12.297,11.224C12.847,11.774 12.804,12.482 12.293,12.994L9.111,16.175C8.415,16.767 7.813,16.646 7.342,16.175C6.715,15.549 6.842,14.907 7.342,14.407L8.192,13.56C7.636,12.777 7.543,12.195 7.594,11.328L5.928,12.994C4.689,14.233 4.692,16.354 5.928,17.589C7.163,18.825 9.29,18.825 10.526,17.589L13.707,14.407C14.416,13.699 14.747,12.789 14.698,11.949C14.65,11.109 14.266,10.362 13.709,9.808L13.707,9.806Z" />
</vector>

0 comments on commit e3aca72

Please sign in to comment.