From e6b402b377ff21b704f639dcc6134f63f46951d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9l=C3=A8ne?= Date: Sat, 25 Jun 2022 14:07:06 +0200 Subject: [PATCH] EmojiReactionsAdapter: implement custom emoji reactions on messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hélène Signed-off-by: Adolfo Santiago --- .../tusky/adapter/EmojiReactionsAdapter.java | 22 +++++-- .../tusky/util/CustomEmojiHelper.kt | 58 +++++++++++++------ 2 files changed, 57 insertions(+), 23 deletions(-) diff --git a/husky/app/src/main/java/com/keylesspalace/tusky/adapter/EmojiReactionsAdapter.java b/husky/app/src/main/java/com/keylesspalace/tusky/adapter/EmojiReactionsAdapter.java index c8491ad..ffe3520 100644 --- a/husky/app/src/main/java/com/keylesspalace/tusky/adapter/EmojiReactionsAdapter.java +++ b/husky/app/src/main/java/com/keylesspalace/tusky/adapter/EmojiReactionsAdapter.java @@ -4,11 +4,14 @@ import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.graphics.drawable.Drawable; +import android.text.SpannableStringBuilder; +import android.text.Spanned; import android.text.method.LinkMovementMethod; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; +import android.widget.TextView.BufferType; import android.widget.Toast; import android.util.Log; @@ -21,6 +24,7 @@ import com.keylesspalace.tusky.entity.Status; import com.keylesspalace.tusky.entity.EmojiReaction; import com.keylesspalace.tusky.interfaces.StatusActionListener; import com.keylesspalace.tusky.util.CardViewMode; +import com.keylesspalace.tusky.util.CustomEmojiHelper; import com.keylesspalace.tusky.util.LinkHelper; import com.keylesspalace.tusky.util.StatusDisplayOptions; import com.keylesspalace.tusky.viewdata.StatusViewData; @@ -51,12 +55,20 @@ public class EmojiReactionsAdapter extends RecyclerView.Adapter { listener.onEmojiReactMenu(v, reaction, statusId); diff --git a/husky/app/src/main/java/com/keylesspalace/tusky/util/CustomEmojiHelper.kt b/husky/app/src/main/java/com/keylesspalace/tusky/util/CustomEmojiHelper.kt index df5ccc6..e967dba 100644 --- a/husky/app/src/main/java/com/keylesspalace/tusky/util/CustomEmojiHelper.kt +++ b/husky/app/src/main/java/com/keylesspalace/tusky/util/CustomEmojiHelper.kt @@ -70,25 +70,8 @@ fun CharSequence.emojify( .matcher(this) while(matcher.find()) { - val span = if(smallEmojis) { - SmallEmojiSpan(WeakReference(view)) - } else { - EmojiSpan(WeakReference(view)) - } - + val span = createEmojiSpan(url, view, smallEmojis, animate) builder.setSpan(span, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) - - var glideRequest = Glide.with(view).load(url) - .set(AnimationDecoderOption.DISABLE_ANIMATION_GIF_DECODER, !animate) - .set(AnimationDecoderOption.DISABLE_ANIMATION_WEBP_DECODER, !animate) - .set(AnimationDecoderOption.DISABLE_ANIMATION_APNG_DECODER, !animate) - val mimetype = getMimeType(url) - if(mimetype == MIME.SVG) { - glideRequest = glideRequest - .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) - .override(512, 512) - } - glideRequest.into(span.getTarget(animate)) } } @@ -99,6 +82,45 @@ fun CharSequence.emojify(emojis: List?, view: View): CharSequence { return this.emojify(emojis, view, false) } +fun createEmojiSpan( + emoji_url: String, + view: View, + forceSmallEmoji: Boolean = false +): EmojiSpan { + val pm = PreferenceManager.getDefaultSharedPreferences(view.context) + val smallEmojis = forceSmallEmoji || !pm.getBoolean(PrefKeys.BIG_EMOJIS, true) + val animate = pm.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false) + + return createEmojiSpan(emoji_url, view, smallEmojis, animate); +} + +private fun createEmojiSpan( + emoji_url: String, + view: View, + smallEmojis: Boolean = false, + animate: Boolean = false +): EmojiSpan { + val span = if(smallEmojis) { + SmallEmojiSpan(WeakReference(view)) + } else { + EmojiSpan(WeakReference(view)) + } + + var glideRequest = Glide.with(view).load(emoji_url) + .set(AnimationDecoderOption.DISABLE_ANIMATION_GIF_DECODER, !animate) + .set(AnimationDecoderOption.DISABLE_ANIMATION_WEBP_DECODER, !animate) + .set(AnimationDecoderOption.DISABLE_ANIMATION_APNG_DECODER, !animate) + val mimetype = getMimeType(emoji_url) + if(mimetype == MIME.SVG) { + glideRequest = glideRequest + .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) + .override(512, 512) + } + glideRequest.into(span.getTarget(animate)) + + return span; +} + open class EmojiSpan(val viewWeakReference: WeakReference) : ReplacementSpan() { var imageDrawable: Drawable? = null