Fix gallery comment style by not reusing Spans
This commit is contained in:
1 parent
e5361949df
commit
0e87595692
1 file changed
+14
-7
@@ -3,10 +3,12 @@ package com.hippo.ehviewer.ui.screen
|
||||
import android.graphics.Typeface
|
||||
import android.text.Html
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.text.style.RelativeSizeSpan
|
||||
import android.text.style.StyleSpan
|
||||
import android.text.style.URLSpan
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.compose.animation.AnimatedVisibilityScope
|
||||
import androidx.compose.animation.Crossfade
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
@@ -116,6 +118,16 @@ import moe.tarsin.coroutines.runSuspendCatching
|
||||
|
||||
private val URL_PATTERN = Regex("(http|https)://[a-z0-9A-Z%-]+(\\.[a-z0-9A-Z%-]+)+(:\\d{1,5})?(/[a-zA-Z0-9-_~:#@!&',;=%/*.?+$\\[\\]()]+)?/?")
|
||||
|
||||
private inline fun SpannableStringBuilder.withSpans(
|
||||
@ColorInt color: Int,
|
||||
builderAction: SpannableStringBuilder.() -> Unit,
|
||||
) = inSpans(
|
||||
RelativeSizeSpan(0.8f),
|
||||
StyleSpan(Typeface.BOLD),
|
||||
ForegroundColorSpan(color),
|
||||
builderAction = builderAction,
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun processComment(
|
||||
comment: GalleryComment,
|
||||
@@ -131,22 +143,17 @@ fun processComment(
|
||||
}
|
||||
}
|
||||
val color = MaterialTheme.colorScheme.onSurfaceVariant.toArgb()
|
||||
val spans = arrayOf(
|
||||
RelativeSizeSpan(0.8f),
|
||||
StyleSpan(Typeface.BOLD),
|
||||
ForegroundColorSpan(color),
|
||||
)
|
||||
if (comment.id != 0L && comment.score != 0) {
|
||||
val score = comment.score
|
||||
val scoreString = if (score > 0) "+$score" else score.toString()
|
||||
append(" ")
|
||||
inSpans(*spans) {
|
||||
withSpans(color) {
|
||||
append(scoreString)
|
||||
}
|
||||
}
|
||||
if (comment.lastEdited != 0L) {
|
||||
append("\n\n")
|
||||
inSpans(*spans) {
|
||||
withSpans(color) {
|
||||
append(
|
||||
stringResource(
|
||||
R.string.last_edited,
|
||||
|
||||
Reference in new issue
Block a user