From ed4fa3690d3588ae44877e9c33e15b55b07e823a Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Thu, 20 Apr 2023 11:49:29 +0200 Subject: [PATCH] Use avatars from server (depending on light/dark mode) Placeholder avatars now also come from the server. This means themed avatars from the android app itself are no longer used here. The static placeholder icons defined in loadConversationAvatar are only used when the http request fails completely. Signed-off-by: Marcel Hibbe --- .../talk/adapters/items/ConversationItem.kt | 10 +--------- .../conversation/info/ConversationInfoActivity.kt | 14 +++++--------- .../talk/extensions/ImageViewExtensions.kt | 14 ++++++++++---- .../com/nextcloud/talk/utils/DisplayUtils.java | 5 +++++ app/src/main/res/drawable/account_circle_96dp.xml | 2 +- 5 files changed, 22 insertions(+), 23 deletions(-) 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 90abdb725..98fb1088e 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 @@ -42,8 +42,6 @@ import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.databinding.RvItemConversationWithLastMessageBinding import com.nextcloud.talk.extensions.loadAvatar import com.nextcloud.talk.extensions.loadConversationAvatar -import com.nextcloud.talk.extensions.loadDefaultGroupCallAvatar -import com.nextcloud.talk.extensions.loadDefaultPublicCallAvatar import com.nextcloud.talk.extensions.loadSystemAvatar import com.nextcloud.talk.models.json.chat.ChatMessage import com.nextcloud.talk.models.json.conversations.Conversation @@ -178,15 +176,9 @@ class ConversationItem( } } - ConversationType.ROOM_GROUP_CALL -> + ConversationType.ROOM_GROUP_CALL, ConversationType.FORMER_ONE_TO_ONE, ConversationType.ROOM_PUBLIC_CALL -> holder.binding.dialogAvatar.loadConversationAvatar(user, model) - ConversationType.FORMER_ONE_TO_ONE -> - holder.binding.dialogAvatar.loadDefaultGroupCallAvatar(viewThemeUtils) - - ConversationType.ROOM_PUBLIC_CALL -> - holder.binding.dialogAvatar.loadDefaultPublicCallAvatar(viewThemeUtils) - else -> holder.binding.dialogAvatar.visibility = View.GONE } } diff --git a/app/src/main/java/com/nextcloud/talk/conversation/info/ConversationInfoActivity.kt b/app/src/main/java/com/nextcloud/talk/conversation/info/ConversationInfoActivity.kt index 1305ae00c..e1a5e7b97 100644 --- a/app/src/main/java/com/nextcloud/talk/conversation/info/ConversationInfoActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversation/info/ConversationInfoActivity.kt @@ -61,8 +61,7 @@ import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.databinding.ControllerConversationInfoBinding import com.nextcloud.talk.events.EventStatus import com.nextcloud.talk.extensions.loadAvatar -import com.nextcloud.talk.extensions.loadDefaultGroupCallAvatar -import com.nextcloud.talk.extensions.loadDefaultPublicCallAvatar +import com.nextcloud.talk.extensions.loadConversationAvatar import com.nextcloud.talk.extensions.loadSystemAvatar import com.nextcloud.talk.jobs.DeleteConversationWorker import com.nextcloud.talk.jobs.LeaveConversationWorker @@ -760,16 +759,13 @@ class ConversationInfoActivity : private fun loadConversationAvatar() { when (conversation!!.type) { Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL -> if (!TextUtils.isEmpty(conversation!!.name)) { - conversation!!.name?.let { binding?.avatarImage?.loadAvatar(conversationUser!!, it) } + conversation!!.name?.let { binding.avatarImage.loadAvatar(conversationUser, it) } } - Conversation.ConversationType.ROOM_GROUP_CALL -> { - binding?.avatarImage?.loadDefaultGroupCallAvatar(viewThemeUtils) - } - Conversation.ConversationType.ROOM_PUBLIC_CALL -> { - binding?.avatarImage?.loadDefaultPublicCallAvatar(viewThemeUtils) + Conversation.ConversationType.ROOM_GROUP_CALL, Conversation.ConversationType.ROOM_PUBLIC_CALL -> { + binding.avatarImage.loadConversationAvatar(conversationUser, conversation!!) } Conversation.ConversationType.ROOM_SYSTEM -> { - binding?.avatarImage?.loadSystemAvatar() + binding.avatarImage.loadSystemAvatar() } else -> { 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 47d382370..2ce24ab13 100644 --- a/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt +++ b/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt @@ -44,6 +44,7 @@ import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.models.json.conversations.Conversation import com.nextcloud.talk.ui.theme.ViewThemeUtils import com.nextcloud.talk.utils.ApiUtils +import com.nextcloud.talk.utils.DisplayUtils private const val ROUNDING_PIXEL = 16f private const val TAG = "ImageViewExtensions" @@ -59,9 +60,8 @@ fun ImageView.loadConversationAvatar( conversation.token ) - // TODO: improve this! using the "old" drawables for now. because the themed drawables are not rounded by - // themselves and coil is - // not able to make placeholders rounded!! https://github.com/coil-kt/coil/issues/37 + // 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 placeholder = when (conversation.type) { Conversation.ConversationType.ROOM_GROUP_CALL -> @@ -125,8 +125,14 @@ private fun ImageView.loadAvatarInternal( diskCacheKey?.let { diskCache?.remove(it) } } + val finalUrl = if (DisplayUtils.isDarkModeOn(this.context)) { + "$url/dark" + } else { + url + } + return DisposableWrapper( - load(url) { + load(finalUrl) { user?.let { addHeader( "Authorization", diff --git a/app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java b/app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java index 61beb5f1a..f5a649dfc 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java @@ -108,6 +108,11 @@ public class DisplayUtils { private static final int DATE_TIME_PARTS_SIZE = 2; + public static Boolean isDarkModeOn(Context context) { + int currentNightMode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; + return currentNightMode == Configuration.UI_MODE_NIGHT_YES; + } + public static void setClickableString(String string, String url, TextView textView) { SpannableString spannableString = new SpannableString(string); spannableString.setSpan(new ClickableSpan() { diff --git a/app/src/main/res/drawable/account_circle_96dp.xml b/app/src/main/res/drawable/account_circle_96dp.xml index eca5e2318..b976f2075 100644 --- a/app/src/main/res/drawable/account_circle_96dp.xml +++ b/app/src/main/res/drawable/account_circle_96dp.xml @@ -21,7 +21,7 @@ android:viewportWidth="24" android:viewportHeight="24">