From 6fef51fcbb4c2b88f39cffeb0d601e3c4311da89 Mon Sep 17 00:00:00 2001 From: sk Date: Fri, 17 Mar 2023 00:51:22 +0100 Subject: [PATCH] measure text manually hopefully fix sk22#422 --- .../fragments/BaseStatusListFragment.java | 1 - .../displayitems/TextStatusDisplayItem.java | 25 +++++++++---------- mastodon/src/main/res/values/dimens.xml | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java index 1ff5a2d2e..10cbfee43 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -503,7 +503,6 @@ public abstract class BaseStatusListFragment exten holder.getItem().status.textExpandable = expandable; HeaderStatusDisplayItem.Holder header = findHolderOfType(holder.getItemID(), HeaderStatusDisplayItem.Holder.class); if (header != null) header.rebind(); - holder.rebind(); } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/TextStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/TextStatusDisplayItem.java index 2cc7913fc..c325336bf 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/TextStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/TextStatusDisplayItem.java @@ -98,9 +98,11 @@ public class TextStatusDisplayItem extends StatusDisplayItem{ private final float textMaxHeight, textCollapsedHeight; private final LinearLayout.LayoutParams collapseParams, wrapParams; + private final ViewGroup parent; public Holder(Activity activity, ViewGroup parent){ super(activity, R.layout.display_item_text, parent); + this.parent=parent; text=findViewById(R.id.text); spoilerTitle=findViewById(R.id.spoiler_title); spoilerTitleInline=findViewById(R.id.spoiler_title_inline); @@ -228,19 +230,16 @@ public class TextStatusDisplayItem extends StatusDisplayItem{ readMore.setVisibility(View.GONE); } - if (GlobalUserPreferences.collapseLongPosts) { - text.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { - @Override - public boolean onPreDraw() { - text.getViewTreeObserver().removeOnPreDrawListener(this); - boolean tooBig = text.getMeasuredHeight() > textMaxHeight; - boolean inTimeline = !item.textSelectable; - boolean hasSpoiler = !TextUtils.isEmpty(item.status.spoilerText); - boolean expandable = inTimeline && tooBig && !hasSpoiler; - item.parentFragment.onEnableExpandable(Holder.this, expandable); - return true; - } - }); + text.measure( + View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY), + View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); + + if (GlobalUserPreferences.collapseLongPosts && !item.status.textExpandable) { + boolean tooBig = text.getMeasuredHeight() > textMaxHeight; + boolean inTimeline = !item.textSelectable; + boolean hasSpoiler = !TextUtils.isEmpty(item.status.spoilerText); + boolean expandable = inTimeline && tooBig && !hasSpoiler; + item.parentFragment.onEnableExpandable(Holder.this, expandable); } readMore.setVisibility(item.status.textExpandable && !item.status.textExpanded ? View.VISIBLE : View.GONE); diff --git a/mastodon/src/main/res/values/dimens.xml b/mastodon/src/main/res/values/dimens.xml index a39dcef97..a4c273231 100644 --- a/mastodon/src/main/res/values/dimens.xml +++ b/mastodon/src/main/res/values/dimens.xml @@ -1,5 +1,5 @@ - 350dp + 220dp 150dp \ No newline at end of file