mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-22 16:50:04 +02:00
bad behavior with truncated messages
This commit is contained in:
parent
545fbe588c
commit
7195f03501
2 changed files with 39 additions and 29 deletions
|
@ -1359,36 +1359,19 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
if (truncate_toots_size > 0) {
|
||||
holder.binding.statusContent.setMaxLines(truncate_toots_size);
|
||||
holder.binding.statusContent.setEllipsize(TextUtils.TruncateAt.END);
|
||||
|
||||
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);
|
||||
if (holder.binding.statusContent.getLineCount() == 0) {
|
||||
holder.binding.statusContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
if (holder.binding.statusContent.getLineCount() > 1) {
|
||||
holder.binding.statusContent.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
resizeContent(context, holder, statusToDeal, adapter);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
resizeContent(context, holder, statusToDeal, adapter);
|
||||
}
|
||||
} else {
|
||||
holder.binding.toggleTruncate.setVisibility(View.GONE);
|
||||
}
|
||||
|
@ -2505,6 +2488,32 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
|
||||
}
|
||||
|
||||
private static void resizeContent(Context context, StatusViewHolder holder, Status statusToDeal, RecyclerView.Adapter<RecyclerView.ViewHolder> adapter) {
|
||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
int truncate_toots_size = sharedpreferences.getInt(context.getString(R.string.SET_TRUNCATE_TOOTS_SIZE), 0);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a broadcast to other open fragments that content a timeline
|
||||
*
|
||||
|
|
|
@ -7,3 +7,4 @@ Changed:
|
|||
|
||||
Fixed:
|
||||
- Cache view with large fonts
|
||||
- Bad behaviors with truncated messages
|
Loading…
Reference in a new issue