fix(instance-info): race condition for collapsing description

This commit is contained in:
FineFindus 2023-05-23 21:39:33 +02:00
parent 818024d8dd
commit c673f08aec
No known key found for this signature in database
GPG Key ID: 64873EE210FF8E6B
1 changed files with 17 additions and 16 deletions

View File

@ -178,7 +178,7 @@ public class InstanceInfoFragment extends LoaderFragment {
if (getActivity() == null || result == null || TextUtils.isEmpty(result.content)) return; if (getActivity() == null || result == null || TextUtils.isEmpty(result.content)) return;
extendedDescription = result.content; extendedDescription = result.content;
updateDescription(); updateDescription();
collapseDescription();
} }
}) })
.execNoAuth(targetDomain); .execNoAuth(targetDomain);
@ -196,7 +196,6 @@ public class InstanceInfoFragment extends LoaderFragment {
description.measure( description.measure(
View.MeasureSpec.makeMeasureSpec(textWrap.getWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(textWrap.getWidth(), View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
} }
@Override @Override
@ -249,21 +248,8 @@ public class InstanceInfoFragment extends LoaderFragment {
uri.setText(instance.title); uri.setText(instance.title);
setTitle(instance.title); setTitle(instance.title);
//set description text and collapse
updateDescription(); updateDescription();
collapseDescription();
textScrollView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
description.measure(
View.MeasureSpec.makeMeasureSpec(textWrap.getWidth(), View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
readMore.setText(isExpanded ? R.string.sk_collapse : R.string.sk_expand);
description.post(() -> {
boolean tooBig = description.getMeasuredHeight() > textMaxHeight;
readMore.setVisibility(tooBig ? View.VISIBLE : View.GONE);
textScrollView.setLayoutParams(tooBig && !isExpanded ? collapseParams : wrapParams);
});
fields.clear(); fields.clear();
@ -307,6 +293,21 @@ public class InstanceInfoFragment extends LoaderFragment {
return HtmlParser.parse(value, account.emojis, Collections.emptyList(), Collections.emptyList(), accountID); return HtmlParser.parse(value, account.emojis, Collections.emptyList(), Collections.emptyList(), accountID);
} }
private void collapseDescription() {
textScrollView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
description.measure(
View.MeasureSpec.makeMeasureSpec(textWrap.getWidth(), View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
readMore.setText(isExpanded ? R.string.sk_collapse : R.string.sk_expand);
description.post(() -> {
boolean tooBig = description.getMeasuredHeight() > textMaxHeight;
readMore.setVisibility(tooBig ? View.VISIBLE : View.GONE);
textScrollView.setLayoutParams(tooBig && !isExpanded ? collapseParams : wrapParams);
});
}
private void updateToolbar(){ private void updateToolbar(){
getToolbar().setBackgroundColor(0); getToolbar().setBackgroundColor(0);
if(toolbarTitleView!=null){ if(toolbarTitleView!=null){