From 54a4b6758be629c357e83c8af5440f1f91e8d501 Mon Sep 17 00:00:00 2001 From: Arne Date: Sun, 1 Sep 2024 18:48:29 +0200 Subject: [PATCH] Apply shapeable avatars --- build.gradle | 2 + .../res/layout/activity_contact_details.xml | 3 +- src/main/res/layout/activity_edit_account.xml | 5 +- src/main/res/layout/activity_muc_details.xml | 3 +- src/main/res/layout/item_account.xml | 5 +- .../res/layout/item_channel_discovery.xml | 5 +- src/main/res/layout/item_contact.xml | 5 +- src/main/res/layout/item_conversation.xml | 5 +- src/main/res/layout/item_message_received.xml | 5 +- src/main/res/layout/item_message_sent.xml | 5 +- src/main/res/layout/item_message_status.xml | 5 +- src/main/res/layout/item_user_preview.xml | 5 +- src/main/res/values/arrays.xml | 12 ++++ src/main/res/values/defaults.xml | 1 + src/main/res/values/dimens.xml | 3 + src/main/res/values/strings.xml | 6 ++ src/main/res/xml/preferences_interface.xml | 7 ++ .../conversations/ui/widget/AvatarView.kt | 71 +++++++++++++++++++ 18 files changed, 122 insertions(+), 31 deletions(-) create mode 100644 src/monocleschat/java/eu/siacs/conversations/ui/widget/AvatarView.kt diff --git a/build.gradle b/build.gradle index 9ac734e658..88a03fc042 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,7 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:8.3.2' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21" } } @@ -16,6 +17,7 @@ plugins { } apply plugin: 'com.android.application' +apply plugin: 'org.jetbrains.kotlin.android' repositories { google() diff --git a/src/main/res/layout/activity_contact_details.xml b/src/main/res/layout/activity_contact_details.xml index 0ebba5e5f6..e58c787fc0 100644 --- a/src/main/res/layout/activity_contact_details.xml +++ b/src/main/res/layout/activity_contact_details.xml @@ -43,12 +43,11 @@ android:layout_height="wrap_content" android:padding="@dimen/card_padding_regular"> - - + android:contentDescription="@string/account_image_description" /> - - + android:contentDescription="@string/account_image_description" /> - + android:scaleType="centerCrop" /> - + android:scaleType="centerCrop" /> - + android:scaleType="centerCrop" /> - + android:scaleType="centerCrop" /> - + android:scaleType="centerCrop" /> diff --git a/src/main/res/layout/item_message_status.xml b/src/main/res/layout/item_message_status.xml index b563582f7b..31e688c311 100644 --- a/src/main/res/layout/item_message_status.xml +++ b/src/main/res/layout/item_message_status.xml @@ -20,7 +20,7 @@ android:layout_centerVertical="true" android:text="@string/load_more_messages" /> - + android:scaleType="centerCrop" /> - + android:scaleType="centerCrop" /> diff --git a/src/main/res/values/arrays.xml b/src/main/res/values/arrays.xml index d457da4580..c12dfa9d06 100644 --- a/src/main/res/values/arrays.xml +++ b/src/main/res/values/arrays.xml @@ -48,6 +48,18 @@ SEND_LOCATION + + @string/avater_shape_rounded_square + @string/avater_shape_oval + @string/avater_shape_square + + + + rounded_square + oval + square + + never auto diff --git a/src/main/res/values/defaults.xml b/src/main/res/values/defaults.xml index 9286cfc2a5..d14b8fddc1 100644 --- a/src/main/res/values/defaults.xml +++ b/src/main/res/values/defaults.xml @@ -54,4 +54,5 @@ true true true + rounded_square diff --git a/src/main/res/values/dimens.xml b/src/main/res/values/dimens.xml index ebadf82b5f..7f8fed8bcb 100644 --- a/src/main/res/values/dimens.xml +++ b/src/main/res/values/dimens.xml @@ -55,4 +55,7 @@ 4dp 20sp 0dp + + + 8dp diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 4f65d95f77..fbe503906a 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -1076,4 +1076,10 @@ Welcome to monocles chat monocles chat is an app that connects you to a global network called Jabber. This network includes services, called gateways, for chatting with other networks such as SMS, IRC, Matrix, and more. How the XMPP network works + + Oval + Rounded Square + Square + Avatars shape + Allows you to select avatars shape globally diff --git a/src/main/res/xml/preferences_interface.xml b/src/main/res/xml/preferences_interface.xml index a08013b421..2d5a01156d 100644 --- a/src/main/res/xml/preferences_interface.xml +++ b/src/main/res/xml/preferences_interface.xml @@ -81,6 +81,13 @@ app:colorpicker_showAlpha="false" /> > + invalidateShape() } + + constructor(context: Context) : super(context) + constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) + constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super( + context, + attrs, + defStyleAttr + ) + + override fun onAttachedToWindow() { + super.onAttachedToWindow() + invalidateShape() + PreferenceManager.getDefaultSharedPreferences(context).registerOnSharedPreferenceChangeListener(preferencesListener) + } + + override fun onDetachedFromWindow() { + super.onDetachedFromWindow() + PreferenceManager.getDefaultSharedPreferences(context).unregisterOnSharedPreferenceChangeListener(preferencesListener) + } + + private fun invalidateShape() { + val shape = PreferenceManager.getDefaultSharedPreferences(context).getString("avatar_shape", context.getString(R.string.avatar_shape)) + + if (shape == currentShape) { + return + } + + when { + shape == "oval" -> { + clipToOutline = true + outlineProvider = object : ViewOutlineProvider() { + override fun getOutline(view: View, outline: Outline) { + outline.setOval(0, 0, view.width, view.height) + } + } + } + shape == "rounded_square" -> { + clipToOutline = true + outlineProvider = object : ViewOutlineProvider() { + override fun getOutline(view: View, outline: Outline) { + val maxRadius = minOf(view.width, view.height) / 2f + val radius = minOf(context.resources.getDimension(R.dimen.avatar_corners_radius), maxRadius) + outline.setRoundRect(0, 0, view.width, view.height, radius) + } + } + } + shape == "square" -> { + clipToOutline = false + outlineProvider = ViewOutlineProvider.BACKGROUND + } + } + + currentShape = shape!! + } +} \ No newline at end of file