mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2025-01-03 14:40:07 +02:00
Fix max lenght in chat + rework truncate feature
This commit is contained in:
parent
a4ec09dc61
commit
5aad4db2a4
4 changed files with 84 additions and 23 deletions
|
@ -1360,27 +1360,33 @@ 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(() -> {
|
||||
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.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) {
|
||||
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(holder.getBindingAdapterPosition());
|
||||
});
|
||||
if (statusToDeal.isTruncated) {
|
||||
holder.binding.statusContent.setMaxLines(truncate_toots_size);
|
||||
} else {
|
||||
holder.binding.statusContent.setMaxLines(9999);
|
||||
}
|
||||
} else {
|
||||
holder.binding.toggleTruncate.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
holder.binding.toggleTruncate.setOnClickListener(v -> {
|
||||
statusToDeal.isTruncated = !statusToDeal.isTruncated;
|
||||
adapter.notifyItemChanged(holder.getBindingAdapterPosition());
|
||||
});
|
||||
if (statusToDeal.isTruncated) {
|
||||
holder.binding.statusContent.setMaxLines(5);
|
||||
} else {
|
||||
holder.binding.statusContent.setMaxLines(9999);
|
||||
}
|
||||
} else {
|
||||
holder.binding.toggleTruncate.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
|
|
@ -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) {
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue