mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-22 16:50:04 +02:00
Allow to truncate messages over x lines
This commit is contained in:
parent
9925c36a17
commit
d1ad105eb7
4 changed files with 62 additions and 34 deletions
|
@ -38,7 +38,6 @@ import android.os.CountDownTimer;
|
|||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.Html;
|
||||
import android.text.Layout;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
|
@ -336,30 +335,8 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
Helper.changeDrawableColor(context, holder.binding.favInfo, theme_text_color);
|
||||
}
|
||||
|
||||
holder.binding.toggleTruncate.setVisibility(View.GONE);
|
||||
|
||||
if (truncate_toots_size > 0) {
|
||||
holder.binding.statusContent.setMaxLines(truncate_toots_size);
|
||||
holder.binding.statusContent.setEllipsize(TextUtils.TruncateAt.END);
|
||||
Layout layout = holder.binding.statusContent.getLayout();
|
||||
if (layout != null) {
|
||||
int lines = layout.getLineCount();
|
||||
if (lines > truncate_toots_size) {
|
||||
int ellipsisCount = layout.getEllipsisCount(lines - 1);
|
||||
if (ellipsisCount > truncate_toots_size) {
|
||||
holder.binding.toggleTruncate.setVisibility(View.VISIBLE);
|
||||
holder.binding.toggleTruncate.setOnClickListener(v -> {
|
||||
statusToDeal.isTruncated = !statusToDeal.isTruncated;
|
||||
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
|
||||
});
|
||||
if (statusToDeal.isTruncated) {
|
||||
holder.binding.statusContent.setMaxLines(5);
|
||||
} else {
|
||||
holder.binding.statusContent.setMaxLines(9999);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status.isFocused) {
|
||||
holder.binding.statusContent.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
|
||||
holder.binding.spoiler.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
|
||||
|
@ -796,7 +773,34 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
}
|
||||
//--- MAIN CONTENT ---
|
||||
holder.binding.statusContent.setText(statusToDeal.span_content, TextView.BufferType.SPANNABLE);
|
||||
if (truncate_toots_size > 0) {
|
||||
holder.binding.statusContent.setMaxLines(truncate_toots_size);
|
||||
holder.binding.statusContent.setEllipsize(TextUtils.TruncateAt.END);
|
||||
|
||||
holder.binding.statusContent.post(() -> {
|
||||
if (holder.binding.statusContent.getLineCount() > truncate_toots_size) {
|
||||
holder.binding.toggleTruncate.setVisibility(View.VISIBLE);
|
||||
if (statusToDeal.isTruncated) {
|
||||
holder.binding.toggleTruncate.setText(R.string.display_toot_truncate);
|
||||
holder.binding.toggleTruncate.setCompoundDrawables(null, null, ContextCompat.getDrawable(context, R.drawable.ic_display_more), null);
|
||||
} else {
|
||||
holder.binding.toggleTruncate.setText(R.string.hide_toot_truncate);
|
||||
holder.binding.toggleTruncate.setCompoundDrawables(null, null, ContextCompat.getDrawable(context, R.drawable.ic_display_less), null);
|
||||
}
|
||||
holder.binding.toggleTruncate.setOnClickListener(v -> {
|
||||
statusToDeal.isTruncated = !statusToDeal.isTruncated;
|
||||
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
|
||||
});
|
||||
if (statusToDeal.isTruncated) {
|
||||
holder.binding.statusContent.setMaxLines(5);
|
||||
} else {
|
||||
holder.binding.statusContent.setMaxLines(9999);
|
||||
}
|
||||
} else {
|
||||
holder.binding.toggleTruncate.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (statusToDeal.translationContent != null) {
|
||||
holder.binding.containerTrans.setVisibility(View.VISIBLE);
|
||||
holder.binding.statusContentTranslated.setText(statusToDeal.span_translate, TextView.BufferType.SPANNABLE);
|
||||
|
|
10
app/src/main/res/drawable/ic_display_less.xml
Normal file
10
app/src/main/res/drawable/ic_display_less.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="@color/cyanea_accent_reference"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M7.41,15.41L12,10.83l4.59,4.58L18,14l-6,-6 -6,6z" />
|
||||
</vector>
|
10
app/src/main/res/drawable/ic_display_more.xml
Normal file
10
app/src/main/res/drawable/ic_display_more.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="@color/cyanea_accent_reference"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M7.41,8.59L12,13.17l4.59,-4.58L18,10l-6,6 -6,-6 1.41,-1.41z" />
|
||||
</vector>
|
|
@ -139,6 +139,7 @@
|
|||
android:textColor="@color/cyanea_accent_dark_reference"
|
||||
android:text="@string/show_content" />
|
||||
|
||||
|
||||
<app.fedilab.android.helper.CustomTextView
|
||||
android:id="@+id/status_content"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -148,19 +149,22 @@
|
|||
android:textIsSelectable="true"
|
||||
tools:maxLines="10"
|
||||
tools:text="@tools:sample/lorem/random" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:visibility="gone"
|
||||
android:id="@+id/toggle_truncate"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||
app:strokeColor="@color/cyanea_accent_dark_reference"
|
||||
android:paddingBottom="1dp"
|
||||
android:paddingTop="1dp"
|
||||
android:textSize="14sp"
|
||||
android:textAllCaps="false"
|
||||
android:text="@string/display_toot_truncate"
|
||||
android:layout_gravity="center"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:drawableEnd="@drawable/ic_display_more"
|
||||
android:gravity="center_vertical"
|
||||
app:strokeColor="@color/cyanea_accent_dark_reference"
|
||||
android:singleLine="true"
|
||||
android:text="@string/display_toot_truncate"
|
||||
app:iconTint="@color/cyanea_accent_reference"
|
||||
android:textAllCaps="false"
|
||||
|
||||
/>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/container_trans"
|
||||
android:layout_width="match_parent"
|
||||
|
|
Loading…
Reference in a new issue