diff options
-rw-r--r-- | app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java | 65 | ||||
-rw-r--r-- | src/fdroid/fastlane/metadata/android/en/changelogs/482.txt | 3 |
2 files changed, 39 insertions, 29 deletions
diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java index 9d4295655..ddf67e19f 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java @@ -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 * diff --git a/src/fdroid/fastlane/metadata/android/en/changelogs/482.txt b/src/fdroid/fastlane/metadata/android/en/changelogs/482.txt index 407155f28..020553135 100644 --- a/src/fdroid/fastlane/metadata/android/en/changelogs/482.txt +++ b/src/fdroid/fastlane/metadata/android/en/changelogs/482.txt @@ -6,4 +6,5 @@ Changed: - Fixed: -- Cache view with large fonts
\ No newline at end of file +- Cache view with large fonts +- Bad behaviors with truncated messages
\ No newline at end of file |