From 8bbad5c4f7b777c3ee50708f146a68cef5e5f6c5 Mon Sep 17 00:00:00 2001 From: Arne Date: Sat, 4 Jan 2025 14:32:26 +0100 Subject: [PATCH] Experimental option to collapse text messages longer than 6 lines --- .../ui/adapter/MessageAdapter.java | 43 +++++++++++++++++++ src/main/res/layout/item_message_content.xml | 19 ++++---- src/main/res/layout/item_message_received.xml | 9 ++-- src/main/res/layout/item_message_sent.xml | 13 +++--- src/main/res/values/strings.xml | 4 +- src/main/res/xml/preferences_interface.xml | 14 +++--- 6 files changed, 74 insertions(+), 28 deletions(-) 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 a6d7e899b..ffab2baf4 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -751,6 +751,37 @@ public class MessageAdapter extends ArrayAdapter { viewHolder.messageBody().setAutoLinkMask(0); viewHolder.messageBody().setText(body); + + // Experimental expandable text + if (activity.xmppConnectionService.getBooleanPreference("set_text_collapsable", R.bool.set_text_collapsable)) { + viewHolder.messageBody().post(new Runnable() { + @Override + public void run() { + int lineCount = viewHolder.messageBody().getLineCount(); + if (lineCount > 6) { + viewHolder.showMore().setVisibility(View.VISIBLE); + } else { + viewHolder.showMore().setVisibility(View.GONE); + } + } + }); + final boolean[] isTextViewClicked = {false}; + viewHolder.showMore().setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (isTextViewClicked[0]) { + //This will shrink textview to 6 lines if it is expanded. + viewHolder.messageBody().setMaxLines(6); + isTextViewClicked[0] = false; + } else { + //This will expand the textview if it is of 6 lines + viewHolder.messageBody().setMaxLines(Integer.MAX_VALUE); + isTextViewClicked[0] = true; + } + } + }); + } else viewHolder.messageBody().setMaxLines(Integer.MAX_VALUE); + if (body.length() <= 0) viewHolder.messageBody().setVisibility(View.GONE); BetterLinkMovementMethod method = new BetterLinkMovementMethod() { @Override @@ -2198,6 +2229,8 @@ public class MessageAdapter extends ArrayAdapter { protected abstract TextView messageBody(); + protected abstract TextView showMore(); + protected abstract ImageView contactPicture(); protected abstract ChipGroup reactions(); @@ -2307,6 +2340,11 @@ public class MessageAdapter extends ArrayAdapter { return this.binding.messageContent.messageBody; } + @Override + protected TextView showMore() { + return this.binding.messageContent.showMore; + } + protected TextView encryption() { return this.binding.messageEncryption; } @@ -2440,6 +2478,11 @@ public class MessageAdapter extends ArrayAdapter { return this.binding.messageContent.messageBody; } + @Override + protected TextView showMore() { + return this.binding.messageContent.showMore; + } + @Override protected ImageView contactPicture() { return this.binding.messagePhoto; diff --git a/src/main/res/layout/item_message_content.xml b/src/main/res/layout/item_message_content.xml index 1c6ab90f3..55772534b 100644 --- a/src/main/res/layout/item_message_content.xml +++ b/src/main/res/layout/item_message_content.xml @@ -64,23 +64,22 @@ android:layout_marginHorizontal="10dp" android:paddingTop="4dp" android:autoLink="web" + android:maxLines="6" android:longClickable="false" android:textAppearance="?textAppearanceBodyMedium" android:visibility="gone" /> - + layout="@layout/item_message_content" + android:animateLayoutChanges="true" /> + app:layout_constraintStart_toStartOf="@+id/message_box" + android:animateLayoutChanges="true" /> + app:layout_constraintTop_toBottomOf="@+id/reactions_anchor" + android:animateLayoutChanges="true" /> \ No newline at end of file diff --git a/src/main/res/layout/item_message_sent.xml b/src/main/res/layout/item_message_sent.xml index 7d80d79d6..f0431aecb 100644 --- a/src/main/res/layout/item_message_sent.xml +++ b/src/main/res/layout/item_message_sent.xml @@ -56,18 +56,19 @@ app:layout_constraintEnd_toStartOf="@id/message_photo_box" app:layout_constraintHorizontal_bias="1.0" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent"> + app:layout_constraintTop_toTopOf="parent" > + android:orientation="vertical" > + layout="@layout/item_message_content" + android:animateLayoutChanges="true" /> + app:layout_constraintEnd_toEndOf="@+id/message_box" + android:animateLayoutChanges="true" /> + app:layout_constraintTop_toBottomOf="@+id/reactions_anchor" + android:animateLayoutChanges="true" /> \ No newline at end of file diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 9c6052596..ba0a98626 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -1112,8 +1112,8 @@ Load a preview of maps for a share location inside the chat Show own account name Shows the used account on messages overview and details - Collapses text with more than 230 signs - Collapse long text + Collapses text longer than 6 lines + Experimental: Collapse long text ... show less ... show more Activate a navigation drawer to better sort chats diff --git a/src/main/res/xml/preferences_interface.xml b/src/main/res/xml/preferences_interface.xml index 18e873ce1..a25031204 100644 --- a/src/main/res/xml/preferences_interface.xml +++ b/src/main/res/xml/preferences_interface.xml @@ -129,14 +129,6 @@ android:entryValues="@array/avatars_shape_values" android:summary="@string/pref_avatar_shape_summary" android:title="@string/pref_avatars_shape" /> - +