Some tries

This commit is contained in:
Thomas 2022-07-11 18:15:55 +02:00
parent 270e722a38
commit aa3c6f07e7
2 changed files with 15 additions and 11 deletions

View File

@ -8,7 +8,6 @@ import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.text.Spannable; import android.text.Spannable;
import android.text.style.ReplacementSpan; import android.text.style.ReplacementSpan;
import android.util.Log;
import android.view.View; import android.view.View;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -31,7 +30,6 @@ import app.fedilab.android.client.entities.api.Emoji;
public class CustomEmoji extends ReplacementSpan { public class CustomEmoji extends ReplacementSpan {
private final View view;
private final float scale; private final float scale;
private Drawable imageDrawable; private Drawable imageDrawable;
private final WeakReference<View> viewWeakReference; private final WeakReference<View> viewWeakReference;
@ -40,21 +38,20 @@ public class CustomEmoji extends ReplacementSpan {
CustomEmoji(WeakReference<View> viewWeakReference) { CustomEmoji(WeakReference<View> viewWeakReference) {
Context mContext = viewWeakReference.get().getContext(); Context mContext = viewWeakReference.get().getContext();
this.viewWeakReference = viewWeakReference; this.viewWeakReference = viewWeakReference;
view = viewWeakReference.get();
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(mContext); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
scale = sharedpreferences.getFloat(mContext.getString(R.string.SET_FONT_SCALE), 1.0f); scale = sharedpreferences.getFloat(mContext.getString(R.string.SET_FONT_SCALE), 1.0f);
} }
public static void displayEmoji(List<Emoji> emojis, Spannable spannableString, View view) { public static void displayEmoji(List<Emoji> emojis, Spannable spannableString, View view) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(view.getContext()); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(view.getContext());
boolean animate = !sharedpreferences.getBoolean(view.getContext().getString(R.string.SET_DISABLE_GIF), false); boolean animate = !sharedpreferences.getBoolean(view.getContext().getString(R.string.SET_DISABLE_ANIMATED_EMOJI), false);
for (Emoji emoji : emojis) { for (Emoji emoji : emojis) {
Matcher matcher = Pattern.compile(":" + emoji.shortcode + ":", Pattern.LITERAL) Matcher matcher = Pattern.compile(":" + emoji.shortcode + ":", Pattern.LITERAL)
.matcher(spannableString); .matcher(spannableString);
while (matcher.find()) { while (matcher.find()) {
CustomEmoji customEmoji = new CustomEmoji(new WeakReference<>(view)); CustomEmoji customEmoji = new CustomEmoji(new WeakReference<>(view));
spannableString.setSpan(customEmoji, matcher.start(), matcher.end(), 0); spannableString.setSpan(customEmoji, matcher.start(), matcher.end(), 0);
Glide.with(view) Glide.with(view.getContext())
.asDrawable() .asDrawable()
.load(animate ? emoji.url : emoji.static_url) .load(animate ? emoji.url : emoji.static_url)
.into(customEmoji.getTarget(animate)); .into(customEmoji.getTarget(animate));
@ -95,8 +92,6 @@ public class CustomEmoji extends ReplacementSpan {
return new CustomTarget<Drawable>() { return new CustomTarget<Drawable>() {
@Override @Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) { public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
Log.v(Helper.TAG, "resource: " + resource);
Log.v(Helper.TAG, "instanceof: " + (resource instanceof Animatable));
View view = viewWeakReference.get(); View view = viewWeakReference.get();
if (animate && resource instanceof Animatable) { if (animate && resource instanceof Animatable) {
Drawable.Callback callback = resource.getCallback(); Drawable.Callback callback = resource.getCallback();

View File

@ -369,9 +369,6 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.actionButtonBoost.setActiveImageTint(R.color.boost_icon); holder.binding.actionButtonBoost.setActiveImageTint(R.color.boost_icon);
holder.binding.actionButtonBookmark.setActiveImageTint(R.color.marked_icon); holder.binding.actionButtonBookmark.setActiveImageTint(R.color.marked_icon);
if (statusToDeal.emojis != null && statusToDeal.emojis.size() > 0) {
CustomEmoji.displayEmoji(statusToDeal.emojis, statusToDeal.span_content, holder.binding.statusContent);
}
if (status.pinned) { if (status.pinned) {
holder.binding.statusPinned.setVisibility(View.VISIBLE); holder.binding.statusPinned.setVisibility(View.VISIBLE);
@ -881,7 +878,19 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
break; break;
} }
//--- MAIN CONTENT --- //--- MAIN CONTENT ---
if (statusToDeal.emojis != null && statusToDeal.emojis.size() > 0) {
CustomEmoji.displayEmoji(statusToDeal.emojis, statusToDeal.span_content, holder.binding.statusContent);
holder.binding.statusContent.postDelayed(new Runnable() {
@Override
public void run() {
holder.binding.statusContent.setText(statusToDeal.span_content, TextView.BufferType.SPANNABLE); holder.binding.statusContent.setText(statusToDeal.span_content, TextView.BufferType.SPANNABLE);
}
}, 100);
} else {
holder.binding.statusContent.setText(statusToDeal.span_content, 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);
holder.binding.statusContent.setEllipsize(TextUtils.TruncateAt.END); holder.binding.statusContent.setEllipsize(TextUtils.TruncateAt.END);