Experimental option to collapse text messages longer than 6 lines

This commit is contained in:
Arne 2025-01-04 14:32:26 +01:00
parent ffe301a2a8
commit 8bbad5c4f7
6 changed files with 74 additions and 28 deletions

View file

@ -751,6 +751,37 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.messageBody().setAutoLinkMask(0); viewHolder.messageBody().setAutoLinkMask(0);
viewHolder.messageBody().setText(body); 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); if (body.length() <= 0) viewHolder.messageBody().setVisibility(View.GONE);
BetterLinkMovementMethod method = new BetterLinkMovementMethod() { BetterLinkMovementMethod method = new BetterLinkMovementMethod() {
@Override @Override
@ -2198,6 +2229,8 @@ public class MessageAdapter extends ArrayAdapter<Message> {
protected abstract TextView messageBody(); protected abstract TextView messageBody();
protected abstract TextView showMore();
protected abstract ImageView contactPicture(); protected abstract ImageView contactPicture();
protected abstract ChipGroup reactions(); protected abstract ChipGroup reactions();
@ -2307,6 +2340,11 @@ public class MessageAdapter extends ArrayAdapter<Message> {
return this.binding.messageContent.messageBody; return this.binding.messageContent.messageBody;
} }
@Override
protected TextView showMore() {
return this.binding.messageContent.showMore;
}
protected TextView encryption() { protected TextView encryption() {
return this.binding.messageEncryption; return this.binding.messageEncryption;
} }
@ -2440,6 +2478,11 @@ public class MessageAdapter extends ArrayAdapter<Message> {
return this.binding.messageContent.messageBody; return this.binding.messageContent.messageBody;
} }
@Override
protected TextView showMore() {
return this.binding.messageContent.showMore;
}
@Override @Override
protected ImageView contactPicture() { protected ImageView contactPicture() {
return this.binding.messagePhoto; return this.binding.messagePhoto;

View file

@ -64,23 +64,22 @@
android:layout_marginHorizontal="10dp" android:layout_marginHorizontal="10dp"
android:paddingTop="4dp" android:paddingTop="4dp"
android:autoLink="web" android:autoLink="web"
android:maxLines="6"
android:longClickable="false" android:longClickable="false"
android:textAppearance="?textAppearanceBodyMedium" android:textAppearance="?textAppearanceBodyMedium"
android:visibility="gone" /> android:visibility="gone" />
<de.monocles.chat.ReadMoreTextView <TextView
app:trimExpandedText="@string/show_less" android:id="@+id/show_more"
app:trimCollapsedText="@string/show_more"
app:trimMode="trimModeLength"
app:colorClickableText="?colorPrimary"
android:id="@+id/message_body_collapsable"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/message_body"
android:layout_marginHorizontal="10dp" android:layout_marginHorizontal="10dp"
android:paddingTop="4dp" android:text="... more / less"
android:autoLink="web" android:textColor="?colorPrimary"
android:longClickable="false" android:textStyle="bold"
android:textAppearance="?textAppearanceBodyMedium" android:textAppearance="?textAppearanceBodyLarge"
android:padding="2dp"
android:visibility="gone" /> android:visibility="gone" />
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton

View file

@ -62,7 +62,8 @@
<include <include
android:id="@+id/message_content" android:id="@+id/message_content"
layout="@layout/item_message_content" /> layout="@layout/item_message_content"
android:animateLayoutChanges="true" />
<com.wefika.flowlayout.FlowLayout <com.wefika.flowlayout.FlowLayout
android:id="@+id/status_line" android:id="@+id/status_line"
@ -159,7 +160,8 @@
android:layout_height="0dp" android:layout_height="0dp"
android:layout_marginBottom="12dp" android:layout_marginBottom="12dp"
app:layout_constraintBottom_toBottomOf="@+id/message_box" app:layout_constraintBottom_toBottomOf="@+id/message_box"
app:layout_constraintStart_toStartOf="@+id/message_box" /> app:layout_constraintStart_toStartOf="@+id/message_box"
android:animateLayoutChanges="true" />
<com.google.android.material.chip.ChipGroup <com.google.android.material.chip.ChipGroup
android:id="@+id/reactions" android:id="@+id/reactions"
@ -175,7 +177,8 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0" app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/message_box" app:layout_constraintStart_toStartOf="@+id/message_box"
app:layout_constraintTop_toBottomOf="@+id/reactions_anchor" /> app:layout_constraintTop_toBottomOf="@+id/reactions_anchor"
android:animateLayoutChanges="true" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</com.daimajia.swipe.SwipeLayout> </com.daimajia.swipe.SwipeLayout>
</layout> </layout>

View file

@ -56,18 +56,19 @@
app:layout_constraintEnd_toStartOf="@id/message_photo_box" app:layout_constraintEnd_toStartOf="@id/message_photo_box"
app:layout_constraintHorizontal_bias="1.0" app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent" >
<LinearLayout <LinearLayout
android:id="@+id/message_box_inner" android:id="@+id/message_box_inner"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="vertical"> android:orientation="vertical" >
<include <include
android:id="@+id/message_content" android:id="@+id/message_content"
layout="@layout/item_message_content" /> layout="@layout/item_message_content"
android:animateLayoutChanges="true" />
<com.wefika.flowlayout.FlowLayout <com.wefika.flowlayout.FlowLayout
android:id="@+id/status_line" android:id="@+id/status_line"
@ -155,7 +156,8 @@
android:layout_height="0dp" android:layout_height="0dp"
android:layout_marginBottom="12dp" android:layout_marginBottom="12dp"
app:layout_constraintBottom_toBottomOf="@+id/message_box" app:layout_constraintBottom_toBottomOf="@+id/message_box"
app:layout_constraintEnd_toEndOf="@+id/message_box" /> app:layout_constraintEnd_toEndOf="@+id/message_box"
android:animateLayoutChanges="true" />
<com.google.android.material.chip.ChipGroup <com.google.android.material.chip.ChipGroup
android:id="@+id/reactions" android:id="@+id/reactions"
@ -171,7 +173,8 @@
app:layout_constraintEnd_toEndOf="@+id/message_box" app:layout_constraintEnd_toEndOf="@+id/message_box"
app:layout_constraintHorizontal_bias="1.0" app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/reactions_anchor" /> app:layout_constraintTop_toBottomOf="@+id/reactions_anchor"
android:animateLayoutChanges="true" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</com.daimajia.swipe.SwipeLayout> </com.daimajia.swipe.SwipeLayout>
</layout> </layout>

View file

@ -1112,8 +1112,8 @@
<string name="pref_show_mappreview_inside_summary">Load a preview of maps for a share location inside the chat</string> <string name="pref_show_mappreview_inside_summary">Load a preview of maps for a share location inside the chat</string>
<string name="pref_show_own_accounts">Show own account name</string> <string name="pref_show_own_accounts">Show own account name</string>
<string name="pref_show_own_accounts_summary">Shows the used account on messages overview and details</string> <string name="pref_show_own_accounts_summary">Shows the used account on messages overview and details</string>
<string name="pref_set_text_collapsable_summary">Collapses text with more than 230 signs</string> <string name="pref_set_text_collapsable_summary">Collapses text longer than 6 lines</string>
<string name="pref_set_text_collapsable">Collapse long text</string> <string name="pref_set_text_collapsable">Experimental: Collapse long text</string>
<string name="show_less">... show less</string> <string name="show_less">... show less</string>
<string name="show_more">... show more</string> <string name="show_more">... show more</string>
<string name="pref_show_show_nav_drawer_summary">Activate a navigation drawer to better sort chats</string> <string name="pref_show_show_nav_drawer_summary">Activate a navigation drawer to better sort chats</string>

View file

@ -129,14 +129,6 @@
android:entryValues="@array/avatars_shape_values" android:entryValues="@array/avatars_shape_values"
android:summary="@string/pref_avatar_shape_summary" android:summary="@string/pref_avatar_shape_summary"
android:title="@string/pref_avatars_shape" /> android:title="@string/pref_avatars_shape" />
<!-- TODO: Add expandable text later
<SwitchPreferenceCompat
android:defaultValue="@bool/set_text_collapsable"
android:icon="@drawable/ic_keyboard_double_arrow_down_24dp"
android:key="set_text_collapsable"
android:summary="@string/pref_set_text_collapsable_summary"
android:title="@string/pref_set_text_collapsable" />
-->
<Preference <Preference
android:icon="@drawable/ic_forum_24dp" android:icon="@drawable/ic_forum_24dp"
app:fragment="eu.siacs.conversations.ui.fragment.settings.InterfaceBubblesSettingsFragment" app:fragment="eu.siacs.conversations.ui.fragment.settings.InterfaceBubblesSettingsFragment"
@ -154,6 +146,12 @@
android:key="show_link_previews" android:key="show_link_previews"
android:summary="@string/show_link_previews_summary" android:summary="@string/show_link_previews_summary"
android:title="@string/show_link_previews" /> android:title="@string/show_link_previews" />
<SwitchPreferenceCompat
android:defaultValue="@bool/set_text_collapsable"
android:icon="@drawable/ic_keyboard_double_arrow_down_24dp"
android:key="set_text_collapsable"
android:summary="@string/pref_set_text_collapsable_summary"
android:title="@string/pref_set_text_collapsable" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/pref_category_operating_system"> <PreferenceCategory android:title="@string/pref_category_operating_system">
<SwitchPreferenceCompat <SwitchPreferenceCompat