Fix announcement reactions (#2311)
* fix size of announcement reactions * fix announcement reactions not updating correctly * remove unused code * improve code * remove unused imports
This commit is contained in:
parent
329bc51f90
commit
db1cc02fb8
1 changed files with 37 additions and 32 deletions
|
@ -15,21 +15,25 @@
|
||||||
|
|
||||||
package com.keylesspalace.tusky.components.announcements
|
package com.keylesspalace.tusky.components.announcements
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
|
import android.text.SpannableStringBuilder
|
||||||
import android.view.ContextThemeWrapper
|
import android.view.ContextThemeWrapper
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.view.size
|
import androidx.core.view.size
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.bumptech.glide.Glide
|
||||||
import com.google.android.material.chip.Chip
|
import com.google.android.material.chip.Chip
|
||||||
import com.keylesspalace.tusky.R
|
import com.keylesspalace.tusky.R
|
||||||
import com.keylesspalace.tusky.databinding.ItemAnnouncementBinding
|
import com.keylesspalace.tusky.databinding.ItemAnnouncementBinding
|
||||||
import com.keylesspalace.tusky.entity.Announcement
|
import com.keylesspalace.tusky.entity.Announcement
|
||||||
import com.keylesspalace.tusky.entity.Emoji
|
|
||||||
import com.keylesspalace.tusky.interfaces.LinkListener
|
import com.keylesspalace.tusky.interfaces.LinkListener
|
||||||
import com.keylesspalace.tusky.util.BindingHolder
|
import com.keylesspalace.tusky.util.BindingHolder
|
||||||
|
import com.keylesspalace.tusky.util.EmojiSpan
|
||||||
import com.keylesspalace.tusky.util.LinkHelper
|
import com.keylesspalace.tusky.util.LinkHelper
|
||||||
import com.keylesspalace.tusky.util.emojify
|
import com.keylesspalace.tusky.util.emojify
|
||||||
|
import java.lang.ref.WeakReference
|
||||||
|
|
||||||
interface AnnouncementActionListener : LinkListener {
|
interface AnnouncementActionListener : LinkListener {
|
||||||
fun openReactionPicker(announcementId: String, target: View)
|
fun openReactionPicker(announcementId: String, target: View)
|
||||||
|
@ -69,31 +73,32 @@ class AnnouncementAdapter(
|
||||||
}
|
}
|
||||||
|
|
||||||
item.reactions.forEachIndexed { i, reaction ->
|
item.reactions.forEachIndexed { i, reaction ->
|
||||||
|
(
|
||||||
chips.getChildAt(i)?.takeUnless { it.id == R.id.addReactionChip } as Chip?
|
chips.getChildAt(i)?.takeUnless { it.id == R.id.addReactionChip } as Chip?
|
||||||
?: Chip(ContextThemeWrapper(chips.context, R.style.Widget_MaterialComponents_Chip_Choice)).apply {
|
?: Chip(ContextThemeWrapper(chips.context, R.style.Widget_MaterialComponents_Chip_Choice)).apply {
|
||||||
isCheckable = true
|
isCheckable = true
|
||||||
checkedIcon = null
|
checkedIcon = null
|
||||||
chips.addView(this, i)
|
chips.addView(this, i)
|
||||||
}
|
}
|
||||||
|
)
|
||||||
.apply {
|
.apply {
|
||||||
val emojiText = if (reaction.url == null) {
|
if (reaction.url == null) {
|
||||||
reaction.name
|
this.text = "${reaction.name} ${reaction.count}"
|
||||||
} else {
|
} else {
|
||||||
context.getString(R.string.emoji_shortcode_format, reaction.name)
|
// we set the EmojiSpan on a space, because otherwise the Chip won't have the right size
|
||||||
|
// https://github.com/tuskyapp/Tusky/issues/2308
|
||||||
|
val spanBuilder = SpannableStringBuilder(" ${reaction.count}")
|
||||||
|
val span = EmojiSpan(WeakReference(this))
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
span.contentDescription = reaction.name
|
||||||
|
}
|
||||||
|
spanBuilder.setSpan(span, 0, 1, 0)
|
||||||
|
Glide.with(this)
|
||||||
|
.asDrawable()
|
||||||
|
.load(if (animateEmojis) { reaction.url } else { reaction.staticUrl })
|
||||||
|
.into(span.getTarget(animateEmojis))
|
||||||
|
this.text = spanBuilder
|
||||||
}
|
}
|
||||||
this.text = ("$emojiText ${reaction.count}")
|
|
||||||
.emojify(
|
|
||||||
listOf(
|
|
||||||
Emoji(
|
|
||||||
reaction.name,
|
|
||||||
reaction.url ?: "",
|
|
||||||
reaction.staticUrl ?: "",
|
|
||||||
null
|
|
||||||
)
|
|
||||||
),
|
|
||||||
this,
|
|
||||||
animateEmojis
|
|
||||||
)
|
|
||||||
|
|
||||||
isChecked = reaction.me
|
isChecked = reaction.me
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue