Show bio instead of fields in non-mutual pre-reply sheet

This commit is contained in:
Grishka 2023-11-18 10:58:09 +03:00
parent 2063dbd0b0
commit 20697fb334
3 changed files with 53 additions and 34 deletions

View File

@ -9,8 +9,8 @@ android {
applicationId "org.joinmastodon.android"
minSdk 23
targetSdk 33
versionCode 77
versionName "2.2.1"
versionCode 78
versionName "2.2.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
resConfigs "ar-rSA", "be-rBY", "bn-rBD", "bs-rBA", "ca-rES", "cs-rCZ", "da-rDK", "de-rDE", "el-rGR", "es-rES", "eu-rES", "fa-rIR", "fi-rFI", "fil-rPH", "fr-rFR", "ga-rIE", "gd-rGB", "gl-rES", "hi-rIN", "hr-rHR", "hu-rHU", "hy-rAM", "ig-rNG", "in-rID", "is-rIS", "it-rIT", "iw-rIL", "ja-rJP", "kab", "ko-rKR", "my-rMM", "nl-rNL", "no-rNO", "oc-rFR", "pl-rPL", "pt-rBR", "pt-rPT", "ro-rRO", "ru-rRU", "si-rLK", "sl-rSI", "sv-rSE", "th-rTH", "tr-rTR", "uk-rUA", "ur-rIN", "vi-rVN", "zh-rCN", "zh-rTW"
}

View File

@ -2,12 +2,7 @@ package org.joinmastodon.android.ui;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Typeface;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.TextAppearanceSpan;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
@ -18,7 +13,6 @@ import android.widget.TextView;
import org.joinmastodon.android.R;
import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.model.AccountField;
import org.joinmastodon.android.ui.text.HtmlParser;
import org.joinmastodon.android.ui.utils.UiUtils;
@ -28,6 +22,8 @@ import me.grishka.appkit.imageloader.requests.UrlImageLoaderRequest;
import me.grishka.appkit.utils.V;
public class NonMutualPreReplySheet extends PreReplySheet{
private boolean fullBioShown=false;
@SuppressLint("DefaultLocale")
public NonMutualPreReplySheet(@NonNull Context context, ResultListener resultListener, Account account){
super(context, resultListener);
@ -62,30 +58,33 @@ public class NonMutualPreReplySheet extends PreReplySheet{
name.setText(account.displayName);
name.setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
nameAndFields.addView(name, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, V.dp(24)));
if(account.fields!=null && !account.fields.isEmpty()){
for(AccountField field:account.fields){
LinearLayout fieldView=new LinearLayout(context);
fieldView.setOrientation(LinearLayout.HORIZONTAL);
TextView key=new TextView(context);
key.setTextAppearance(R.style.m3_body_medium);
key.setTextColor(UiUtils.getThemeColor(context, R.attr.colorM3Secondary));
key.setSingleLine();
key.setEllipsize(TextUtils.TruncateAt.END);
key.setText(field.name);
key.setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
key.setPaddingRelative(0, 0, V.dp(8), 0);
fieldView.addView(key, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
TextView value=new TextView(context);
value.setTextAppearance(R.style.m3_body_medium);
value.setTypeface(Typeface.create("sans-serif-medium", Typeface.NORMAL));
value.setTextColor(UiUtils.getThemeColor(context, R.attr.colorM3Secondary));
value.setSingleLine();
value.setEllipsize(TextUtils.TruncateAt.END);
value.setText(HtmlParser.stripAndRemoveInvisibleSpans(field.value));
value.setGravity(Gravity.CENTER_VERTICAL | Gravity.END);
fieldView.addView(value, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1f));
nameAndFields.addView(fieldView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, V.dp(20)));
if(!TextUtils.isEmpty(account.note)){
String strippedBio=HtmlParser.stripAndRemoveInvisibleSpans(account.note);
TextView bioShort=new TextView(context);
bioShort.setTextAppearance(R.style.m3_body_medium);
bioShort.setTextColor(UiUtils.getThemeColor(context, R.attr.colorM3Secondary));
bioShort.setMaxLines(2);
bioShort.setEllipsize(TextUtils.TruncateAt.END);
bioShort.setText(strippedBio);
nameAndFields.addView(bioShort, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
TextView bioFull=new TextView(context);
bioFull.setTextAppearance(R.style.m3_body_medium);
bioFull.setTextColor(UiUtils.getThemeColor(context, R.attr.colorM3Secondary));
bioFull.setText(strippedBio);
bioFull.setVisibility(View.GONE);
nameAndFields.addView(bioFull, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
nameAndFields.setOnClickListener(v->{
UiUtils.beginLayoutTransition((ViewGroup) getWindow().getDecorView());
fullBioShown=!fullBioShown;
if(fullBioShown){
bioFull.setVisibility(View.VISIBLE);
bioShort.setVisibility(View.GONE);
}else{
bioFull.setVisibility(View.GONE);
bioShort.setVisibility(View.VISIBLE);
}
});
}else{
TextView username=new TextView(context);
username.setTextAppearance(R.style.m3_body_medium);

View File

@ -203,8 +203,28 @@ public class HtmlParser{
public static String stripAndRemoveInvisibleSpans(String html){
Document doc=Jsoup.parseBodyFragment(html);
doc.body().select("span.invisible").remove();
Cleaner cleaner=new Cleaner(Safelist.none());
return cleaner.clean(doc).body().text();
Cleaner cleaner=new Cleaner(Safelist.none().addTags("br", "p"));
StringBuilder sb=new StringBuilder();
cleaner.clean(doc).body().traverse(new NodeVisitor(){
@Override
public void head(Node node, int depth){
if(node instanceof TextNode tn){
sb.append(tn.text());
}else if(node instanceof Element el){
if("br".equals(el.tagName())){
sb.append('\n');
}
}
}
@Override
public void tail(Node node, int depth){
if(node instanceof Element el && "p".equals(el.tagName()) && el.nextSibling()!=null){
sb.append("\n\n");
}
}
});
return sb.toString();
}
public static CharSequence parseLinks(String text){