diff options
author | Thomas <tschneider.ac@gmail.com> | 2022-05-24 16:40:09 +0200 |
---|---|---|
committer | Thomas <tschneider.ac@gmail.com> | 2022-05-24 16:40:09 +0200 |
commit | d1ad105eb7070bed94c61a8f22a7169b2d6a4b36 (patch) | |
tree | b6bfe2d59351136582aefabd4d1911394630dc82 /app/src | |
parent | 9925c36a17e7347d27da706eb11634542819a27b (diff) |
Allow to truncate messages over x lines
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java | 52 | ||||
-rw-r--r-- | app/src/main/res/drawable/ic_display_less.xml | 10 | ||||
-rw-r--r-- | app/src/main/res/drawable/ic_display_more.xml | 10 | ||||
-rw-r--r-- | app/src/main/res/layout/drawer_status.xml | 22 |
4 files changed, 61 insertions, 33 deletions
diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java index 70fd0be8c..1d6aadd69 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java @@ -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); diff --git a/app/src/main/res/drawable/ic_display_less.xml b/app/src/main/res/drawable/ic_display_less.xml new file mode 100644 index 000000000..453333c92 --- /dev/null +++ b/app/src/main/res/drawable/ic_display_less.xml @@ -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> diff --git a/app/src/main/res/drawable/ic_display_more.xml b/app/src/main/res/drawable/ic_display_more.xml new file mode 100644 index 000000000..71e1d3bcf --- /dev/null +++ b/app/src/main/res/drawable/ic_display_more.xml @@ -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> diff --git a/app/src/main/res/layout/drawer_status.xml b/app/src/main/res/layout/drawer_status.xml index 238b72219..780989532 100644 --- a/app/src/main/res/layout/drawer_status.xml +++ b/app/src/main/res/layout/drawer_status.xml @@ -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" + style="@style/Widget.MaterialComponents.Button.TextButton" + android:layout_width="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:paddingBottom="1dp" - android:paddingTop="1dp" - android:textSize="14sp" - android:textAllCaps="false" + android:singleLine="true" android:text="@string/display_toot_truncate" - android:layout_gravity="center" - android:layout_width="wrap_content" - android:layout_height="wrap_content"/> + app:iconTint="@color/cyanea_accent_reference" + android:textAllCaps="false" + + /> <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/container_trans" android:layout_width="match_parent" |