bad behavior with truncated messages
This commit is contained in:
parent
545fbe588c
commit
7195f03501
|
@ -1359,36 +1359,19 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
if (truncate_toots_size > 0) {
|
if (truncate_toots_size > 0) {
|
||||||
holder.binding.statusContent.setMaxLines(truncate_toots_size);
|
holder.binding.statusContent.setMaxLines(truncate_toots_size);
|
||||||
holder.binding.statusContent.setEllipsize(TextUtils.TruncateAt.END);
|
holder.binding.statusContent.setEllipsize(TextUtils.TruncateAt.END);
|
||||||
|
if (holder.binding.statusContent.getLineCount() == 0) {
|
||||||
holder.binding.statusContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
holder.binding.statusContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onGlobalLayout() {
|
public void onGlobalLayout() {
|
||||||
if (holder.binding.statusContent.getLineCount() > 1) {
|
if (holder.binding.statusContent.getLineCount() > 1) {
|
||||||
holder.binding.statusContent.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
holder.binding.statusContent.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||||
if (holder.binding.statusContent.getLineCount() > truncate_toots_size) {
|
resizeContent(context, holder, statusToDeal, adapter);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
resizeContent(context, holder, statusToDeal, adapter);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
holder.binding.toggleTruncate.setVisibility(View.GONE);
|
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
|
* Send a broadcast to other open fragments that content a timeline
|
||||||
*
|
*
|
||||||
|
|
|
@ -7,3 +7,4 @@ Changed:
|
||||||
|
|
||||||
Fixed:
|
Fixed:
|
||||||
- Cache view with large fonts
|
- Cache view with large fonts
|
||||||
|
- Bad behaviors with truncated messages
|
Loading…
Reference in New Issue