fix: emoji should animate in more cases
Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
parent
54413154a6
commit
5a6a25c113
|
|
@ -31,6 +31,7 @@ import androidx.compose.material3.LocalTextStyle
|
|||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.key
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
|
|
@ -283,26 +284,28 @@ fun Message(
|
|||
}
|
||||
}
|
||||
|
||||
message.content?.let {
|
||||
if (message.content.isBlank()) return@let // if only an attachment is sent
|
||||
key(message.content) {
|
||||
message.content?.let {
|
||||
if (message.content.isBlank()) return@let // if only an attachment is sent
|
||||
|
||||
AndroidView(
|
||||
factory = { ctx ->
|
||||
androidx.appcompat.widget.AppCompatTextView(ctx).apply {
|
||||
maxLines = if (truncate) 1 else Int.MAX_VALUE
|
||||
ellipsize = TextUtils.TruncateAt.END
|
||||
textSize = 16f
|
||||
typeface = ResourcesCompat.getFont(ctx, R.font.inter)
|
||||
AndroidView(
|
||||
factory = { ctx ->
|
||||
androidx.appcompat.widget.AppCompatTextView(ctx).apply {
|
||||
maxLines = if (truncate) 1 else Int.MAX_VALUE
|
||||
ellipsize = TextUtils.TruncateAt.END
|
||||
textSize = 16f
|
||||
typeface = ResourcesCompat.getFont(ctx, R.font.inter)
|
||||
|
||||
movementMethod = LongClickLinkMovementMethod.instance
|
||||
movementMethod = LongClickLinkMovementMethod.instance
|
||||
|
||||
setTextColor(contentColor.toArgb())
|
||||
setTextColor(contentColor.toArgb())
|
||||
}
|
||||
},
|
||||
update = {
|
||||
it.text = parse(message)
|
||||
}
|
||||
},
|
||||
update = {
|
||||
it.text = parse(message)
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
message.attachments?.let {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import android.text.SpannableStringBuilder
|
|||
import android.text.Spanned
|
||||
import chat.revolt.api.REVOLT_FILES
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.resource.gif.GifDrawable
|
||||
import com.discord.simpleast.core.node.Node
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
|
@ -56,19 +57,38 @@ class CustomEmoteNode(private val emoteId: String, private val context: Context)
|
|||
override fun render(builder: SpannableStringBuilder, renderContext: MarkdownContext) {
|
||||
val content = renderContext.emojiMap[emoteId]?.let { ":${it.name}:" }
|
||||
?: ":${emoteId}:"
|
||||
val emoteUrl = "$REVOLT_FILES/emojis/$emoteId"
|
||||
val isGif = renderContext.emojiMap[emoteId]?.animated ?: false
|
||||
val emoteUrl = "$REVOLT_FILES/emojis/$emoteId/emote${if (isGif) ".gif" else ".png"}"
|
||||
|
||||
val density = context.resources.displayMetrics.density.toInt()
|
||||
|
||||
builder.append(content)
|
||||
runBlocking(Dispatchers.IO) {
|
||||
val drawable = Glide.with(context)
|
||||
.asDrawable()
|
||||
.load(emoteUrl)
|
||||
.submit()
|
||||
.get()
|
||||
val drawable = try {
|
||||
Glide.with(context)
|
||||
.asDrawable()
|
||||
.load(emoteUrl)
|
||||
.submit()
|
||||
.get()
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}.also {
|
||||
if (it == null) {
|
||||
builder.replace(
|
||||
builder.length - content.length,
|
||||
builder.length,
|
||||
content
|
||||
)
|
||||
}
|
||||
} ?: return@runBlocking
|
||||
|
||||
val targetSize = if (renderContext.useLargeEmojis) 48 else 28
|
||||
if (drawable is GifDrawable) {
|
||||
drawable.apply {
|
||||
start()
|
||||
}
|
||||
}
|
||||
|
||||
val targetSize = if (renderContext.useLargeEmojis) 48 else 22
|
||||
val maxWidth = if (renderContext.useLargeEmojis) 58 else 38
|
||||
|
||||
val wantWidth = min(
|
||||
|
|
|
|||
Loading…
Reference in New Issue