Fix animated emojis in composable views
This commit is contained in:
parent
a26c078731
commit
81abedb89b
4 changed files with 451 additions and 276 deletions
|
@ -15,38 +15,48 @@
|
|||
|
||||
package com.keylesspalace.tusky.adapter
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.github.penfeizhou.animation.glide.AnimationDecoderOption
|
||||
import com.keylesspalace.tusky.R
|
||||
import com.keylesspalace.tusky.entity.Emoji
|
||||
import java.util.*
|
||||
|
||||
class EmojiAdapter(emojiList: List<Emoji>, private val onEmojiSelectedListener: OnEmojiSelectedListener) : RecyclerView.Adapter<EmojiAdapter.EmojiHolder>() {
|
||||
private val emojiList : List<Emoji>
|
||||
class EmojiAdapter(
|
||||
emojiList: List<Emoji>,
|
||||
private val onEmojiSelectedListener: OnEmojiSelectedListener,
|
||||
private val animateEmojis: Boolean
|
||||
) : RecyclerView.Adapter<EmojiAdapter.EmojiHolder>() {
|
||||
|
||||
private val emojis: List<Emoji>
|
||||
|
||||
init {
|
||||
this.emojiList = emojiList.filter { emoji -> emoji.visibleInPicker == null || emoji.visibleInPicker }
|
||||
.sortedBy { it.shortcode.toLowerCase(Locale.ROOT) }
|
||||
this.emojis =
|
||||
emojiList.filter { emoji -> emoji.visibleInPicker == null || emoji.visibleInPicker }
|
||||
.sortedBy { it.shortcode.lowercase() }
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return emojiList.size
|
||||
return emojis.size
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EmojiHolder {
|
||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_emoji_button, parent, false) as ImageView
|
||||
val view = LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.item_emoji_button, parent, false) as ImageView
|
||||
return EmojiHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(viewHolder: EmojiHolder, position: Int) {
|
||||
val emoji = emojiList[position]
|
||||
val emoji = emojis[position]
|
||||
|
||||
Glide.with(viewHolder.emojiImageView)
|
||||
.load(emoji.url)
|
||||
.into(viewHolder.emojiImageView)
|
||||
.load(emoji.url)
|
||||
.set(AnimationDecoderOption.DISABLE_ANIMATION_GIF_DECODER, !animateEmojis)
|
||||
.set(AnimationDecoderOption.DISABLE_ANIMATION_WEBP_DECODER, !animateEmojis)
|
||||
.set(AnimationDecoderOption.DISABLE_ANIMATION_APNG_DECODER, !animateEmojis)
|
||||
.into(viewHolder.emojiImageView)
|
||||
|
||||
viewHolder.emojiImageView.setOnClickListener {
|
||||
onEmojiSelectedListener.onEmojiSelected(emoji.shortcode)
|
||||
|
|
|
@ -55,6 +55,7 @@ class AnnouncementsActivity : BottomSheetActivity(), AnnouncementActionListener,
|
|||
|
||||
private val viewModel: AnnouncementsViewModel by viewModels { viewModelFactory }
|
||||
|
||||
private lateinit var preferences: SharedPreferences
|
||||
private lateinit var adapter: AnnouncementAdapter
|
||||
|
||||
private val picker by lazy { EmojiPicker(this) }
|
||||
|
@ -89,7 +90,7 @@ class AnnouncementsActivity : BottomSheetActivity(), AnnouncementActionListener,
|
|||
val divider = DividerItemDecoration(this, DividerItemDecoration.VERTICAL)
|
||||
announcementsList.addItemDecoration(divider)
|
||||
|
||||
val preferences: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
preferences = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
val wellbeingEnabled = preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false)
|
||||
|
||||
adapter = AnnouncementAdapter(emptyList(), this, wellbeingEnabled)
|
||||
|
@ -128,7 +129,11 @@ class AnnouncementsActivity : BottomSheetActivity(), AnnouncementActionListener,
|
|||
|
||||
viewModel.emojis.observe(this) {
|
||||
it?.let { list ->
|
||||
picker.adapter = EmojiAdapter(list, this)
|
||||
picker.adapter = EmojiAdapter(
|
||||
list,
|
||||
this,
|
||||
preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -167,9 +167,11 @@ class ComposeActivity : BaseActivity(),
|
|||
private val maxUploadMediaNumber = 4
|
||||
private var mediaCount = 0
|
||||
|
||||
private lateinit var preferences: SharedPreferences
|
||||
|
||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val preferences = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
preferences = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
val theme = preferences.getString("appTheme", ThemeUtils.APP_THEME_DEFAULT)
|
||||
if(theme == "black") {
|
||||
setTheme(R.style.TuskyDialogActivityBlackTheme)
|
||||
|
@ -1447,7 +1449,11 @@ class ComposeActivity : BaseActivity(),
|
|||
|
||||
private fun setEmojiList(emojiList: List<Emoji>?) {
|
||||
if(emojiList != null) {
|
||||
binding.emojiView.adapter = EmojiAdapter(emojiList, this@ComposeActivity)
|
||||
binding.emojiView.adapter = EmojiAdapter(
|
||||
emojiList,
|
||||
this@ComposeActivity,
|
||||
preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false)
|
||||
)
|
||||
enableButton(binding.composeEmojiButton, true, emojiList.isNotEmpty())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue