diff --git a/app/src/main/java/app/fedilab/android/activities/AdminAccountActivity.java b/app/src/main/java/app/fedilab/android/activities/AdminAccountActivity.java index 94e63ecfc..b31c8194e 100644 --- a/app/src/main/java/app/fedilab/android/activities/AdminAccountActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/AdminAccountActivity.java @@ -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 -> { diff --git a/app/src/main/java/app/fedilab/android/activities/AdminReportActivity.java b/app/src/main/java/app/fedilab/android/activities/AdminReportActivity.java index 4feea554c..e3c97445e 100644 --- a/app/src/main/java/app/fedilab/android/activities/AdminReportActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/AdminReportActivity.java @@ -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 -> { diff --git a/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java b/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java index 7371dbbdf..2d8930499 100644 --- a/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java @@ -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()); diff --git a/app/src/main/java/app/fedilab/android/client/entities/api/Account.java b/app/src/main/java/app/fedilab/android/client/entities/api/Account.java index 5450e7a26..94623d4b0 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/api/Account.java +++ b/app/src/main/java/app/fedilab/android/client/entities/api/Account.java @@ -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 viewWeakReference, SpannableHelper.EmojiCallback callback) { - if (span_display_name != null) { - return span_display_name; - } + public synchronized Spannable getSpanDisplayName(Context context, WeakReference 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 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 viewWeakReference) { + return SpannableHelper.convert(context, note, null, this, true, viewWeakReference); } public transient RelationShip relationShip; diff --git a/app/src/main/java/app/fedilab/android/client/entities/api/Poll.java b/app/src/main/java/app/fedilab/android/client/entities/api/Poll.java index 7df3e7c03..4cd8cff9f 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/api/Poll.java +++ b/app/src/main/java/app/fedilab/android/client/entities/api/Poll.java @@ -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 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 viewWeakReference) { + span_title = SpannableHelper.convert(context, title, status, null, true, viewWeakReference); return span_title; } } diff --git a/app/src/main/java/app/fedilab/android/client/entities/api/Status.java b/app/src/main/java/app/fedilab/android/client/entities/api/Status.java index 159feea2d..a1e3e70d9 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/api/Status.java +++ b/app/src/main/java/app/fedilab/android/client/entities/api/Status.java @@ -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 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 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 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 viewWeakReference) { + return SpannableHelper.convert(context, spoiler_text, this, null, true, viewWeakReference); } - public synchronized Spannable getSpanTranslate(Context context, WeakReference 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 viewWeakReference) { + return SpannableHelper.convert(context, translationContent, this, null, true, viewWeakReference); } @NonNull diff --git a/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java b/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java index 39fec6469..8c9a5bbe3 100644 --- a/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java @@ -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 viewWeakReference, - EmojiCallback listener) { + WeakReference viewWeakReference) { SpannableString initialContent; if (text == null) { @@ -97,16 +95,13 @@ public class SpannableHelper { } SpannableStringBuilder content; View view = viewWeakReference.get(); - String id = null; List mentionList = null; List 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 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 finalEmojiList = emojiList; - String finalId = id; - List finalEmojiList1 = emojiList; Glide.with(context) .asDrawable() .load(animate ? emoji.url : emoji.static_url) .into( new CustomTarget() { - @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 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); - } } diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/AccountAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/AccountAdapter.java index 53b7303d9..872980879 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/AccountAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/AccountAdapter.java @@ -227,14 +227,12 @@ public class AccountAdapter extends RecyclerView.Adapter(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); } diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/AccountListAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/AccountListAdapter.java index cbcaef6e4..356d880cb 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/AccountListAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/AccountListAdapter.java @@ -81,8 +81,7 @@ public class AccountListAdapter extends RecyclerView.Adapter(holder.binding.displayName), - id -> notifyItemChanged(position)), + new WeakReference<>(holder.binding.displayName)), TextView.BufferType.SPANNABLE); holder.binding.username.setText(String.format("@%s", account.acct)); diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java index d1e667221..f6f41080d 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java @@ -1043,22 +1043,19 @@ public class ComposeAdapter extends RecyclerView.Adapter(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); diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/ConversationAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/ConversationAdapter.java index 561e34b2c..94e1d748e 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/ConversationAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/ConversationAdapter.java @@ -140,8 +140,7 @@ public class ConversationAdapter extends RecyclerView.Adapter(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(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)); diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java index d383571e1..194e94b4f 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java @@ -144,8 +144,7 @@ public class NotificationAdapter extends RecyclerView.Adapter(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(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(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)); diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java index bd373a09d..e6963e266 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java @@ -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 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 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 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 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 //--- 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 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 } 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 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 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 .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 -> {