remove weak references

This commit is contained in:
Thomas 2025-05-29 11:01:48 +02:00
parent 2ff3e10303
commit 60db57a42f
23 changed files with 114 additions and 124 deletions

View file

@ -1290,7 +1290,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
if (!isFinishing()) { if (!isFinishing()) {
headerMainBinding.accountName.setText( headerMainBinding.accountName.setText(
Helper.getCurrentAccount(BaseMainActivity.this).mastodon_account.getSpanDisplayNameEmoji(BaseMainActivity.this, Helper.getCurrentAccount(BaseMainActivity.this).mastodon_account.getSpanDisplayNameEmoji(BaseMainActivity.this,
new WeakReference<>(headerMainBinding.accountName)), headerMainBinding.accountName),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
} }
float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f); float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f);

View file

@ -523,7 +523,7 @@ public class ProfileActivity extends BaseActivity {
binding.accountDn.setText( binding.accountDn.setText(
account.getSpanDisplayNameEmoji(ProfileActivity.this, account.getSpanDisplayNameEmoji(ProfileActivity.this,
new WeakReference<>(binding.accountDn)), binding.accountDn),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
binding.accountUn.setText(String.format("@%s", account.acct)); binding.accountUn.setText(String.format("@%s", account.acct));
@ -540,7 +540,7 @@ public class ProfileActivity extends BaseActivity {
}); });
binding.accountNote.setText( binding.accountNote.setText(
account.getSpanNote(ProfileActivity.this, account.getSpanNote(ProfileActivity.this,
new WeakReference<>(binding.accountNote)), binding.accountNote),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
binding.accountNote.setMovementMethod(LinkMovementMethod.getInstance()); binding.accountNote.setMovementMethod(LinkMovementMethod.getInstance());

View file

@ -324,7 +324,7 @@ public class AdminAccountActivity extends BaseActivity {
binding.accountDn.setText( binding.accountDn.setText(
adminAccount.account.getSpanDisplayNameEmoji(AdminAccountActivity.this, adminAccount.account.getSpanDisplayNameEmoji(AdminAccountActivity.this,
new WeakReference<>(binding.accountDn)), binding.accountDn),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
binding.accountUn.setText(String.format("@%s", adminAccount.account.acct)); binding.accountUn.setText(String.format("@%s", adminAccount.account.acct));
binding.accountUn.setOnLongClickListener(v -> { binding.accountUn.setOnLongClickListener(v -> {

View file

@ -337,7 +337,7 @@ public class AdminReportActivity extends BaseBarActivity {
binding.accountDn.setText( binding.accountDn.setText(
account.getSpanDisplayNameEmoji(AdminReportActivity.this, account.getSpanDisplayNameEmoji(AdminReportActivity.this,
new WeakReference<>(binding.accountDn)), binding.accountDn),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
binding.accountUn.setText(String.format("@%s", account.acct)); binding.accountUn.setText(String.format("@%s", account.acct));
binding.accountUn.setOnLongClickListener(v -> { binding.accountUn.setOnLongClickListener(v -> {

View file

@ -91,26 +91,26 @@ public class Account implements Serializable {
public transient String pronouns = null; public transient String pronouns = null;
public synchronized Spannable getSpanDisplayName(Context context, WeakReference<View> viewWeakReference) { public synchronized Spannable getSpanDisplayName(Context context, View view) {
if (display_name == null || display_name.isEmpty()) { if (display_name == null || display_name.isEmpty()) {
display_name = username; display_name = username;
} }
return SpannableHelper.convert(context, display_name, null, this, null, viewWeakReference, true, false); return SpannableHelper.convert(context, display_name, null, this, null, view, true, false);
} }
public synchronized Spannable getSpanDisplayNameEmoji(Activity activity, WeakReference<View> viewWeakReference) { public synchronized Spannable getSpanDisplayNameEmoji(Activity activity, View view) {
if (display_name == null || display_name.isEmpty()) { if (display_name == null || display_name.isEmpty()) {
display_name = username; display_name = username;
} }
return SpannableHelper.convertEmoji(activity, display_name, this, viewWeakReference); return SpannableHelper.convertEmoji(activity, display_name, this, view);
} }
public synchronized Spannable getSpanDisplayNameTitle(Context context, WeakReference<View> viewWeakReference, String title) { public synchronized Spannable getSpanDisplayNameTitle(Context context, View view, String title) {
return SpannableHelper.convert(context, title, null, this, null, viewWeakReference, true, false); return SpannableHelper.convert(context, title, null, this, null, view, true, false);
} }
public synchronized Spannable getSpanNote(Context context, WeakReference<View> viewWeakReference) { public synchronized Spannable getSpanNote(Context context, View view) {
return SpannableHelper.convert(context, note, null, this, null, viewWeakReference, true, false); return SpannableHelper.convert(context, note, null, this, null, view, true, false);
} }

View file

@ -55,8 +55,8 @@ public class Announcement {
public List<Reaction> reactions; public List<Reaction> reactions;
public synchronized Spannable getSpanContent(Context context, WeakReference<View> viewWeakReference) { public synchronized Spannable getSpanContent(Context context, View view) {
return SpannableHelper.convert(context, content, null, null, this, viewWeakReference, true, false); return SpannableHelper.convert(context, content, null, null, this, view, true, false);
} }
} }

View file

@ -42,12 +42,12 @@ public class Field implements Serializable {
private transient ForegroundColorSpan value_span; private transient ForegroundColorSpan value_span;
private transient ForegroundColorSpan name_span; private transient ForegroundColorSpan name_span;
public synchronized Spannable getValueSpan(Context context, Account account, WeakReference<View> viewWeakReference) { public synchronized Spannable getValueSpan(Context context, Account account, View view) {
if (verified_at != null && value != null) { if (verified_at != null && value != null) {
value_span = new ForegroundColorSpan(ContextCompat.getColor(context, R.color.verified_text)); value_span = new ForegroundColorSpan(ContextCompat.getColor(context, R.color.verified_text));
} }
Spannable spannable = SpannableHelper.convert(context, value, null, account, null, viewWeakReference, true, false); Spannable spannable = SpannableHelper.convert(context, value, null, account, null, view, true, false);
if (value_span != null && spannable != null) { if (value_span != null && spannable != null) {
spannable.setSpan(value_span, 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(value_span, 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} }
@ -55,9 +55,9 @@ public class Field implements Serializable {
} }
public synchronized Spannable getLabelSpan(Context context, Account account, WeakReference<View> viewWeakReference) { public synchronized Spannable getLabelSpan(Context context, Account account, View view) {
Spannable spannable = SpannableHelper.convert(context, name, null, account, null, viewWeakReference, true, false); Spannable spannable = SpannableHelper.convert(context, name, null, account, null, view, true, false);
if (name_span != null && spannable != null) { if (name_span != null && spannable != null) {
spannable.setSpan(name_span, 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(name_span, 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} }

View file

@ -60,8 +60,8 @@ public class Poll implements Serializable {
public transient Spannable span_title; public transient Spannable span_title;
public Spannable getSpanTitle(Context context, Status status, WeakReference<View> viewWeakReference) { public Spannable getSpanTitle(Context context, Status status,View view) {
span_title = SpannableHelper.convert(context, title, status, null, null, viewWeakReference, false, false); span_title = SpannableHelper.convert(context, title, status, null, null, view, false, false);
return span_title; return span_title;
} }
} }

View file

@ -155,23 +155,23 @@ public class Status implements Serializable, Cloneable {
return same; return same;
} }
public synchronized Spannable getSpanContent(Context context, boolean checkRemotely, WeakReference<View> viewWeakReference) { public synchronized Spannable getSpanContent(Context context, boolean checkRemotely, View view) {
if (contentSpan == null) { if (contentSpan == null) {
contentSpan = SpannableHelper.convert(context, content, this, null, null, checkRemotely, viewWeakReference, true, true); contentSpan = SpannableHelper.convert(context, content, this, null, null, checkRemotely, view, true, true);
} }
return contentSpan; return contentSpan;
} }
public synchronized Spannable getSpanSpoiler(Context context, WeakReference<View> viewWeakReference) { public synchronized Spannable getSpanSpoiler(Context context, View view) {
if (contentSpoilerSpan == null) { if (contentSpoilerSpan == null) {
contentSpoilerSpan = SpannableHelper.convert(context, spoiler_text, this, null, null, viewWeakReference, true, false); contentSpoilerSpan = SpannableHelper.convert(context, spoiler_text, this, null, null, view, true, false);
} }
return contentSpoilerSpan; return contentSpoilerSpan;
} }
public synchronized Spannable getSpanTranslate(Context context, WeakReference<View> viewWeakReference) { public synchronized Spannable getSpanTranslate(Context context, View view) {
if (contentTranslateSpan == null) { if (contentTranslateSpan == null) {
contentTranslateSpan = SpannableHelper.convert(context, translationContent, this, null, null, viewWeakReference, true, true); contentTranslateSpan = SpannableHelper.convert(context, translationContent, this, null, null, view, true, true);
} }
return contentTranslateSpan; return contentTranslateSpan;
} }

View file

@ -6,7 +6,6 @@ import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.drawable.Animatable; import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.text.SpannableStringBuilder;
import android.text.style.ReplacementSpan; import android.text.style.ReplacementSpan;
import android.view.View; import android.view.View;
@ -14,28 +13,21 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.target.Target; import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition; import com.bumptech.glide.request.transition.Transition;
import java.lang.ref.WeakReference;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.mastodon.client.entities.api.Emoji;
public class CustomImageSpan extends ReplacementSpan { public class CustomImageSpan extends ReplacementSpan {
private final WeakReference<View> viewWeakReference;
private float scale; private float scale;
private Drawable imageDrawable; private Drawable imageDrawable;
CustomImageSpan(WeakReference<View> viewWeakReference) { CustomImageSpan(View view) {
Context mContext = viewWeakReference.get().getContext(); Context mContext = view.getContext();
this.viewWeakReference = viewWeakReference;
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(mContext); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
scale = sharedpreferences.getFloat(mContext.getString(R.string.SET_FONT_SCALE), 1.1f); scale = sharedpreferences.getFloat(mContext.getString(R.string.SET_FONT_SCALE), 1.1f);
if (scale > 1.3f) { if (scale > 1.3f) {
@ -43,20 +35,6 @@ public class CustomImageSpan extends ReplacementSpan {
} }
} }
public void makeEmoji(SpannableStringBuilder content, Emoji emoji, boolean animate) {
if (emoji != null) {
Matcher matcher = Pattern.compile(":" + emoji.shortcode + ":", Pattern.LITERAL)
.matcher(content);
while (matcher.find()) {
CustomImageSpan customEmoji = new CustomImageSpan(new WeakReference<>(viewWeakReference.get()));
content.setSpan(customEmoji, matcher.start(), matcher.end(), 0);
Glide.with(viewWeakReference.get())
.asDrawable()
.load(animate ? emoji.url : emoji.static_url)
.into(customEmoji.getTarget(animate));
}
}
}
@Override @Override
public int getSize(@NonNull Paint paint, CharSequence charSequence, int i, int i1, @Nullable Paint.FontMetricsInt fontMetricsInt) { public int getSize(@NonNull Paint paint, CharSequence charSequence, int i, int i1, @Nullable Paint.FontMetricsInt fontMetricsInt) {
@ -84,45 +62,48 @@ public class CustomImageSpan extends ReplacementSpan {
} }
} }
public Target<Drawable> getTarget(boolean animate) { public Target<Drawable> getTarget(View view, boolean animate) {
return new CustomTarget<>() { return new CustomTarget<>() {
@Override
public void onStart() {
super.onStart();
if(imageDrawable instanceof Animatable) {
((Animatable) imageDrawable).start();
}
}
@Override
public void onStop() {
super.onStop();
if(imageDrawable instanceof Animatable) {
((Animatable) imageDrawable).stop();
}
}
@Override @Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) { public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
View view = viewWeakReference.get();
if (animate && resource instanceof Animatable) { if (animate && resource instanceof Animatable) {
Drawable.Callback drawableCallBack = resource.getCallback();
resource.setCallback(new Drawable.Callback() { resource.setCallback(new Drawable.Callback() {
@Override @Override
public void invalidateDrawable(@NonNull Drawable drawable) { public void invalidateDrawable(@NonNull Drawable drawable) {
if (drawableCallBack != null) { view.invalidate();
drawableCallBack.invalidateDrawable(drawable);
}
if(view != null) {
view.invalidate();
}
} }
@Override @Override
public void scheduleDrawable(@NonNull Drawable drawable, @NonNull Runnable runnable, long l) { public void scheduleDrawable(@NonNull Drawable drawable, @NonNull Runnable runnable, long l) {
if (drawableCallBack != null) { view.postDelayed(runnable,l);
drawableCallBack.scheduleDrawable(drawable, runnable, l);
}
} }
@Override @Override
public void unscheduleDrawable(@NonNull Drawable drawable, @NonNull Runnable runnable) { public void unscheduleDrawable(@NonNull Drawable drawable, @NonNull Runnable runnable) {
if (drawableCallBack != null) { view.removeCallbacks(runnable);
drawableCallBack.unscheduleDrawable(drawable, runnable);
}
} }
}); });
((Animatable) resource).start(); ((Animatable) resource).start();
} }
imageDrawable = resource; imageDrawable = resource;
if (view != null) { view.invalidate();
view.invalidate();
}
} }
@Override @Override

View file

@ -109,13 +109,13 @@ public class SpannableHelper {
public static Spannable convert(Context context, String text, public static Spannable convert(Context context, String text,
Status status, Account account, Announcement announcement, Status status, Account account, Announcement announcement,
WeakReference<View> viewWeakReference, boolean convertHtml, boolean convertMarkdown) { View view, boolean convertHtml, boolean convertMarkdown) {
return convert(context, text, status, account, announcement, false, viewWeakReference, convertHtml, convertMarkdown); return convert(context, text, status, account, announcement, false, view, convertHtml, convertMarkdown);
} }
public static Spannable convert(Context context, String text, public static Spannable convert(Context context, String text,
Status status, Account account, Announcement announcement, boolean checkRemotely, Status status, Account account, Announcement announcement, boolean checkRemotely,
WeakReference<View> viewWeakReference, boolean convertHtml, boolean convertMarkdown) { View view, boolean convertHtml, boolean convertMarkdown) {
if (text == null) { if (text == null) {
return null; return null;
} }
@ -375,25 +375,34 @@ public class SpannableHelper {
} }
boolean animate = !sharedpreferences.getBoolean(context.getString(R.string.SET_DISABLE_ANIMATED_EMOJI), false); boolean animate = !sharedpreferences.getBoolean(context.getString(R.string.SET_DISABLE_ANIMATED_EMOJI), false);
if(emojiList != null) { if(emojiList != null) {
emojiList.forEach(emoji -> { for(Emoji emoji: emojiList) {
CustomImageSpan customImageSpan = new CustomImageSpan(viewWeakReference);
customImageSpan.makeEmoji(content, emoji, animate);
});
}
Matcher matcher = Pattern.compile(":" + emoji.shortcode + ":", Pattern.LITERAL)
.matcher(content);
while (matcher.find()) {
CustomImageSpan customImageSpan = new CustomImageSpan(view);
content.setSpan(customImageSpan, matcher.start(), matcher.end(), 0);
Glide.with(context)
.asDrawable()
.load(animate ? emoji.url : emoji.static_url)
.into(customImageSpan.getTarget(view, animate));
}
}
}
CustomImageSpan customImageSpan = new CustomImageSpan(view);
if (!imagesToReplace.isEmpty()) { if (!imagesToReplace.isEmpty()) {
for (Map.Entry<String, String> entry : imagesToReplace.entrySet()) { for (Map.Entry<String, String> entry : imagesToReplace.entrySet()) {
CustomImageSpan customImageSpan = new CustomImageSpan(viewWeakReference);
String key = entry.getKey(); String key = entry.getKey();
String url = entry.getValue(); String url = entry.getValue();
Matcher matcher = Pattern.compile(key, Pattern.LITERAL) Matcher matcher = Pattern.compile(key, Pattern.LITERAL)
.matcher(content); .matcher(content);
while (matcher.find()) { while (matcher.find()) {
content.setSpan(customImageSpan, matcher.start(), matcher.end(), 0); content.setSpan(customImageSpan, matcher.start(), matcher.end(), 0);
Glide.with(viewWeakReference.get().getContext()) Glide.with(context)
.asDrawable() .asDrawable()
.load(url) .load(url)
.into(customImageSpan.getTarget(animate)); .into(customImageSpan.getTarget(view, false));
} }
} }
@ -979,7 +988,7 @@ public class SpannableHelper {
} }
public static Spannable convertEmoji(Activity activity, String text, Account account, WeakReference<View> viewWeakReference) { public static Spannable convertEmoji(Activity activity, String text, Account account, View view) {
SpannableString initialContent; SpannableString initialContent;
if (text == null) { if (text == null) {
@ -999,13 +1008,13 @@ public class SpannableHelper {
Matcher matcher = Pattern.compile(":" + emoji.shortcode + ":", Pattern.LITERAL) Matcher matcher = Pattern.compile(":" + emoji.shortcode + ":", Pattern.LITERAL)
.matcher(content); .matcher(content);
while (matcher.find()) { while (matcher.find()) {
CustomImageSpan customImageSpan = new CustomImageSpan(viewWeakReference); CustomImageSpan customImageSpan = new CustomImageSpan(view);
content.setSpan(customImageSpan, matcher.start(), matcher.end(), 0); content.setSpan(customImageSpan, matcher.start(), matcher.end(), 0);
if (Helper.isValidContextForGlide(activity)) { if (Helper.isValidContextForGlide(activity)) {
Glide.with(viewWeakReference.get().getContext()) Glide.with(view.getContext())
.asDrawable() .asDrawable()
.load(animate ? emoji.url : emoji.static_url) .load(animate ? emoji.url : emoji.static_url)
.into(customImageSpan.getTarget(animate)); .into(customImageSpan.getTarget(view, animate));
} }
} }
} }

View file

@ -309,12 +309,12 @@ public class AccountAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
} }
accountViewHolder.binding.displayName.setText( accountViewHolder.binding.displayName.setText(
account.getSpanDisplayName(context, account.getSpanDisplayName(context,
new WeakReference<>(accountViewHolder.binding.displayName)), accountViewHolder.binding.displayName),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
accountViewHolder.binding.username.setText(String.format("@%s", account.acct)); accountViewHolder.binding.username.setText(String.format("@%s", account.acct));
accountViewHolder.binding.bio.setText( accountViewHolder.binding.bio.setText(
account.getSpanNote(context, account.getSpanNote(context,
new WeakReference<>(accountViewHolder.binding.bio)), accountViewHolder.binding.bio),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
} }

View file

@ -91,7 +91,7 @@ public class AccountListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
MastodonHelper.loadPPMastodon(holder.binding.avatar, account); MastodonHelper.loadPPMastodon(holder.binding.avatar, account);
holder.binding.displayName.setText( holder.binding.displayName.setText(
account.getSpanDisplayName(context, account.getSpanDisplayName(context,
new WeakReference<>(holder.binding.displayName)), holder.binding.displayName),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
holder.binding.username.setText(String.format("@%s", account.acct)); holder.binding.username.setText(String.format("@%s", account.acct));

View file

@ -102,7 +102,7 @@ public class AnnouncementAdapter extends RecyclerView.Adapter<AnnouncementAdapte
} }
holder.binding.content.setText( holder.binding.content.setText(
announcement.getSpanContent(context, announcement.getSpanContent(context,
new WeakReference<>(holder.binding.content)), holder.binding.content),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
if (announcement.starts_at != null) { if (announcement.starts_at != null) {
String dateIni; String dateIni;

View file

@ -1418,14 +1418,14 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
} }
holder.binding.statusContent.setText( holder.binding.statusContent.setText(
status.getSpanContent(context, false, status.getSpanContent(context, false,
new WeakReference<>(holder.binding.statusContent)), holder.binding.statusContent),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
holder.binding.statusContent.setMovementMethod(LongClickLinkMovementMethod.getInstance()); holder.binding.statusContent.setMovementMethod(LongClickLinkMovementMethod.getInstance());
MastodonHelper.loadPPMastodon(holder.binding.avatar, status.account); MastodonHelper.loadPPMastodon(holder.binding.avatar, status.account);
if (status.account != null) { if (status.account != null) {
holder.binding.displayName.setText( holder.binding.displayName.setText(
status.account.getSpanDisplayName(context, status.account.getSpanDisplayName(context,
new WeakReference<>(holder.binding.displayName)), holder.binding.displayName),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
holder.binding.username.setText(String.format("@%s", status.account.acct)); holder.binding.username.setText(String.format("@%s", status.account.acct));
} }
@ -1434,7 +1434,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
holder.binding.spoiler.setVisibility(View.VISIBLE); holder.binding.spoiler.setVisibility(View.VISIBLE);
holder.binding.spoiler.setText( holder.binding.spoiler.setText(
status.getSpanSpoiler(context, status.getSpanSpoiler(context,
new WeakReference<>(holder.binding.spoiler)), holder.binding.spoiler),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
} else { } else {
holder.binding.spoiler.setVisibility(View.GONE); holder.binding.spoiler.setVisibility(View.GONE);

View file

@ -199,7 +199,7 @@ public class ConversationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
holder.binding.spoiler.setVisibility(View.VISIBLE); holder.binding.spoiler.setVisibility(View.VISIBLE);
holder.binding.spoiler.setText( holder.binding.spoiler.setText(
conversation.last_status.getSpanSpoiler(context, conversation.last_status.getSpanSpoiler(context,
new WeakReference<>(holder.binding.spoiler)), holder.binding.spoiler),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
} else { } else {
holder.binding.spoiler.setVisibility(View.GONE); holder.binding.spoiler.setVisibility(View.GONE);
@ -209,7 +209,7 @@ public class ConversationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
//--- MAIN CONTENT --- //--- MAIN CONTENT ---
holder.binding.statusContent.setText( holder.binding.statusContent.setText(
conversation.last_status.getSpanContent(context, false, conversation.last_status.getSpanContent(context, false,
new WeakReference<>(holder.binding.statusContent)), holder.binding.statusContent),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
//--- DATE --- //--- DATE ---
holder.binding.lastMessageDate.setText(Helper.dateDiff(context, conversation.last_status.created_at)); holder.binding.lastMessageDate.setText(Helper.dateDiff(context, conversation.last_status.created_at));

View file

@ -72,13 +72,13 @@ public class FieldAdapter extends RecyclerView.Adapter<FieldAdapter.FieldViewHol
holder.binding.value.setText( holder.binding.value.setText(
field.getValueSpan(context, account, field.getValueSpan(context, account,
new WeakReference<>(holder.binding.value)), holder.binding.value),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
holder.binding.value.setMovementMethod(LinkMovementMethod.getInstance()); holder.binding.value.setMovementMethod(LinkMovementMethod.getInstance());
holder.binding.label.setText( holder.binding.label.setText(
field.getLabelSpan(context, account, field.getLabelSpan(context, account,
new WeakReference<>(holder.binding.label)), holder.binding.label),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
holder.binding.label.setMovementMethod(LinkMovementMethod.getInstance()); holder.binding.label.setMovementMethod(LinkMovementMethod.getInstance());
} }

View file

@ -251,7 +251,7 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
MastodonHelper.loadPPMastodon(holderFollow.binding.avatar, notification.account); MastodonHelper.loadPPMastodon(holderFollow.binding.avatar, notification.account);
holderFollow.binding.displayName.setText( holderFollow.binding.displayName.setText(
notification.account.getSpanDisplayName(context, notification.account.getSpanDisplayName(context,
new WeakReference<>(holderFollow.binding.displayName)), holderFollow.binding.displayName),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
holderFollow.binding.username.setText(String.format("@%s", notification.account.acct)); holderFollow.binding.username.setText(String.format("@%s", notification.account.acct));
@ -415,7 +415,7 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
} }
holderStatus.bindingNotification.status.displayName.setText( holderStatus.bindingNotification.status.displayName.setText(
notification.account.getSpanDisplayNameTitle(context, notification.account.getSpanDisplayNameTitle(context,
new WeakReference<>(holderStatus.bindingNotification.status.displayName), title), holderStatus.bindingNotification.status.displayName, title),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
holderStatus.bindingNotification.status.username.setText(String.format("@%s", notification.account.acct)); holderStatus.bindingNotification.status.username.setText(String.format("@%s", notification.account.acct));
@ -494,7 +494,7 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
}); });
holderStatus.bindingNotification.status.displayName.setText( holderStatus.bindingNotification.status.displayName.setText(
notification.account.getSpanDisplayNameTitle(context, notification.account.getSpanDisplayNameTitle(context,
new WeakReference<>(holderStatus.bindingNotification.status.displayName), title), holderStatus.bindingNotification.status.displayName, title),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
holderStatus.bindingNotification.status.username.setText(String.format("@%s", notification.account.acct)); holderStatus.bindingNotification.status.username.setText(String.format("@%s", notification.account.acct));
holderStatus.bindingNotification.status.actionButtons.setVisibility(View.GONE); holderStatus.bindingNotification.status.actionButtons.setVisibility(View.GONE);

View file

@ -604,13 +604,13 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.quotedMessage.cardviewContainer.setStrokeColor(ThemeHelper.getAttColor(context, R.attr.colorPrimary)); holder.binding.quotedMessage.cardviewContainer.setStrokeColor(ThemeHelper.getAttColor(context, R.attr.colorPrimary));
holder.binding.quotedMessage.statusContent.setText( holder.binding.quotedMessage.statusContent.setText(
statusToDeal.quote.getSpanContent(context, remote, statusToDeal.quote.getSpanContent(context, remote,
new WeakReference<>(holder.binding.quotedMessage.statusContent)), holder.binding.quotedMessage.statusContent),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
MastodonHelper.loadPPMastodon(holder.binding.quotedMessage.avatar, statusToDeal.quote.account); MastodonHelper.loadPPMastodon(holder.binding.quotedMessage.avatar, statusToDeal.quote.account);
if (statusToDeal.quote.account != null) { if (statusToDeal.quote.account != null) {
holder.binding.quotedMessage.displayName.setText( holder.binding.quotedMessage.displayName.setText(
statusToDeal.quote.account.getSpanDisplayName(context, statusToDeal.quote.account.getSpanDisplayName(context,
new WeakReference<>(holder.binding.quotedMessage.displayName)), holder.binding.quotedMessage.displayName),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
holder.binding.quotedMessage.username.setText(String.format("@%s", statusToDeal.quote.account.acct)); holder.binding.quotedMessage.username.setText(String.format("@%s", statusToDeal.quote.account.acct));
} }
@ -619,7 +619,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.quotedMessage.spoiler.setVisibility(View.VISIBLE); holder.binding.quotedMessage.spoiler.setVisibility(View.VISIBLE);
holder.binding.quotedMessage.spoiler.setText( holder.binding.quotedMessage.spoiler.setText(
statusToDeal.quote.getSpanSpoiler(context, statusToDeal.quote.getSpanSpoiler(context,
new WeakReference<>(holder.binding.quotedMessage.spoiler)), holder.binding.quotedMessage.spoiler),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
} else { } else {
holder.binding.quotedMessage.spoiler.setVisibility(View.GONE); holder.binding.quotedMessage.spoiler.setVisibility(View.GONE);
@ -1258,7 +1258,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.displayName.setText( holder.binding.displayName.setText(
statusToDeal.account.getSpanDisplayName(context, statusToDeal.account.getSpanDisplayName(context,
new WeakReference<>(holder.binding.displayName)), holder.binding.displayName),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
holder.binding.username.setText(String.format("@%s", statusToDeal.account.acct)); holder.binding.username.setText(String.format("@%s", statusToDeal.account.acct));
//final float scale = context.getResources().getDisplayMetrics().density; //final float scale = context.getResources().getDisplayMetrics().density;
@ -1440,7 +1440,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.spoiler.setVisibility(View.VISIBLE); holder.binding.spoiler.setVisibility(View.VISIBLE);
holder.binding.spoiler.setText( holder.binding.spoiler.setText(
statusToDeal.getSpanSpoiler(context, statusToDeal.getSpanSpoiler(context,
new WeakReference<>(holder.binding.spoiler)), holder.binding.spoiler),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
statusToDeal.isExpended = true; statusToDeal.isExpended = true;
} else { } else {
@ -1453,7 +1453,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.spoiler.setText( holder.binding.spoiler.setText(
statusToDeal.getSpanSpoiler(context, statusToDeal.getSpanSpoiler(context,
new WeakReference<>(holder.binding.spoiler)), holder.binding.spoiler),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
} }
if (statusToDeal.isExpended) { if (statusToDeal.isExpended) {
@ -1477,7 +1477,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} }
holder.binding.statusBoosterDisplayName.setText( holder.binding.statusBoosterDisplayName.setText(
status.account.getSpanDisplayName(context, status.account.getSpanDisplayName(context,
new WeakReference<>(holder.binding.statusBoosterDisplayName)), holder.binding.statusBoosterDisplayName),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
holder.binding.statusBoosterInfo.setVisibility(View.VISIBLE); holder.binding.statusBoosterInfo.setVisibility(View.VISIBLE);
@ -1506,7 +1506,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
//--- MAIN CONTENT --- //--- MAIN CONTENT ---
holder.binding.statusContent.setText( holder.binding.statusContent.setText(
statusToDeal.getSpanContent(context, remote, statusToDeal.getSpanContent(context, remote,
new WeakReference<>(holder.binding.statusContent)), holder.binding.statusContent),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
if (truncate_toots_size > 0) { if (truncate_toots_size > 0) {
holder.binding.statusContent.setMaxLines(truncate_toots_size); holder.binding.statusContent.setMaxLines(truncate_toots_size);
@ -1531,7 +1531,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.containerTrans.setVisibility(View.VISIBLE); holder.binding.containerTrans.setVisibility(View.VISIBLE);
holder.binding.statusContentTranslated.setText( holder.binding.statusContentTranslated.setText(
statusToDeal.getSpanTranslate(context, statusToDeal.getSpanTranslate(context,
new WeakReference<>(holder.binding.statusContentTranslated)), holder.binding.statusContentTranslated),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
} else { } else {
holder.binding.containerTrans.setVisibility(View.GONE); holder.binding.containerTrans.setVisibility(View.GONE);
@ -1955,7 +1955,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
pollItemBinding.pollItemPercent.setText(String.format("%s %%", (int) value)); pollItemBinding.pollItemPercent.setText(String.format("%s %%", (int) value));
pollItemBinding.pollItemText.setText( pollItemBinding.pollItemText.setText(
pollItem.getSpanTitle(context, statusToDeal, pollItem.getSpanTitle(context, statusToDeal,
new WeakReference<>(pollItemBinding.pollItemText)), pollItemBinding.pollItemText),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
pollItemBinding.pollItemValue.setProgress((int) value); pollItemBinding.pollItemValue.setProgress((int) value);
if (pollItem.votes_count == greaterValue) { if (pollItem.votes_count == greaterValue) {
@ -1984,7 +1984,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
CheckBox cb = new CheckBox(context); CheckBox cb = new CheckBox(context);
cb.setText( cb.setText(
pollOption.getSpanTitle(context, statusToDeal, pollOption.getSpanTitle(context, statusToDeal,
new WeakReference<>(cb)), cb),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
holder.binding.poll.multipleChoice.addView(cb); holder.binding.poll.multipleChoice.addView(cb);
} }
@ -1997,7 +1997,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
RadioButton rb = new RadioButton(context); RadioButton rb = new RadioButton(context);
rb.setText( rb.setText(
pollOption.getSpanTitle(context, statusToDeal, pollOption.getSpanTitle(context, statusToDeal,
new WeakReference<>(rb)), rb),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
holder.binding.poll.singleChoiceRadioGroup.addView(rb); holder.binding.poll.singleChoiceRadioGroup.addView(rb);
@ -3378,7 +3378,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} }
holder.bindingArt.artUsername.setText( holder.bindingArt.artUsername.setText(
status.account.getSpanDisplayName(context, status.account.getSpanDisplayName(context,
new WeakReference<>(holder.bindingArt.artUsername)), holder.bindingArt.artUsername),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
holder.bindingArt.artAcct.setText(String.format(Locale.getDefault(), "@%s", status.account.acct)); holder.bindingArt.artAcct.setText(String.format(Locale.getDefault(), "@%s", status.account.acct));
holder.bindingArt.artPp.setOnClickListener(v -> { holder.bindingArt.artPp.setOnClickListener(v -> {
@ -3543,7 +3543,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}); });
holder.bindingPixelfed.artUsername.setText( holder.bindingPixelfed.artUsername.setText(
statusToDeal.account.getSpanDisplayName(context, statusToDeal.account.getSpanDisplayName(context,
new WeakReference<>(holder.bindingPixelfed.artUsername)), holder.bindingPixelfed.artUsername),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
holder.bindingPixelfed.artAcct.setText(String.format(Locale.getDefault(), "@%s", statusToDeal.account.acct)); holder.bindingPixelfed.artAcct.setText(String.format(Locale.getDefault(), "@%s", statusToDeal.account.acct));
holder.bindingPixelfed.artPp.setOnClickListener(v -> { holder.bindingPixelfed.artPp.setOnClickListener(v -> {

View file

@ -241,7 +241,7 @@ public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerVie
status.underlined = true; status.underlined = true;
holder.binding.messageContent.setText( holder.binding.messageContent.setText(
status.getSpanContent(context, false, status.getSpanContent(context, false,
new WeakReference<>(holder.binding.messageContent)), holder.binding.messageContent),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
holder.binding.messageContent.setMovementMethod(LongClickLinkMovementMethod.getInstance()); holder.binding.messageContent.setMovementMethod(LongClickLinkMovementMethod.getInstance());
if (measuredWidth <= 0 && status.media_attachments != null && status.media_attachments.size() > 0) { if (measuredWidth <= 0 && status.media_attachments != null && status.media_attachments.size() > 0) {
@ -370,7 +370,7 @@ public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerVie
pollItemBinding.pollItemPercent.setText(String.format("%s %%", (int) value)); pollItemBinding.pollItemPercent.setText(String.format("%s %%", (int) value));
pollItemBinding.pollItemText.setText( pollItemBinding.pollItemText.setText(
pollItem.getSpanTitle(context, status, pollItem.getSpanTitle(context, status,
new WeakReference<>(pollItemBinding.pollItemText)), pollItemBinding.pollItemText),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
if (status.account.id.equals(MainActivity.currentUserID)) { if (status.account.id.equals(MainActivity.currentUserID)) {
pollItemBinding.pollItemPercent.setTextColor(ThemeHelper.getAttColor(context, R.attr.colorOnPrimary)); pollItemBinding.pollItemPercent.setTextColor(ThemeHelper.getAttColor(context, R.attr.colorOnPrimary));
@ -407,7 +407,7 @@ public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerVie
CheckBox cb = new CheckBox(context); CheckBox cb = new CheckBox(context);
cb.setText( cb.setText(
pollOption.getSpanTitle(context, status, pollOption.getSpanTitle(context, status,
new WeakReference<>(cb)), cb),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
holder.binding.poll.multipleChoice.addView(cb); holder.binding.poll.multipleChoice.addView(cb);
if (status.account.id.equals(MainActivity.currentUserID)) { if (status.account.id.equals(MainActivity.currentUserID)) {
@ -426,7 +426,7 @@ public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerVie
RadioButton rb = new RadioButton(context); RadioButton rb = new RadioButton(context);
rb.setText( rb.setText(
pollOption.getSpanTitle(context, status, pollOption.getSpanTitle(context, status,
new WeakReference<>(rb)), rb),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
if (status.account.id.equals(MainActivity.currentUserID)) { if (status.account.id.equals(MainActivity.currentUserID)) {
@ -524,7 +524,7 @@ public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerVie
} }
holder.binding.userName.setText( holder.binding.userName.setText(
status.account.getSpanDisplayName(context, status.account.getSpanDisplayName(context,
new WeakReference<>(holder.binding.userName)), holder.binding.userName),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
if (status.media_attachments != null && status.media_attachments.size() > 0) { if (status.media_attachments != null && status.media_attachments.size() > 0) {

View file

@ -56,13 +56,13 @@ public class StatusHistoryAdapter extends RecyclerView.Adapter<RecyclerView.View
Status status = statuses.get(position); Status status = statuses.get(position);
holder.binding.statusContent.setText( holder.binding.statusContent.setText(
status.getSpanContent(context, false, status.getSpanContent(context, false,
new WeakReference<>(holder.binding.statusContent)), holder.binding.statusContent),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
if (status.spoiler_text != null && !status.spoiler_text.trim().isEmpty()) { if (status.spoiler_text != null && !status.spoiler_text.trim().isEmpty()) {
holder.binding.spoiler.setVisibility(View.VISIBLE); holder.binding.spoiler.setVisibility(View.VISIBLE);
holder.binding.spoiler.setText( holder.binding.spoiler.setText(
status.getSpanSpoiler(context, status.getSpanSpoiler(context,
new WeakReference<>(holder.binding.spoiler)), holder.binding.spoiler),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
} else { } else {
holder.binding.spoiler.setVisibility(View.GONE); holder.binding.spoiler.setVisibility(View.GONE);
@ -72,7 +72,7 @@ public class StatusHistoryAdapter extends RecyclerView.Adapter<RecyclerView.View
if (status.account != null) { if (status.account != null) {
holder.binding.displayName.setText( holder.binding.displayName.setText(
status.account.getSpanDisplayName(context, status.account.getSpanDisplayName(context,
new WeakReference<>(holder.binding.displayName)), holder.binding.displayName),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
holder.binding.username.setText(String.format("@%s", status.account.acct)); holder.binding.username.setText(String.format("@%s", status.account.acct));
} }

View file

@ -101,12 +101,12 @@ public class SuggestionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
} }
holder.binding.displayName.setText( holder.binding.displayName.setText(
account.getSpanDisplayName(context, account.getSpanDisplayName(context,
new WeakReference<>(holder.binding.displayName)), holder.binding.displayName),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
holder.binding.username.setText(String.format("@%s", account.acct)); holder.binding.username.setText(String.format("@%s", account.acct));
holder.binding.bio.setText( holder.binding.bio.setText(
account.getSpanNote(context, account.getSpanNote(context,
new WeakReference<>(holder.binding.bio)), holder.binding.bio),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
holder.binding.followAction.setOnClickListener(v -> { holder.binding.followAction.setOnClickListener(v -> {

View file

@ -73,7 +73,7 @@ public class ReportAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.accountDn.setText( holder.binding.accountDn.setText(
report.account.account.getSpanDisplayName(context, report.account.account.getSpanDisplayName(context,
new WeakReference<>(holder.binding.accountDn)), holder.binding.accountDn),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
MastodonHelper.loadPPMastodon(holder.binding.accountPp, target_account); MastodonHelper.loadPPMastodon(holder.binding.accountPp, target_account);