support avatars shape customization

This commit is contained in:
kosyak 2024-07-21 12:00:17 +02:00
parent 7ef0e53892
commit 21658d20d0
18 changed files with 119 additions and 33 deletions

View file

@ -64,7 +64,6 @@ dependencies {
implementation 'de.measite.minidns:minidns-hla:0.2.4' implementation 'de.measite.minidns:minidns-hla:0.2.4'
implementation 'me.leolin:ShortcutBadger:1.1.22@aar' implementation 'me.leolin:ShortcutBadger:1.1.22@aar'
implementation 'org.whispersystems:signal-protocol-java:2.6.2' implementation 'org.whispersystems:signal-protocol-java:2.6.2'
implementation 'com.makeramen:roundedimageview:2.3.0'
implementation "com.wefika:flowlayout:0.4.1" implementation "com.wefika:flowlayout:0.4.1"
//noinspection GradleDependency //noinspection GradleDependency
implementation('com.github.natario1:Transcoder:v0.9.1') { implementation('com.github.natario1:Transcoder:v0.9.1') {

View file

@ -0,0 +1,71 @@
package eu.siacs.conversations.ui.widget
import android.content.Context
import android.content.SharedPreferences
import android.graphics.Outline
import android.preference.PreferenceManager
import android.util.AttributeSet
import android.view.View
import android.view.ViewOutlineProvider
import androidx.appcompat.widget.AppCompatImageView
import eu.siacs.conversations.R
class AvatarView : AppCompatImageView {
private var currentShape: String = ""
private val preferencesListener = SharedPreferences.OnSharedPreferenceChangeListener { _, _ -> 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!!
}
}

View file

@ -10,13 +10,12 @@
android:paddingBottom="8dp" android:paddingBottom="8dp"
android:paddingTop="8dp"> android:paddingTop="8dp">
<com.makeramen.roundedimageview.RoundedImageView <eu.siacs.conversations.ui.widget.AvatarView
android:id="@+id/account_image" android:id="@+id/account_image"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:contentDescription="@string/account_image_description" android:contentDescription="@string/account_image_description" />
app:riv_corner_radius="6dp" />
<LinearLayout <LinearLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"

View file

@ -35,12 +35,11 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="@dimen/card_padding_regular"> android:padding="@dimen/card_padding_regular">
<com.makeramen.roundedimageview.RoundedImageView <eu.siacs.conversations.ui.widget.AvatarView
android:id="@+id/details_contact_badge" android:id="@+id/details_contact_badge"
android:layout_width="@dimen/avatar_on_details_screen_size" android:layout_width="@dimen/avatar_on_details_screen_size"
android:layout_height="@dimen/avatar_on_details_screen_size" android:layout_height="@dimen/avatar_on_details_screen_size"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
app:riv_corner_radius="8dp"
android:scaleType="centerCrop" /> android:scaleType="centerCrop" />
<LinearLayout <LinearLayout

View file

@ -39,14 +39,13 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="@dimen/card_padding_regular"> android:padding="@dimen/card_padding_regular">
<com.makeramen.roundedimageview.RoundedImageView <eu.siacs.conversations.ui.widget.AvatarView
android:id="@+id/avater" android:id="@+id/avater"
android:layout_width="@dimen/avatar_on_details_screen_size" android:layout_width="@dimen/avatar_on_details_screen_size"
android:layout_height="@dimen/avatar_on_details_screen_size" android:layout_height="@dimen/avatar_on_details_screen_size"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_marginRight="@dimen/avatar_item_distance" android:layout_marginRight="@dimen/avatar_item_distance"
android:contentDescription="@string/account_image_description" android:contentDescription="@string/account_image_description" />
app:riv_corner_radius="8dp" />
<LinearLayout <LinearLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"

View file

@ -40,11 +40,10 @@
android:gravity="center_vertical" android:gravity="center_vertical"
android:padding="16dp"> android:padding="16dp">
<com.makeramen.roundedimageview.RoundedImageView <eu.siacs.conversations.ui.widget.AvatarView
android:id="@+id/muc_pm_counterpart_avatar" android:id="@+id/muc_pm_counterpart_avatar"
android:layout_width="@dimen/avatar_on_details_screen_size" android:layout_width="@dimen/avatar_on_details_screen_size"
android:layout_height="@dimen/avatar_on_details_screen_size" android:layout_height="@dimen/avatar_on_details_screen_size"
app:riv_corner_radius="8dp"
android:layout_marginEnd="@dimen/avatar_item_distance"/> android:layout_marginEnd="@dimen/avatar_item_distance"/>
<LinearLayout <LinearLayout
@ -97,12 +96,11 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="32dp"> android:layout_marginBottom="32dp">
<com.makeramen.roundedimageview.RoundedImageView <eu.siacs.conversations.ui.widget.AvatarView
android:id="@+id/your_photo" android:id="@+id/your_photo"
android:layout_width="@dimen/avatar_on_details_screen_size" android:layout_width="@dimen/avatar_on_details_screen_size"
android:layout_height="@dimen/avatar_on_details_screen_size" android:layout_height="@dimen/avatar_on_details_screen_size"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
app:riv_corner_radius="8dp"
android:layout_marginEnd="@dimen/avatar_item_distance" android:layout_marginEnd="@dimen/avatar_item_distance"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_marginRight="@dimen/avatar_item_distance" /> android:layout_marginRight="@dimen/avatar_item_distance" />

View file

@ -8,13 +8,12 @@
android:background="?selectableItemBackground" android:background="?selectableItemBackground"
android:padding="@dimen/list_padding"> android:padding="@dimen/list_padding">
<com.makeramen.roundedimageview.RoundedImageView <eu.siacs.conversations.ui.widget.AvatarView
android:id="@+id/contact_photo" android:id="@+id/contact_photo"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:scaleType="centerCrop" android:scaleType="centerCrop"/>
app:riv_corner_radius="6dp"/>
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"

View file

@ -19,13 +19,12 @@
android:orientation="horizontal" android:orientation="horizontal"
android:padding="8dp"> android:padding="8dp">
<com.makeramen.roundedimageview.RoundedImageView <eu.siacs.conversations.ui.widget.AvatarView
android:id="@+id/conversation_image" android:id="@+id/conversation_image"
android:layout_width="56dp" android:layout_width="56dp"
android:layout_height="56dp" android:layout_height="56dp"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:scaleType="centerCrop" android:scaleType="centerCrop" />
app:riv_corner_radius="8dp" />
<RelativeLayout <RelativeLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
@ -43,6 +42,7 @@
android:paddingRight="4dp" android:paddingRight="4dp"
android:maxLines="1" android:maxLines="1"
android:ellipsize="end" android:ellipsize="end"
android:fontFamily="sans-serif-medium"
android:textAppearance="@style/TextAppearance.Conversations.Subhead" /> android:textAppearance="@style/TextAppearance.Conversations.Subhead" />
<RelativeLayout <RelativeLayout

View file

@ -22,15 +22,14 @@
android:alpha="0" android:alpha="0"
android:visibility="invisible"/> android:visibility="invisible"/>
<com.makeramen.roundedimageview.RoundedImageView <eu.siacs.conversations.ui.widget.AvatarView
android:id="@+id/message_photo" android:id="@+id/message_photo"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:translationY="-2dp" android:translationY="-2dp"
android:scaleType="fitXY" android:scaleType="fitXY" />
app:riv_corner_radius="6dp" />
<LinearLayout <LinearLayout
android:id="@+id/message_box" android:id="@+id/message_box"

View file

@ -22,15 +22,14 @@
android:alpha="0" android:alpha="0"
android:visibility="invisible"/> android:visibility="invisible"/>
<com.makeramen.roundedimageview.RoundedImageView <eu.siacs.conversations.ui.widget.AvatarView
android:id="@+id/message_photo" android:id="@+id/message_photo"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:translationY="-2dp" android:translationY="-2dp"
android:scaleType="fitXY" android:scaleType="fitXY" />
app:riv_corner_radius="6dp" />
<LinearLayout <LinearLayout
android:id="@+id/message_box" android:id="@+id/message_box"

View file

@ -19,7 +19,7 @@
android:text="@string/load_more_messages" android:text="@string/load_more_messages"
android:textColor="?colorAccent"/> android:textColor="?colorAccent"/>
<com.makeramen.roundedimageview.RoundedImageView <eu.siacs.conversations.ui.widget.AvatarView
android:id="@+id/message_photo" android:id="@+id/message_photo"
android:layout_width="32dp" android:layout_width="32dp"
android:layout_height="32dp" android:layout_height="32dp"
@ -27,8 +27,7 @@
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_marginRight="-1.5dp" android:layout_marginRight="-1.5dp"
android:padding="0dp" android:padding="0dp"
android:scaleType="fitXY" android:scaleType="fitXY" />
app:riv_corner_radius="4dp"/>
<TextView <TextView
android:id="@+id/status_message" android:id="@+id/status_message"

View file

@ -9,13 +9,12 @@
android:background="?selectableItemBackground" android:background="?selectableItemBackground"
android:padding="@dimen/list_padding"> android:padding="@dimen/list_padding">
<com.makeramen.roundedimageview.RoundedImageView <eu.siacs.conversations.ui.widget.AvatarView
android:id="@+id/avatar" android:id="@+id/avatar"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:scaleType="centerCrop" android:scaleType="centerCrop" />
app:riv_corner_radius="6dp" />
<RelativeLayout <RelativeLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"

View file

@ -6,12 +6,11 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:padding="2dp" android:padding="2dp"
android:background="?selectableItemBackground"> android:background="?selectableItemBackground">
<com.makeramen.roundedimageview.RoundedImageView <eu.siacs.conversations.ui.widget.AvatarView
android:id="@+id/avatar" android:id="@+id/avatar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/black54" android:background="@color/black54"
app:riv_corner_radius="6dp"
android:scaleType="centerInside"/> android:scaleType="centerInside"/>
</eu.siacs.conversations.ui.widget.SquareFrameLayout> </eu.siacs.conversations.ui.widget.SquareFrameLayout>
</layout> </layout>

View file

@ -89,6 +89,18 @@
<item>SEND_LOCATION</item> <item>SEND_LOCATION</item>
</string-array> </string-array>
<string-array name="avatars_shape">
<item>@string/avater_shape_rounded_square</item>
<item>@string/avater_shape_oval</item>
<item>@string/avater_shape_square</item>
</string-array>
<string-array name="avatars_shape_values">
<item>rounded_square</item>
<item>oval</item>
<item>square</item>
</string-array>
<string-array name="picture_compression_values"> <string-array name="picture_compression_values">
<item>never</item> <item>never</item>
<item>auto</item> <item>auto</item>

View file

@ -54,4 +54,5 @@
<string name="default_push_account">none</string> <string name="default_push_account">none</string>
<bool name="always_full_timestamps">false</bool> <bool name="always_full_timestamps">false</bool>
<bool name="skip_image_editor_screen">false</bool> <bool name="skip_image_editor_screen">false</bool>
<string name="avatar_shape">rounded_square</string>
</resources> </resources>

View file

@ -78,4 +78,6 @@
<dimen name="activity_margin">16dp</dimen> <dimen name="activity_margin">16dp</dimen>
<dimen name="colorpicker_hue_width">30dp</dimen> <dimen name="colorpicker_hue_width">30dp</dimen>
<dimen name="avatar_corners_radius">8dp</dimen>
</resources> </resources>

View file

@ -599,6 +599,8 @@
<string name="pref_theme_dark">Dark</string> <string name="pref_theme_dark">Dark</string>
<string name="pref_show_navigation_bar">Show navigation bar</string> <string name="pref_show_navigation_bar">Show navigation bar</string>
<string name="pref_show_navigation_bar_summary">Use alternative navigation way via navigation bar on the bottom of the screen</string> <string name="pref_show_navigation_bar_summary">Use alternative navigation way via navigation bar on the bottom of the screen</string>
<string name="pref_avatars_shape">Avatars shape</string>
<string name="pref_avatar_shape_summary">Allows you to select avatars shape globally</string>
<string name="pref_use_green_background">Green Background</string> <string name="pref_use_green_background">Green Background</string>
<string name="pref_use_green_background_summary">Use green background for received messages</string> <string name="pref_use_green_background_summary">Use green background for received messages</string>
<string name="pref_always_show_full_timestamps">Show full timestamps</string> <string name="pref_always_show_full_timestamps">Show full timestamps</string>
@ -1099,4 +1101,7 @@
<string name="delete_background_failed">Couldn\'t remove background image</string> <string name="delete_background_failed">Couldn\'t remove background image</string>
<string name="delete_background_success">Background image removed</string> <string name="delete_background_success">Background image removed</string>
<string name="no_background_set">No custom background set</string> <string name="no_background_set">No custom background set</string>
<string name="avater_shape_oval">Oval</string>
<string name="avater_shape_rounded_square">Rounded Square</string>
<string name="avater_shape_square">Square</string>
</resources> </resources>

View file

@ -183,6 +183,13 @@
android:key="show_nav_bar" android:key="show_nav_bar"
android:summary="@string/pref_show_navigation_bar_summary" android:summary="@string/pref_show_navigation_bar_summary"
android:title="@string/pref_show_navigation_bar" /> android:title="@string/pref_show_navigation_bar" />
<ListPreference
android:defaultValue="@string/avatar_shape"
android:key="avatar_shape"
android:entries="@array/avatars_shape"
android:entryValues="@array/avatars_shape_values"
android:summary="@string/pref_avatar_shape_summary"
android:title="@string/pref_avatars_shape" />
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="@bool/use_green_background" android:defaultValue="@bool/use_green_background"
android:key="use_green_background" android:key="use_green_background"