diff --git a/src/main/java/eu/siacs/conversations/AppSettings.java b/src/main/java/eu/siacs/conversations/AppSettings.java index 080cbaf3f..1614aa683 100644 --- a/src/main/java/eu/siacs/conversations/AppSettings.java +++ b/src/main/java/eu/siacs/conversations/AppSettings.java @@ -47,6 +47,7 @@ public class AppSettings { public static final String COLORFUL_CHAT_BUBBLES = "use_green_background"; public static final String LARGE_FONT = "large_font"; public static final String SHOW_LINK_PREVIEWS = "show_link_previews"; + public static final String SHOW_AVATARS = "show_avatars"; private static final String ACCEPT_INVITES_FROM_STRANGERS = "accept_invites_from_strangers"; private static final String INSTALLATION_ID = "im.conversations.android.install_id"; @@ -118,6 +119,10 @@ public class AppSettings { return getBooleanPreference(SHOW_LINK_PREVIEWS, R.bool.show_link_previews); } + public boolean isShowAvatars() { + return getBooleanPreference(SHOW_AVATARS, R.bool.show_avatars); + } + public boolean isUseTor() { return getBooleanPreference(USE_TOR, R.bool.use_tor); } diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 78b30f568..ae313decc 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -161,7 +161,7 @@ public class MessageAdapter extends ArrayAdapter { private OnContactPictureLongClicked mOnContactPictureLongClickedListener; private OnInlineImageLongClicked mOnInlineImageLongClickedListener; private boolean mUseGreenBackground = false; - private BubbleDesign bubbleDesign = new BubbleDesign(false, false); + private BubbleDesign bubbleDesign = new BubbleDesign(false, false, true); private final boolean mForceNames; private final Map lastWebxdcUpdate = new HashMap<>(); private String selectionUuid = null; @@ -1114,6 +1114,7 @@ public class MessageAdapter extends ArrayAdapter { } } + @NonNull @Override public View getView(final int position, View view, final @NonNull ViewGroup parent) { final Message message = getItem(position); @@ -1381,11 +1382,21 @@ public class MessageAdapter extends ArrayAdapter { // sent and received bubbles final var mergeIntoTop = mergeIntoTop(position, message); final var mergeIntoBottom = mergeIntoBottom(position, message); - final var requiresAvatar = type == SENT ? !mergeIntoBottom : !mergeIntoTop; + final var showAvatar = + bubbleDesign.showAvatars + || (type == RECEIVED + && message.getConversation().getMode() + == Conversation.MODE_MULTI); setBubblePadding(viewHolder.root, mergeIntoTop, mergeIntoBottom); - setRequiresAvatar(viewHolder, requiresAvatar); - viewHolder.message_box.setClipToOutline(true); //This eats the bubble tails on A14 for some reason - AvatarWorkerTask.loadAvatar(message, viewHolder.contact_picture, R.dimen.avatar_on_conversation_overview); + if (showAvatar) { + final var requiresAvatar = type == SENT ? !mergeIntoBottom : !mergeIntoTop; + setRequiresAvatar(viewHolder, requiresAvatar); + AvatarWorkerTask.loadAvatar(message, viewHolder.contact_picture, R.dimen.avatar); + } else { + viewHolder.contact_picture.setVisibility(View.GONE); + } + setAvatarDistance(viewHolder.message_box, type, showAvatar); + viewHolder.message_box.setClipToOutline(true); } resetClickListener(viewHolder.message_box, viewHolder.messageBody); @@ -1719,6 +1730,30 @@ public class MessageAdapter extends ArrayAdapter { } + private void setAvatarDistance( + final LinearLayout messageBox, final int type, final boolean showAvatar) { + final ViewGroup.MarginLayoutParams layoutParams = + (ViewGroup.MarginLayoutParams) messageBox.getLayoutParams(); + if (showAvatar) { + final var resources = messageBox.getResources(); + if (type == RECEIVED) { + layoutParams.setMarginStart( + resources.getDimensionPixelSize(R.dimen.bubble_avatar_distance)); + layoutParams.setMarginEnd(0); + } else if (type == SENT) { + layoutParams.setMarginStart(0); + layoutParams.setMarginEnd( + resources.getDimensionPixelSize(R.dimen.bubble_avatar_distance)); + } else { + throw new AssertionError("Avatar distances are not available on this view type"); + } + } else { + layoutParams.setMarginStart(0); + layoutParams.setMarginEnd(0); + } + messageBox.setLayoutParams(layoutParams); + } + private void setBubblePadding( final SwipeLayout root, final boolean mergeIntoTop, @@ -1884,8 +1919,12 @@ public class MessageAdapter extends ArrayAdapter { } public void updatePreferences() { + final AppSettings appSettings = new AppSettings(activity); this.bubbleDesign = - new BubbleDesign(appSettings.isColorfulChatBubbles(), appSettings.isLargeFont()); + new BubbleDesign( + appSettings.isColorfulChatBubbles(), + appSettings.isLargeFont(), + appSettings.isShowAvatars()); } public void setHighlightedTerm(List terms) { @@ -2008,10 +2047,15 @@ public class MessageAdapter extends ArrayAdapter { private static class BubbleDesign { public final boolean colorfulChatBubbles; public final boolean largeFont; + public final boolean showAvatars; - private BubbleDesign(final boolean colorfulChatBubbles, final boolean largeFont) { + private BubbleDesign( + final boolean colorfulChatBubbles, + final boolean largeFont, + final boolean showAvatars) { this.colorfulChatBubbles = colorfulChatBubbles; this.largeFont = largeFont; + this.showAvatars = showAvatars; } } diff --git a/src/main/java/eu/siacs/conversations/ui/fragment/settings/InterfaceBubblesSettingsFragment.java b/src/main/java/eu/siacs/conversations/ui/fragment/settings/InterfaceBubblesSettingsFragment.java new file mode 100644 index 000000000..73ff4df0b --- /dev/null +++ b/src/main/java/eu/siacs/conversations/ui/fragment/settings/InterfaceBubblesSettingsFragment.java @@ -0,0 +1,19 @@ +package eu.siacs.conversations.ui.fragment.settings; + +import android.os.Bundle; +import androidx.annotation.Nullable; +import eu.siacs.conversations.R; + +public class InterfaceBubblesSettingsFragment extends XmppPreferenceFragment { + + @Override + public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) { + setPreferencesFromResource(R.xml.preferences_interface_bubbles, rootKey); + } + + @Override + public void onStart() { + super.onStart(); + requireActivity().setTitle(R.string.pref_title_bubbles); + } +} diff --git a/src/main/res/drawable/ic_account_circle_24dp.xml b/src/main/res/drawable/ic_account_circle_24dp.xml new file mode 100644 index 000000000..25c7c244b --- /dev/null +++ b/src/main/res/drawable/ic_account_circle_24dp.xml @@ -0,0 +1,12 @@ + + + + + diff --git a/src/main/res/drawable/ic_colors_24dp.xml b/src/main/res/drawable/ic_colors_24dp.xml new file mode 100644 index 000000000..106cd34c1 --- /dev/null +++ b/src/main/res/drawable/ic_colors_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/src/main/res/layout/item_message_received.xml b/src/main/res/layout/item_message_received.xml index 5e32ffdfc..8341fa977 100644 --- a/src/main/res/layout/item_message_received.xml +++ b/src/main/res/layout/item_message_received.xml @@ -44,10 +44,8 @@ android:background="@drawable/message_bubble_received" android:backgroundTint="?colorTertiaryContainer" android:longClickable="true" - android:paddingLeft="7dp" + android:layout_marginStart="@dimen/bubble_avatar_distance" android:minHeight="@dimen/bubble_avatar_size" - android:layout_marginEnd="20dp" - android:layout_marginRight="20dp" app:layout_constrainedWidth="true" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" diff --git a/src/main/res/layout/item_message_sent.xml b/src/main/res/layout/item_message_sent.xml index f3eb0b6fb..1fdda63cd 100644 --- a/src/main/res/layout/item_message_sent.xml +++ b/src/main/res/layout/item_message_sent.xml @@ -51,9 +51,7 @@ android:backgroundTint="?colorSecondaryContainer" android:longClickable="true" android:minHeight="@dimen/bubble_avatar_size" - android:paddingRight="7dp" - android:layout_marginLeft="20dp" - android:layout_marginStart="20dp" + android:layout_marginEnd="@dimen/bubble_avatar_distance" app:layout_constrainedWidth="true" app:layout_constraintEnd_toStartOf="@id/message_photo_box" app:layout_constraintHorizontal_bias="1.0" diff --git a/src/main/res/values/defaults.xml b/src/main/res/values/defaults.xml index aa09778cd..dd134b918 100644 --- a/src/main/res/values/defaults.xml +++ b/src/main/res/values/defaults.xml @@ -19,6 +19,7 @@ auto false false + false none true true diff --git a/src/main/res/values/dimens.xml b/src/main/res/values/dimens.xml index dddd87832..19e61fa96 100644 --- a/src/main/res/values/dimens.xml +++ b/src/main/res/values/dimens.xml @@ -101,4 +101,5 @@ 4dp 1dp 48dp + 6dp diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index b7d31a019..e72638415 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -1371,4 +1371,9 @@ Save as contact / bookmark Suspected SPAM Chats from strangers + Show avatars + Display avatars for your messages and in 1:1 chats, in addition to group chats. + Chat bubbles + Background color, Font size, Avatars + Chat Bubbles \ No newline at end of file diff --git a/src/main/res/xml/preferences_interface.xml b/src/main/res/xml/preferences_interface.xml index b416a86ad..e24881b7a 100644 --- a/src/main/res/xml/preferences_interface.xml +++ b/src/main/res/xml/preferences_interface.xml @@ -131,18 +131,11 @@ android:summary="@string/pref_set_text_collapsable_summary" android:title="@string/pref_set_text_collapsable" /> --> - - + app:fragment="eu.siacs.conversations.ui.fragment.settings.InterfaceBubblesSettingsFragment" + app:summary="@string/pref_chat_bubbles_summary" + app:title="@string/pref_chat_bubbles" /> + + + + + \ No newline at end of file