some changes

This commit is contained in:
Thomas 2022-07-18 14:13:12 +02:00
parent dd924cba20
commit 8e0808dcda
13 changed files with 41 additions and 145 deletions

View file

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

View file

@ -325,8 +325,7 @@ public class AdminReportActivity extends BaseActivity {
binding.accountDn.setText(
account.getSpanDisplayName(AdminReportActivity.this,
new WeakReference<>(binding.accountDn),
id -> binding.accountDn.invalidate()),
new WeakReference<>(binding.accountDn)),
TextView.BufferType.SPANNABLE);
binding.accountUn.setText(String.format("@%s", account.acct));
binding.accountUn.setOnLongClickListener(v -> {

View file

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

View file

@ -79,32 +79,16 @@ public class Account implements Serializable {
@SerializedName("moved")
public Account moved;
public transient boolean emojiDisplayNameFetched = false;
public transient boolean emojiNoteFetched = false;
//Some extra spannable element - They will be filled automatically when fetching the account
private transient Spannable span_display_name;
private transient Spannable span_note;
public synchronized Spannable getSpanDisplayName(Context context, WeakReference<View> viewWeakReference, SpannableHelper.EmojiCallback callback) {
if (span_display_name != null) {
return span_display_name;
}
public synchronized Spannable getSpanDisplayName(Context context, WeakReference<View> viewWeakReference) {
if (display_name == null) {
display_name = username;
}
span_display_name = SpannableHelper.convert(context, display_name, null, this, true, viewWeakReference, !emojiDisplayNameFetched ? callback : null);
emojiDisplayNameFetched = true;
return span_display_name;
return SpannableHelper.convert(context, display_name, null, this, true, viewWeakReference);
}
public synchronized Spannable getSpanNote(Context context, WeakReference<View> viewWeakReference, SpannableHelper.EmojiCallback callback) {
if (span_note != null) {
return span_note;
}
span_note = SpannableHelper.convert(context, note, null, this, true, viewWeakReference, !emojiNoteFetched ? callback : null);
emojiNoteFetched = true;
return span_note;
public synchronized Spannable getSpanNote(Context context, WeakReference<View> viewWeakReference) {
return SpannableHelper.convert(context, note, null, this, true, viewWeakReference);
}
public transient RelationShip relationShip;

View file

@ -58,16 +58,10 @@ public class Poll implements Serializable {
@SerializedName("votes_count")
public int votes_count;
//Some extra spannable element - They will be filled automatically when fetching the poll
public transient Spannable span_title;
public transient boolean emojiTitleFetched = false;
public Spannable span_title;
public Spannable getSpanTitle(Context context, Status status, WeakReference<View> viewWeakReference, SpannableHelper.EmojiCallback callback) {
if (span_title != null) {
return span_title;
}
span_title = SpannableHelper.convert(context, title, status, null, true, viewWeakReference, !emojiTitleFetched ? callback : null);
emojiTitleFetched = true;
public Spannable getSpanTitle(Context context, Status status, WeakReference<View> viewWeakReference) {
span_title = SpannableHelper.convert(context, title, status, null, true, viewWeakReference);
return span_title;
}
}

View file

@ -93,9 +93,6 @@ public class Status implements Serializable, Cloneable {
public Attachment art_attachment;
public transient boolean emojiContentFetched = false;
public transient boolean emojiSpoilerFetched = false;
public transient boolean emojiTranslateFetched = false;
public boolean isExpended = false;
public boolean isTruncated = true;
public boolean isFetchMore = false;
@ -110,44 +107,22 @@ public class Status implements Serializable, Cloneable {
public transient int cursorPosition = 0;
public transient boolean submitted = false;
//Some extra spannable element - They will be filled automatically when fetching the status
private transient Spannable span_content;
private transient Spannable span_spoiler_text;
private transient Spannable span_translate;
public synchronized Spannable getSpanContent(Context context, WeakReference<View> viewWeakReference, SpannableHelper.EmojiCallback callback) {
if (span_content != null) {
return span_content;
}
span_content = SpannableHelper.convert(context, content, this, null, true, viewWeakReference, !emojiContentFetched ? callback : null);
emojiContentFetched = true;
return span_content;
public synchronized Spannable getSpanContent(Context context, WeakReference<View> viewWeakReference) {
return SpannableHelper.convert(context, content, this, null, true, viewWeakReference);
}
public Spannable getSpanContentNitter() {
if (span_content != null) {
return span_content;
}
span_content = SpannableHelper.convertNitter(content);
return span_content;
return SpannableHelper.convertNitter(content);
}
public synchronized Spannable getSpanSpoiler(Context context, WeakReference<View> viewWeakReference, SpannableHelper.EmojiCallback callback) {
if (span_spoiler_text != null) {
return span_spoiler_text;
}
span_spoiler_text = SpannableHelper.convert(context, spoiler_text, this, null, true, viewWeakReference, !emojiSpoilerFetched ? callback : null);
emojiSpoilerFetched = true;
return span_spoiler_text;
public synchronized Spannable getSpanSpoiler(Context context, WeakReference<View> viewWeakReference) {
return SpannableHelper.convert(context, spoiler_text, this, null, true, viewWeakReference);
}
public synchronized Spannable getSpanTranslate(Context context, WeakReference<View> viewWeakReference, SpannableHelper.EmojiCallback callback) {
if (span_translate != null) {
return span_translate;
}
span_translate = SpannableHelper.convert(context, translationContent, this, null, true, viewWeakReference, !emojiTranslateFetched ? callback : null);
emojiTranslateFetched = true;
return span_translate;
public synchronized Spannable getSpanTranslate(Context context, WeakReference<View> viewWeakReference) {
return SpannableHelper.convert(context, translationContent, this, null, true, viewWeakReference);
}
@NonNull

View file

@ -40,7 +40,6 @@ import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.text.style.ImageSpan;
import android.text.style.URLSpan;
import android.util.Log;
import android.util.Patterns;
import android.view.LayoutInflater;
import android.view.View;
@ -88,8 +87,7 @@ public class SpannableHelper {
public static Spannable convert(Context context, String text,
Status status, Account account,
boolean convertHtml,
WeakReference<View> viewWeakReference,
EmojiCallback listener) {
WeakReference<View> viewWeakReference) {
SpannableString initialContent;
if (text == null) {
@ -97,16 +95,13 @@ public class SpannableHelper {
}
SpannableStringBuilder content;
View view = viewWeakReference.get();
String id = null;
List<Mention> mentionList = null;
List<Emoji> emojiList = null;
if (status != null) {
mentionList = status.mentions;
emojiList = status.emojis;
id = status.id;
} else if (account != null) {
emojiList = account.emojis;
id = account.id;
}
HashMap<String, String> urlDetails = new HashMap<>();
if (convertHtml) {
@ -142,24 +137,12 @@ public class SpannableHelper {
if (emojiList != null && emojiList.size() > 0) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean animate = !sharedpreferences.getBoolean(context.getString(R.string.SET_DISABLE_ANIMATED_EMOJI), false);
int count = 1;
for (Emoji emoji : emojiList) {
int finalCount = count;
List<Emoji> finalEmojiList = emojiList;
String finalId = id;
List<Emoji> finalEmojiList1 = emojiList;
Glide.with(context)
.asDrawable()
.load(animate ? emoji.url : emoji.static_url)
.into(
new CustomTarget<Drawable>() {
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
super.onLoadFailed(errorDrawable);
if (finalCount == finalEmojiList.size() && listener != null) {
listener.transformationDone(finalId);
}
}
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
@ -202,11 +185,7 @@ public class SpannableHelper {
((Animatable) resource).start();
}
Log.v(Helper.TAG, ">: " + emoji.shortcode + " --> " + listener + " - " + finalCount + " <> " + finalEmojiList1.size());
if (finalCount == finalEmojiList.size() && listener != null) {
Log.v(Helper.TAG, "OK FOR: " + emoji.shortcode + " --> " + finalId);
listener.transformationDone(finalId);
}
}
@Override
@ -215,7 +194,6 @@ public class SpannableHelper {
}
}
);
count++;
}
}
return trimSpannable(new SpannableStringBuilder(content));
@ -677,9 +655,4 @@ public class SpannableHelper {
}
return spannableString;
}
public interface EmojiCallback {
void transformationDone(String id);
}
}

View file

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

View file

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

View file

@ -1043,22 +1043,19 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
StatusSimpleViewHolder holder = (StatusSimpleViewHolder) viewHolder;
holder.binding.statusContent.setText(
status.getSpanContent(context,
new WeakReference<>(holder.binding.statusContent),
id -> notifyItemChanged(position)),
new WeakReference<>(holder.binding.statusContent)),
TextView.BufferType.SPANNABLE);
MastodonHelper.loadPPMastodon(holder.binding.avatar, status.account);
holder.binding.displayName.setText(
status.account.getSpanDisplayName(context,
new WeakReference<>(holder.binding.displayName),
id -> notifyItemChanged(position)),
new WeakReference<>(holder.binding.displayName)),
TextView.BufferType.SPANNABLE);
holder.binding.username.setText(String.format("@%s", status.account.acct));
if (status.spoiler_text != null && !status.spoiler_text.trim().isEmpty()) {
holder.binding.spoiler.setVisibility(View.VISIBLE);
holder.binding.spoiler.setText(
status.getSpanSpoiler(context,
new WeakReference<>(holder.binding.spoiler),
id -> notifyItemChanged(position)),
new WeakReference<>(holder.binding.spoiler)),
TextView.BufferType.SPANNABLE);
} else {
holder.binding.spoiler.setVisibility(View.GONE);

View file

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

View file

@ -144,8 +144,7 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
MastodonHelper.loadPPMastodon(holderFollow.binding.avatar, notification.account);
holderFollow.binding.displayName.setText(
notification.account.getSpanDisplayName(context,
new WeakReference<>(holderFollow.binding.displayName),
id -> notifyItemChanged(getPositionAsync(notificationList, id))),
new WeakReference<>(holderFollow.binding.displayName)),
TextView.BufferType.SPANNABLE);
holderFollow.binding.username.setText(String.format("@%s", notification.account.acct));
if (getItemViewType(position) == TYPE_FOLLOW_REQUEST) {
@ -217,8 +216,7 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
notification.account.display_name = title;
holderStatus.bindingNotification.status.displayName.setText(
notification.account.getSpanDisplayName(context,
new WeakReference<>(holderStatus.bindingNotification.status.displayName),
id -> holderStatus.bindingNotification.status.displayName.post(() -> notifyItemChanged(getPositionAsync(notificationList, id)))),
new WeakReference<>(holderStatus.bindingNotification.status.displayName)),
TextView.BufferType.SPANNABLE);
holderStatus.bindingNotification.status.username.setText(String.format("@%s", notification.account.acct));
holderStatus.bindingNotification.containerTransparent.setAlpha(.1f);
@ -289,8 +287,7 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
notification.account.display_name = title;
holderStatus.bindingNotification.status.displayName.setText(
notification.account.getSpanDisplayName(context,
new WeakReference<>(holderStatus.bindingNotification.status.displayName),
id -> holderStatus.bindingNotification.status.displayName.post(() -> notifyItemChanged(getPositionAsync(notificationList, id)))),
new WeakReference<>(holderStatus.bindingNotification.status.displayName)),
TextView.BufferType.SPANNABLE);
holderStatus.bindingNotification.status.displayName.setText(title, TextView.BufferType.SPANNABLE);
holderStatus.bindingNotification.status.username.setText(String.format("@%s", notification.account.acct));

View file

@ -40,7 +40,6 @@ import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
@ -747,8 +746,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.displayName.setText(
statusToDeal.account.getSpanDisplayName(context,
new WeakReference<>(holder.binding.displayName),
id -> holder.binding.displayName.post(() -> adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, id)))),
new WeakReference<>(holder.binding.displayName)),
TextView.BufferType.SPANNABLE);
if (theme_text_header_1_line != -1) {
holder.binding.displayName.setTextColor(theme_text_header_1_line);
@ -816,8 +814,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.spoiler.setVisibility(View.VISIBLE);
holder.binding.spoiler.setText(
statusToDeal.getSpanSpoiler(context,
new WeakReference<>(holder.binding.spoiler),
id -> holder.binding.spoiler.post(() -> adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, id)))),
new WeakReference<>(holder.binding.spoiler)),
TextView.BufferType.SPANNABLE);
statusToDeal.isExpended = true;
statusToDeal.isMediaDisplayed = true;
@ -832,8 +829,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.spoiler.setText(
statusToDeal.getSpanSpoiler(context,
new WeakReference<>(holder.binding.spoiler),
id -> holder.binding.spoiler.post(() -> adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, id)))),
new WeakReference<>(holder.binding.spoiler)),
TextView.BufferType.SPANNABLE);
}
if (statusToDeal.isExpended) {
@ -853,8 +849,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.statusBoosterDisplayName.setText(
status.account.getSpanDisplayName(context,
new WeakReference<>(holder.binding.statusBoosterDisplayName),
id -> holder.binding.statusBoosterDisplayName.post(() -> adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, id)))),
new WeakReference<>(holder.binding.statusBoosterDisplayName)),
TextView.BufferType.SPANNABLE);
holder.binding.statusBoosterInfo.setVisibility(View.VISIBLE);
@ -890,12 +885,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
//--- MAIN CONTENT ---
holder.binding.statusContent.setText(
statusToDeal.getSpanContent(context,
new WeakReference<>(holder.binding.statusContent),
id -> holder.binding.statusContent.post(() -> {
Log.v(Helper.TAG, "notifiy: " + id);
Log.v(Helper.TAG, "position: " + getPositionAsync(notificationList, statusList, id));
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, id));
})),
new WeakReference<>(holder.binding.statusContent)),
TextView.BufferType.SPANNABLE);
if (truncate_toots_size > 0) {
holder.binding.statusContent.setMaxLines(truncate_toots_size);
@ -929,8 +919,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.containerTrans.setVisibility(View.VISIBLE);
holder.binding.statusContentTranslated.setText(
statusToDeal.getSpanTranslate(context,
new WeakReference<>(holder.binding.statusContentTranslated),
id -> holder.binding.statusContentTranslated.post(() -> adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, id)))),
new WeakReference<>(holder.binding.statusContentTranslated)),
TextView.BufferType.SPANNABLE);
} else {
holder.binding.containerTrans.setVisibility(View.GONE);
@ -1195,8 +1184,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}
pollItemBinding.pollItemText.setText(
pollItem.getSpanTitle(context, statusToDeal,
new WeakReference<>(pollItemBinding.pollItemText),
id -> pollItemBinding.pollItemText.post(() -> adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, id)))),
new WeakReference<>(pollItemBinding.pollItemText)),
TextView.BufferType.SPANNABLE);
pollItemBinding.pollItemValue.setProgress((int) value);
if (pollItem.votes_count == greaterValue) {
@ -1227,8 +1215,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
cb.setButtonTintList(ThemeHelper.getButtonColorStateList(context));
cb.setText(
pollOption.getSpanTitle(context, statusToDeal,
new WeakReference<>(cb),
id -> cb.post(() -> adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, id)))),
new WeakReference<>(cb)),
TextView.BufferType.SPANNABLE);
holder.binding.poll.multipleChoice.addView(cb);
}
@ -1242,8 +1229,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
rb.setButtonTintList(ThemeHelper.getButtonColorStateList(context));
rb.setText(
pollOption.getSpanTitle(context, statusToDeal,
new WeakReference<>(rb),
id -> rb.post(() -> adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, id)))),
new WeakReference<>(rb)),
TextView.BufferType.SPANNABLE);
holder.binding.poll.singleChoiceRadioGroup.addView(rb);
@ -1846,8 +1832,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
.into(holder.bindingArt.artMedia);
holder.bindingArt.artAcct.setText(
status.account.getSpanDisplayName(context,
new WeakReference<>(holder.bindingArt.artAcct),
id -> holder.bindingArt.artAcct.post(() -> notifyItemChanged(getPositionAsync(null, statusList, id)))),
new WeakReference<>(holder.bindingArt.artAcct)),
TextView.BufferType.SPANNABLE);
holder.bindingArt.artUsername.setText(String.format(Locale.getDefault(), "@%s", status.account.acct));
holder.bindingArt.artPp.setOnClickListener(v -> {