From bdeb88c41f7b0a03df0a980ee4150efb63f0a8f7 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Mon, 5 Dec 2022 19:15:28 +0100 Subject: [PATCH] respect "animate emojis" setting in emoji picker (#2996) --- .../keylesspalace/tusky/adapter/EmojiAdapter.kt | 16 ++++++++++++---- .../announcements/AnnouncementsActivity.kt | 2 +- .../tusky/components/compose/ComposeActivity.kt | 10 ++++++---- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/EmojiAdapter.kt b/app/src/main/java/com/keylesspalace/tusky/adapter/EmojiAdapter.kt index d3412e5b..51aa43f7 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/EmojiAdapter.kt +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/EmojiAdapter.kt @@ -27,7 +27,8 @@ import java.util.Locale class EmojiAdapter( emojiList: List, - private val onEmojiSelectedListener: OnEmojiSelectedListener + private val onEmojiSelectedListener: OnEmojiSelectedListener, + private val animate: Boolean ) : RecyclerView.Adapter>() { private val emojiList: List = emojiList.filter { emoji -> emoji.visibleInPicker == null || emoji.visibleInPicker } @@ -44,9 +45,16 @@ class EmojiAdapter( val emoji = emojiList[position] val emojiImageView = holder.binding.root - Glide.with(emojiImageView) - .load(emoji.url) - .into(emojiImageView) + if (animate) { + Glide.with(emojiImageView) + .load(emoji.url) + .into(emojiImageView) + } else { + Glide.with(emojiImageView) + .asBitmap() + .load(emoji.url) + .into(emojiImageView) + } emojiImageView.setOnClickListener { onEmojiSelectedListener.onEmojiSelected(emoji.shortcode) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/announcements/AnnouncementsActivity.kt b/app/src/main/java/com/keylesspalace/tusky/components/announcements/AnnouncementsActivity.kt index b0c6653b..b353fe86 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/announcements/AnnouncementsActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/announcements/AnnouncementsActivity.kt @@ -122,7 +122,7 @@ class AnnouncementsActivity : BottomSheetActivity(), AnnouncementActionListener, } viewModel.emojis.observe(this) { - picker.adapter = EmojiAdapter(it, this) + picker.adapter = EmojiAdapter(it, this, animateEmojis) } viewModel.load() diff --git a/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt b/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt index 8f85f343..83531dc4 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt @@ -138,6 +138,8 @@ class ComposeActivity : private var finishingUploadDialog: ProgressDialog? = null private var photoUploadUri: Uri? = null + private val preferences by lazy { PreferenceManager.getDefaultSharedPreferences(this) } + @VisibleForTesting var maximumTootCharacters = InstanceInfoRepository.DEFAULT_CHARACTER_LIMIT var charactersReservedPerUrl = InstanceInfoRepository.DEFAULT_CHARACTERS_RESERVED_PER_URL @@ -205,7 +207,6 @@ class ComposeActivity : accountManager.setActiveAccount(accountId) } - val preferences = PreferenceManager.getDefaultSharedPreferences(this) val theme = preferences.getString("appTheme", ThemeUtils.APP_THEME_DEFAULT) if (theme == "black") { setTheme(R.style.TuskyDialogActivityBlackTheme) @@ -216,7 +217,7 @@ class ComposeActivity : // do not do anything when not logged in, activity will be finished in super.onCreate() anyway val activeAccount = accountManager.activeAccount ?: return - setupAvatar(preferences, activeAccount) + setupAvatar(activeAccount) val mediaAdapter = MediaPreviewAdapter( this, onAddCaption = { item -> @@ -562,7 +563,7 @@ class ComposeActivity : } } - private fun setupAvatar(preferences: SharedPreferences, activeAccount: AccountEntity) { + private fun setupAvatar(activeAccount: AccountEntity) { val actionBarSizeAttr = intArrayOf(R.attr.actionBarSize) val a = obtainStyledAttributes(null, actionBarSizeAttr) val avatarSize = a.getDimensionPixelSize(0, 1) @@ -1148,7 +1149,8 @@ class ComposeActivity : private fun setEmojiList(emojiList: List?) { if (emojiList != null) { - binding.emojiView.adapter = EmojiAdapter(emojiList, this@ComposeActivity) + val animateEmojis = preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false) + binding.emojiView.adapter = EmojiAdapter(emojiList, this@ComposeActivity, animateEmojis) enableButton(binding.composeEmojiButton, true, emojiList.isNotEmpty()) } }