measure text manually

hopefully fix sk22#422
This commit is contained in:
sk
2023-03-17 00:51:22 +01:00
parent d5b6c02b22
commit 6fef51fcbb
3 changed files with 13 additions and 15 deletions

View File

@@ -503,7 +503,6 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
holder.getItem().status.textExpandable = expandable; holder.getItem().status.textExpandable = expandable;
HeaderStatusDisplayItem.Holder header = findHolderOfType(holder.getItemID(), HeaderStatusDisplayItem.Holder.class); HeaderStatusDisplayItem.Holder header = findHolderOfType(holder.getItemID(), HeaderStatusDisplayItem.Holder.class);
if (header != null) header.rebind(); if (header != null) header.rebind();
holder.rebind();
} }
} }

View File

@@ -98,9 +98,11 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
private final float textMaxHeight, textCollapsedHeight; private final float textMaxHeight, textCollapsedHeight;
private final LinearLayout.LayoutParams collapseParams, wrapParams; private final LinearLayout.LayoutParams collapseParams, wrapParams;
private final ViewGroup parent;
public Holder(Activity activity, ViewGroup parent){ public Holder(Activity activity, ViewGroup parent){
super(activity, R.layout.display_item_text, parent); super(activity, R.layout.display_item_text, parent);
this.parent=parent;
text=findViewById(R.id.text); text=findViewById(R.id.text);
spoilerTitle=findViewById(R.id.spoiler_title); spoilerTitle=findViewById(R.id.spoiler_title);
spoilerTitleInline=findViewById(R.id.spoiler_title_inline); spoilerTitleInline=findViewById(R.id.spoiler_title_inline);
@@ -228,19 +230,16 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
readMore.setVisibility(View.GONE); readMore.setVisibility(View.GONE);
} }
if (GlobalUserPreferences.collapseLongPosts) { text.measure(
text.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY),
@Override View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
public boolean onPreDraw() {
text.getViewTreeObserver().removeOnPreDrawListener(this); if (GlobalUserPreferences.collapseLongPosts && !item.status.textExpandable) {
boolean tooBig = text.getMeasuredHeight() > textMaxHeight; boolean tooBig = text.getMeasuredHeight() > textMaxHeight;
boolean inTimeline = !item.textSelectable; boolean inTimeline = !item.textSelectable;
boolean hasSpoiler = !TextUtils.isEmpty(item.status.spoilerText); boolean hasSpoiler = !TextUtils.isEmpty(item.status.spoilerText);
boolean expandable = inTimeline && tooBig && !hasSpoiler; boolean expandable = inTimeline && tooBig && !hasSpoiler;
item.parentFragment.onEnableExpandable(Holder.this, expandable); item.parentFragment.onEnableExpandable(Holder.this, expandable);
return true;
}
});
} }
readMore.setVisibility(item.status.textExpandable && !item.status.textExpanded ? View.VISIBLE : View.GONE); readMore.setVisibility(item.status.textExpandable && !item.status.textExpanded ? View.VISIBLE : View.GONE);

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<dimen name="text_max_height">350dp</dimen> <dimen name="text_max_height">220dp</dimen>
<dimen name="text_collapsed_height">150dp</dimen> <dimen name="text_collapsed_height">150dp</dimen>
</resources> </resources>