diff --git a/app/src/main/java/app/fedilab/android/activities/ShowAccountActivity.java b/app/src/main/java/app/fedilab/android/activities/ShowAccountActivity.java index 18ee706b0..55f39778d 100644 --- a/app/src/main/java/app/fedilab/android/activities/ShowAccountActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ShowAccountActivity.java @@ -618,7 +618,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt SpannableString spannableString = Helper.clickableElementsDescription(ShowAccountActivity.this, account.getNote()); account.setNoteSpan(spannableString); if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) - account.makeEmojisAccountProfile(ShowAccountActivity.this, ShowAccountActivity.this, account); + account.fillProfileAccount(ShowAccountActivity.this, ShowAccountActivity.this, account); account_note.setText(account.getNoteSpan(), TextView.BufferType.SPANNABLE); account_note.setMovementMethod(LinkMovementMethod.getInstance()); if (!peertubeAccount && tabLayout.getTabAt(0) != null && tabLayout.getTabAt(1) != null && tabLayout.getTabAt(2) != null) { diff --git a/app/src/main/java/app/fedilab/android/activities/ShowConversationActivity.java b/app/src/main/java/app/fedilab/android/activities/ShowConversationActivity.java index 253ecc828..45fe57945 100644 --- a/app/src/main/java/app/fedilab/android/activities/ShowConversationActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ShowConversationActivity.java @@ -111,10 +111,6 @@ public class ShowConversationActivity extends BaseActivity implements OnRetrieve detailsStatus.setFocused(true); //Some spannable Status.fillSpan(new WeakReference<>(ShowConversationActivity.this), detailsStatus); - if (detailsStatus.getPoll() != null) { - Status.makeEmojiPoll(new WeakReference<>(ShowConversationActivity.this), detailsStatus.getPoll()); - } - Account.makeAccountNameEmoji(new WeakReference<>(ShowConversationActivity.this), detailsStatus.getAccount()); if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) { diff --git a/app/src/main/java/app/fedilab/android/asynctasks/RetrieveFeedsAsyncTask.java b/app/src/main/java/app/fedilab/android/asynctasks/RetrieveFeedsAsyncTask.java index 68d3519bf..d7740441e 100644 --- a/app/src/main/java/app/fedilab/android/asynctasks/RetrieveFeedsAsyncTask.java +++ b/app/src/main/java/app/fedilab/android/asynctasks/RetrieveFeedsAsyncTask.java @@ -374,8 +374,6 @@ public class RetrieveFeedsAsyncTask extends AsyncTask { for (app.fedilab.android.client.Entities.Status status : statuses) { app.fedilab.android.client.Entities.Status.fillSpan(contextReference, status); - app.fedilab.android.client.Entities.Status.makeEmojiPoll(contextReference, status.getReblog() != null ? status.getReblog().getPoll() : status.getPoll()); - Account.makeAccountNameEmoji(contextReference, status.getReblog() != null ? status.getReblog().getAccount() : status.getAccount()); } } else { statuses = new ArrayList<>(); diff --git a/app/src/main/java/app/fedilab/android/client/API.java b/app/src/main/java/app/fedilab/android/client/API.java index d5192c4d9..2b9531746 100644 --- a/app/src/main/java/app/fedilab/android/client/API.java +++ b/app/src/main/java/app/fedilab/android/client/API.java @@ -740,7 +740,6 @@ public class API { } catch (JSONException | ParseException e) { e.printStackTrace(); } - Status.makeEmojiPoll(new WeakReference<>(context), poll); return poll; } @@ -1510,11 +1509,6 @@ public class API { } catch (JSONException | ParseException e) { e.printStackTrace(); } - try { - Account.makeAccountNameEmoji(new WeakReference<>(context), account); - } catch (Exception e) { - e.printStackTrace(); - } return account; } diff --git a/app/src/main/java/app/fedilab/android/client/Entities/Account.java b/app/src/main/java/app/fedilab/android/client/Entities/Account.java index 65e9ad7f5..004971521 100644 --- a/app/src/main/java/app/fedilab/android/client/Entities/Account.java +++ b/app/src/main/java/app/fedilab/android/client/Entities/Account.java @@ -200,63 +200,6 @@ public class Account implements Parcelable { this.invited_by_account_id = in.readString(); } - public static void makeAccountNameEmoji(final WeakReference contextWeakReference, Account account) { - Context context = contextWeakReference.get(); - if ((context instanceof Activity && ((Activity) context).isFinishing()) || account == null || account.getDisplay_name() == null) - return; - - account.setDisplayNameSpan(new SpannableString(account.getDisplay_name())); - SpannableString displayNameSpan = account.getDisplayNameSpan(); - if (displayNameSpan == null) - return; - final List emojis = account.getEmojis(); - SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false); - if (emojis != null && emojis.size() > 0) { - final int[] i = {0}; - for (final Emojis emoji : emojis) { - try { - Glide.with(context) - .asDrawable() - .load(disableAnimatedEmoji ? emoji.getStatic_url() : emoji.getUrl()) - .into(new CustomTarget() { - @Override - public void onResourceReady(@NonNull Drawable resource, @Nullable Transition transition) { - final String targetedEmoji = ":" + emoji.getShortcode() + ":"; - if (displayNameSpan.toString().contains(targetedEmoji)) { - //emojis can be used several times so we have to loop - for (int startPosition = -1; (startPosition = displayNameSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) { - final int endPosition = startPosition + targetedEmoji.length(); - if (resource != null && endPosition <= displayNameSpan.toString().length() && endPosition >= startPosition) { - try { - resource.setBounds(0, 0, (int) Helper.convertDpToPixel(20, context), (int) Helper.convertDpToPixel(20, context)); - resource.setVisible(true, true); - ImageSpan imageSpan = new ImageSpan(resource); - displayNameSpan.setSpan( - imageSpan, startPosition, - endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); - } catch (Exception ignored) { - } - return; - } - } - } - } - - @Override - public void onLoadCleared(@Nullable Drawable placeholder) { - - } - - - }); - } catch (Exception e) { - e.printStackTrace(); - } - - } - } - } @Override public int describeContents() { @@ -534,6 +477,9 @@ public class Account implements Parcelable { } public SpannableString getDisplayNameSpan() { + if (this.displayNameSpan == null) { + displayNameSpan = new SpannableString(display_name); + } return displayNameSpan; } @@ -745,15 +691,14 @@ public class Account implements Parcelable { return spannableString; } - public void makeEmojisAccountProfile(final Context context, final OnRetrieveEmojiAccountInterface listener, Account account) { + public void fillProfileAccount(final Context context, final OnRetrieveEmojiAccountInterface listener, Account account) { if (context instanceof Activity && ((Activity) context).isFinishing()) return; if (fields == null) fields = new LinkedHashMap<>(); if (fieldsSpan == null) fieldsSpan = new LinkedHashMap<>(); - if (account.getDisplay_name() != null) - displayNameSpan = new SpannableString(account.getDisplay_name()); + displayNameSpan = account.getDisplayNameSpan(); ArrayList accountsMentionUnknown = new ArrayList<>(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); diff --git a/app/src/main/java/app/fedilab/android/client/Entities/PollOptions.java b/app/src/main/java/app/fedilab/android/client/Entities/PollOptions.java index 90f389e57..496afb283 100644 --- a/app/src/main/java/app/fedilab/android/client/Entities/PollOptions.java +++ b/app/src/main/java/app/fedilab/android/client/Entities/PollOptions.java @@ -74,6 +74,9 @@ public class PollOptions implements Parcelable { } public SpannableString getTitleSpan() { + if( titleSpan == null) { + titleSpan = new SpannableString(title); + } return titleSpan; } diff --git a/app/src/main/java/app/fedilab/android/client/Entities/Status.java b/app/src/main/java/app/fedilab/android/client/Entities/Status.java index 814787918..219c035df 100644 --- a/app/src/main/java/app/fedilab/android/client/Entities/Status.java +++ b/app/src/main/java/app/fedilab/android/client/Entities/Status.java @@ -267,7 +267,6 @@ public class Status implements Parcelable { public static void fillSpan(WeakReference contextWeakReference, Status status) { Status.transform(contextWeakReference, status); - Status.makeEmojis(contextWeakReference, status); Status.makeImage(contextWeakReference, status); } @@ -895,126 +894,6 @@ public class Status implements Parcelable { status.setContentSpanTranslated(contentSpanTranslated); } - private static void makeEmojis(final WeakReference contextWeakReference, Status status) { - Context context = contextWeakReference.get(); - if (context instanceof Activity && ((Activity) context).isFinishing()) - return; - if (status.getReblog() != null && status.getReblog().getEmojis() == null) - return; - if (status.getReblog() == null && status.getEmojis() == null) - return; - final List emojis = status.getReblog() != null ? status.getReblog().getEmojis() : status.getEmojis(); - - SpannableString contentSpan = status.getContentSpan(); - SpannableString contentSpanCW = status.getContentSpanCW(); - SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false); - - - if (emojis != null && emojis.size() > 0) { - final int[] i = {0}; - for (final Emojis emoji : emojis) { - Glide.with(context) - .asDrawable() - .load(disableAnimatedEmoji ? emoji.getStatic_url() : emoji.getUrl()) - .into(new CustomTarget() { - @Override - public void onResourceReady(@NonNull Drawable resource, @Nullable Transition transition) { - final String targetedEmoji = ":" + emoji.getShortcode() + ":"; - if (contentSpan != null && contentSpan.toString().contains(targetedEmoji)) { - //emojis can be used several times so we have to loop - for (int startPosition = -1; (startPosition = contentSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) { - final int endPosition = startPosition + targetedEmoji.length(); - if (endPosition <= contentSpan.toString().length() && endPosition >= startPosition) { - ImageSpan imageSpan; - try { - resource.setBounds(0, 0, (int) Helper.convertDpToPixel(20, context), (int) Helper.convertDpToPixel(20, context)); - resource.setVisible(true, true); - imageSpan = new ImageSpan(resource); - contentSpan.setSpan( - imageSpan, startPosition, - endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); - } catch (Exception ignored) { - } - } - } - } - if (contentSpanCW != null && contentSpanCW.toString().contains(targetedEmoji)) { - //emojis can be used several times so we have to loop - for (int startPosition = -1; (startPosition = contentSpanCW.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) { - final int endPosition = startPosition + targetedEmoji.length(); - if (endPosition <= contentSpanCW.toString().length() && endPosition >= startPosition) { - ImageSpan imageSpan; - resource.setBounds(0, 0, (int) Helper.convertDpToPixel(20, context), (int) Helper.convertDpToPixel(20, context)); - resource.setVisible(true, true); - imageSpan = new ImageSpan(resource); - contentSpanCW.setSpan( - imageSpan, startPosition, - endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); - } - } - } - } - - @Override - public void onLoadCleared(@Nullable Drawable placeholder) { - - } - }); - - } - } - } - - public static void makeEmojiPoll(final WeakReference contextWeakReference, Poll poll) { - Context context = contextWeakReference.get(); - if ((context instanceof Activity && ((Activity) context).isFinishing()) || poll == null || poll.getOptionsList() == null) - return; - final List emojis = poll.getEmojis(); - SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false); - int inc = 0; - for (PollOptions pollOption : poll.getOptionsList()) { - inc++; - SpannableString titleSpan = new SpannableString(pollOption.getTitle()); - if (emojis != null && emojis.size() > 0) { - final int[] i = {0}; - for (final Emojis emoji : emojis) { - Glide.with(context) - .asDrawable() - .load(disableAnimatedEmoji ? emoji.getStatic_url() : emoji.getUrl()) - .into(new CustomTarget() { - @Override - public void onResourceReady(@NonNull Drawable resource, @Nullable Transition transition) { - final String targetedEmoji = ":" + emoji.getShortcode() + ":"; - if (titleSpan.toString().contains(targetedEmoji)) { - //emojis can be used several times so we have to loop - for (int startPosition = -1; (startPosition = titleSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) { - final int endPosition = startPosition + targetedEmoji.length(); - if (endPosition <= titleSpan.toString().length() && endPosition >= startPosition) { - ImageSpan imageSpan; - resource.setBounds(0, 0, (int) Helper.convertDpToPixel(20, context), (int) Helper.convertDpToPixel(20, context)); - resource.setVisible(true, true); - imageSpan = new ImageSpan(resource); - titleSpan.setSpan( - imageSpan, startPosition, - endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); - pollOption.setTitleSpan(titleSpan); - } - } - } - } - - @Override - public void onLoadCleared(@Nullable Drawable placeholder) { - - } - }); - - } - } - } - } private static void makeImage(final WeakReference contextWeakReference, Status status) { Context context = contextWeakReference.get(); @@ -1068,78 +947,6 @@ public class Status implements Parcelable { } - public static void makeEmojisTranslation(final Context context, final OnRetrieveEmojiInterface listener, Status status) { - - if (context instanceof Activity && ((Activity) context).isFinishing()) - return; - SpannableString spannableStringTranslated = null; - if (status.getContentTranslated() != null) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - spannableStringTranslated = new SpannableString(Html.fromHtml(status.getContentTranslated(), Html.FROM_HTML_MODE_LEGACY)); - else - spannableStringTranslated = new SpannableString(Html.fromHtml(status.getContentTranslated())); - } - - final List emojis = status.getReblog() != null ? status.getReblog().getEmojis() : status.getEmojis(); - if (emojis != null && emojis.size() > 0) { - final int[] i = {0}; - for (final Emojis emoji : emojis) { - final SpannableString finalSpannableStringTranslated = spannableStringTranslated; - Glide.with(context) - .asBitmap() - .load(emoji.getUrl()) - .listener(new RequestListener() { - @Override - public boolean onResourceReady(Bitmap resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { - return false; - } - - @Override - public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { - i[0]++; - if (i[0] == (emojis.size())) { - if (finalSpannableStringTranslated != null) - status.setContentSpanTranslated(finalSpannableStringTranslated); - listener.onRetrieveEmoji(status, true); - } - return false; - } - }) - .into(new CustomTarget() { - @Override - public void onResourceReady(@NonNull Bitmap resource, Transition transition) { - final String targetedEmoji = ":" + emoji.getShortcode() + ":"; - - if (finalSpannableStringTranslated != null && finalSpannableStringTranslated.toString().contains(targetedEmoji)) { - //emojis can be used several times so we have to loop - for (int startPosition = -1; (startPosition = finalSpannableStringTranslated.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) { - final int endPosition = startPosition + targetedEmoji.length(); - if (endPosition <= finalSpannableStringTranslated.toString().length() && endPosition >= startPosition) - finalSpannableStringTranslated.setSpan( - new ImageSpan(context, - Bitmap.createScaledBitmap(resource, (int) Helper.convertDpToPixel(20, context), - (int) Helper.convertDpToPixel(20, context), false)), startPosition, - endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); - } - } - i[0]++; - if (i[0] == (emojis.size())) { - if (finalSpannableStringTranslated != null) - status.setContentSpanTranslated(finalSpannableStringTranslated); - status.setEmojiTranslateFound(true); - listener.onRetrieveEmoji(status, true); - } - } - - @Override - public void onLoadCleared(@Nullable Drawable placeholder) { - - } - }); - - } - } - } private static void replaceQuoteSpans(Context context, Spannable spannable) { QuoteSpan[] quoteSpans = spannable.getSpans(0, spannable.length(), QuoteSpan.class); diff --git a/app/src/main/java/app/fedilab/android/drawers/PixelfedListAdapter.java b/app/src/main/java/app/fedilab/android/drawers/PixelfedListAdapter.java index a0f082b98..d28339c5d 100644 --- a/app/src/main/java/app/fedilab/android/drawers/PixelfedListAdapter.java +++ b/app/src/main/java/app/fedilab/android/drawers/PixelfedListAdapter.java @@ -114,6 +114,7 @@ import es.dmoral.toasty.Toasty; import static android.content.Context.MODE_PRIVATE; import static app.fedilab.android.activities.BaseMainActivity.mutedAccount; import static app.fedilab.android.activities.BaseMainActivity.social; +import static app.fedilab.android.helper.Helper.makeEmojis; /** @@ -1063,7 +1064,7 @@ public class PixelfedListAdapter extends RecyclerView.Adapter { - translateToot(status); + translateToot(status, holder.status_content_translated); status.setCustomFeaturesDisplayed(false); notifyStatusChanged(status); }); @@ -1561,6 +1555,7 @@ public class StatusListAdapter extends RecyclerView.Adapter 0) + if (status.getReblog().getAccount().getDisplay_name().length() > 0) { holder.status_account_displayname_owner.setText(displayNameSpan, TextView.BufferType.SPANNABLE); - else + makeEmojis(context, holder.status_account_displayname_owner, status.getReblog() != null ? status.getReblog().getAccount().getDisplayNameSpan() : status.getAccount().getDisplayNameSpan(), status.getReblog() != null ? status.getReblog().getAccount().getEmojis() : status.getAccount().getEmojis()); + }else holder.status_account_displayname_owner.setText(status.getReblog().getAccount().getAcct().replace("@", "")); + holder.status_account_displayname_owner.setVisibility(View.VISIBLE); if (holder.status_boosted_date != null) { holder.status_boosted_date.setText(Helper.dateDiff(context, status.getCreated_at())); @@ -2891,7 +2888,7 @@ public class StatusListAdapter extends RecyclerView.Adapter(activity), account); + + makeEmojis(activity, username, account.getDisplayNameSpan(), account.getEmojis()); username.setText(String.format("@%s", account.getUsername() + "@" + account.getInstance())); displayedName.setText(account.getDisplayNameSpan(), TextView.BufferType.SPANNABLE); loadGiF(activity, account, profilePicture); @@ -4505,4 +4509,63 @@ public class Helper { .show(); } } + + + public static void makeEmojis(Context context, View customTextView, SpannableString contentSpan, List emojis) { + + SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false); + + + if (emojis != null && emojis.size() > 0) { + for (final Emojis emoji : emojis) { + Glide.with(context) + .asDrawable() + .load(disableAnimatedEmoji ? emoji.getStatic_url() : emoji.getUrl()) + .into(new CustomTarget() { + @Override + public void onResourceReady(@NonNull Drawable resource, @Nullable Transition transition) { + final String targetedEmoji = ":" + emoji.getShortcode() + ":"; + if (contentSpan != null && contentSpan.toString().contains(targetedEmoji)) { + //emojis can be used several times so we have to loop + for (int startPosition = -1; (startPosition = contentSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) { + final int endPosition = startPosition + targetedEmoji.length(); + if (endPosition <= contentSpan.toString().length() && endPosition >= startPosition) { + ImageSpan imageSpan; + try { + resource.setBounds(0, 0, (int) Helper.convertDpToPixel(20, context), (int) Helper.convertDpToPixel(20, context)); + resource.setVisible(true, true); + imageSpan = new ImageSpan(resource); + contentSpan.setSpan( + imageSpan, startPosition, + endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); + Log.v(Helper.TAG,emoji.getShortcode() + " -> " + customTextView.getClass().getName()); + if( customTextView instanceof CustomTextView) { + ((CustomTextView)customTextView).setText(contentSpan, TextView.BufferType.SPANNABLE); + }else if (customTextView instanceof RadioButton){ + ((RadioButton)customTextView).setText(contentSpan, TextView.BufferType.SPANNABLE); + }else if (customTextView instanceof CheckBox){ + ((CheckBox)customTextView).setText(contentSpan, TextView.BufferType.SPANNABLE); + }else if (customTextView instanceof TextView){ + ((TextView)customTextView).setText(contentSpan, TextView.BufferType.SPANNABLE); + } + + } catch (Exception ignored) { + } + } + } + } + } + + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { + + } + }); + + } + } + } + + }