Commit 5aad4db2 authored by Thomas's avatar Thomas
Browse files

Fix max lenght in chat + rework truncate feature

parent a4ec09dc
Loading
Loading
Loading
Loading
+26 −20
Original line number Diff line number Diff line
@@ -1360,7 +1360,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
            holder.binding.statusContent.setMaxLines(truncate_toots_size);
            holder.binding.statusContent.setEllipsize(TextUtils.TruncateAt.END);

            holder.binding.statusContent.post(() -> {
            holder.binding.statusContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (holder.binding.statusContent.getLineCount() > 1) {
                        holder.binding.statusContent.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        if (holder.binding.statusContent.getLineCount() > truncate_toots_size) {
                            holder.binding.toggleTruncate.setVisibility(View.VISIBLE);
                            if (statusToDeal.isTruncated) {
@@ -1375,13 +1379,15 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
                                adapter.notifyItemChanged(holder.getBindingAdapterPosition());
                            });
                            if (statusToDeal.isTruncated) {
                        holder.binding.statusContent.setMaxLines(5);
                                holder.binding.statusContent.setMaxLines(truncate_toots_size);
                            } else {
                                holder.binding.statusContent.setMaxLines(9999);
                            }
                        } else {
                            holder.binding.toggleTruncate.setVisibility(View.GONE);
                        }
                    }
                }
            });
        } else {
            holder.binding.toggleTruncate.setVisibility(View.GONE);
+39 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.SpannableString;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -260,6 +261,44 @@ public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerVie
        }
        holder.binding.mainContainer.setLayoutParams(layoutParams);

        int truncate_toots_size = sharedpreferences.getInt(context.getString(R.string.SET_TRUNCATE_TOOTS_SIZE), 0);
        if (truncate_toots_size > 0) {
            holder.binding.messageContent.setMaxLines(truncate_toots_size);
            holder.binding.messageContent.setEllipsize(TextUtils.TruncateAt.END);

            holder.binding.messageContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (holder.binding.messageContent.getLineCount() > 1) {
                        holder.binding.messageContent.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        if (holder.binding.messageContent.getLineCount() > truncate_toots_size) {
                            holder.binding.toggleTruncate.setVisibility(View.VISIBLE);
                            if (status.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 -> {
                                status.isTruncated = !status.isTruncated;
                                notifyItemChanged(holder.getBindingAdapterPosition());
                            });
                            if (status.isTruncated) {
                                holder.binding.messageContent.setMaxLines(truncate_toots_size);
                            } else {
                                holder.binding.messageContent.setMaxLines(9999);
                            }
                        } else {
                            holder.binding.toggleTruncate.setVisibility(View.GONE);
                        }
                    }
                }
            });
        } else {
            holder.binding.toggleTruncate.setVisibility(View.GONE);
        }

        final float scale = sharedpreferences.getFloat(context.getString(R.string.SET_FONT_SCALE), 1.1f);
        if (status.poll != null && status.poll.options != null) {

+1 −1
Original line number Diff line number Diff line
@@ -461,7 +461,7 @@
            android:id="@+id/media"
            layout="@layout/layout_drawer_attachments"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="48dp"
            android:layout_marginTop="6dp"
            android:layout_marginEnd="6dp"
+18 −2
Original line number Diff line number Diff line
@@ -51,18 +51,34 @@
        android:layout_height="wrap_content"
        android:layout_marginEnd="6dp"
        android:layout_marginTop="6dp"
        android:maxLines="10"
        android:textColor="?attr/colorOnPrimary"
        app:layout_constraintTop_toBottomOf="@+id/user_pp"
        tools:text="@tools:sample/lorem/random" />

    <com.google.android.material.button.MaterialButton
        android:id="@+id/toggle_truncate"
        style="@style/Widget.Material3.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"
        android:singleLine="true"
        android:text="@string/display_toot_truncate"
        android:textAllCaps="false"
        android:visibility="gone"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/message_content"
        tools:visibility="visible" />

    <androidx.appcompat.widget.LinearLayoutCompat
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="6dp"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/message_content">
        app:layout_constraintTop_toBottomOf="@id/toggle_truncate">


        <include