Show bio instead of fields in non-mutual pre-reply sheet
This commit is contained in:
parent
2063dbd0b0
commit
20697fb334
|
@ -9,8 +9,8 @@ android {
|
||||||
applicationId "org.joinmastodon.android"
|
applicationId "org.joinmastodon.android"
|
||||||
minSdk 23
|
minSdk 23
|
||||||
targetSdk 33
|
targetSdk 33
|
||||||
versionCode 77
|
versionCode 78
|
||||||
versionName "2.2.1"
|
versionName "2.2.2"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
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"
|
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"
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,7 @@ package org.joinmastodon.android.ui;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Typeface;
|
|
||||||
import android.text.SpannableStringBuilder;
|
|
||||||
import android.text.TextUtils;
|
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.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -18,7 +13,6 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import org.joinmastodon.android.R;
|
import org.joinmastodon.android.R;
|
||||||
import org.joinmastodon.android.model.Account;
|
import org.joinmastodon.android.model.Account;
|
||||||
import org.joinmastodon.android.model.AccountField;
|
|
||||||
import org.joinmastodon.android.ui.text.HtmlParser;
|
import org.joinmastodon.android.ui.text.HtmlParser;
|
||||||
import org.joinmastodon.android.ui.utils.UiUtils;
|
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||||
|
|
||||||
|
@ -28,6 +22,8 @@ import me.grishka.appkit.imageloader.requests.UrlImageLoaderRequest;
|
||||||
import me.grishka.appkit.utils.V;
|
import me.grishka.appkit.utils.V;
|
||||||
|
|
||||||
public class NonMutualPreReplySheet extends PreReplySheet{
|
public class NonMutualPreReplySheet extends PreReplySheet{
|
||||||
|
private boolean fullBioShown=false;
|
||||||
|
|
||||||
@SuppressLint("DefaultLocale")
|
@SuppressLint("DefaultLocale")
|
||||||
public NonMutualPreReplySheet(@NonNull Context context, ResultListener resultListener, Account account){
|
public NonMutualPreReplySheet(@NonNull Context context, ResultListener resultListener, Account account){
|
||||||
super(context, resultListener);
|
super(context, resultListener);
|
||||||
|
@ -62,30 +58,33 @@ public class NonMutualPreReplySheet extends PreReplySheet{
|
||||||
name.setText(account.displayName);
|
name.setText(account.displayName);
|
||||||
name.setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
|
name.setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
|
||||||
nameAndFields.addView(name, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, V.dp(24)));
|
nameAndFields.addView(name, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, V.dp(24)));
|
||||||
if(account.fields!=null && !account.fields.isEmpty()){
|
if(!TextUtils.isEmpty(account.note)){
|
||||||
for(AccountField field:account.fields){
|
String strippedBio=HtmlParser.stripAndRemoveInvisibleSpans(account.note);
|
||||||
LinearLayout fieldView=new LinearLayout(context);
|
TextView bioShort=new TextView(context);
|
||||||
fieldView.setOrientation(LinearLayout.HORIZONTAL);
|
bioShort.setTextAppearance(R.style.m3_body_medium);
|
||||||
TextView key=new TextView(context);
|
bioShort.setTextColor(UiUtils.getThemeColor(context, R.attr.colorM3Secondary));
|
||||||
key.setTextAppearance(R.style.m3_body_medium);
|
bioShort.setMaxLines(2);
|
||||||
key.setTextColor(UiUtils.getThemeColor(context, R.attr.colorM3Secondary));
|
bioShort.setEllipsize(TextUtils.TruncateAt.END);
|
||||||
key.setSingleLine();
|
bioShort.setText(strippedBio);
|
||||||
key.setEllipsize(TextUtils.TruncateAt.END);
|
nameAndFields.addView(bioShort, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||||
key.setText(field.name);
|
|
||||||
key.setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
|
TextView bioFull=new TextView(context);
|
||||||
key.setPaddingRelative(0, 0, V.dp(8), 0);
|
bioFull.setTextAppearance(R.style.m3_body_medium);
|
||||||
fieldView.addView(key, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
bioFull.setTextColor(UiUtils.getThemeColor(context, R.attr.colorM3Secondary));
|
||||||
TextView value=new TextView(context);
|
bioFull.setText(strippedBio);
|
||||||
value.setTextAppearance(R.style.m3_body_medium);
|
bioFull.setVisibility(View.GONE);
|
||||||
value.setTypeface(Typeface.create("sans-serif-medium", Typeface.NORMAL));
|
nameAndFields.addView(bioFull, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||||
value.setTextColor(UiUtils.getThemeColor(context, R.attr.colorM3Secondary));
|
nameAndFields.setOnClickListener(v->{
|
||||||
value.setSingleLine();
|
UiUtils.beginLayoutTransition((ViewGroup) getWindow().getDecorView());
|
||||||
value.setEllipsize(TextUtils.TruncateAt.END);
|
fullBioShown=!fullBioShown;
|
||||||
value.setText(HtmlParser.stripAndRemoveInvisibleSpans(field.value));
|
if(fullBioShown){
|
||||||
value.setGravity(Gravity.CENTER_VERTICAL | Gravity.END);
|
bioFull.setVisibility(View.VISIBLE);
|
||||||
fieldView.addView(value, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1f));
|
bioShort.setVisibility(View.GONE);
|
||||||
nameAndFields.addView(fieldView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, V.dp(20)));
|
}else{
|
||||||
}
|
bioFull.setVisibility(View.GONE);
|
||||||
|
bioShort.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
});
|
||||||
}else{
|
}else{
|
||||||
TextView username=new TextView(context);
|
TextView username=new TextView(context);
|
||||||
username.setTextAppearance(R.style.m3_body_medium);
|
username.setTextAppearance(R.style.m3_body_medium);
|
||||||
|
|
|
@ -203,8 +203,28 @@ public class HtmlParser{
|
||||||
public static String stripAndRemoveInvisibleSpans(String html){
|
public static String stripAndRemoveInvisibleSpans(String html){
|
||||||
Document doc=Jsoup.parseBodyFragment(html);
|
Document doc=Jsoup.parseBodyFragment(html);
|
||||||
doc.body().select("span.invisible").remove();
|
doc.body().select("span.invisible").remove();
|
||||||
Cleaner cleaner=new Cleaner(Safelist.none());
|
Cleaner cleaner=new Cleaner(Safelist.none().addTags("br", "p"));
|
||||||
return cleaner.clean(doc).body().text();
|
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){
|
public static CharSequence parseLinks(String text){
|
||||||
|
|
Loading…
Reference in New Issue