From 2825c47ad3f5270542db69a688ee14a798612ab4 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 5 May 2023 15:02:12 +0200 Subject: [PATCH] fix conversation avatars for NC26 Signed-off-by: Marcel Hibbe --- .../talk/adapters/items/ConversationItem.kt | 2 +- .../ConversationInfoActivity.kt | 2 +- .../ConversationInfoEditActivity.kt | 2 +- .../talk/extensions/ImageViewExtensions.kt | 24 +++++++++++++- app/src/main/res/drawable/ic_avatar_link.xml | 31 +++++++++++++++++++ 5 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/drawable/ic_avatar_link.xml diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.kt b/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.kt index 6d3d5cbcc1..9e952d6347 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.kt @@ -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 } diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt index bce388b024..4b5502ffc1 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt @@ -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 -> { diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt index 38add41866..fd72a57360 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt @@ -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 -> { diff --git a/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt b/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt index 65d46f5dd5..b69a704f01 100644 --- a/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt +++ b/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt @@ -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( @@ -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 = @@ -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 diff --git a/app/src/main/res/drawable/ic_avatar_link.xml b/app/src/main/res/drawable/ic_avatar_link.xml new file mode 100644 index 0000000000..21e7d94dd3 --- /dev/null +++ b/app/src/main/res/drawable/ic_avatar_link.xml @@ -0,0 +1,31 @@ + + + + + \ No newline at end of file