feat(feed): 랭킹 강조 텍스트 계약을 추가한다

This commit is contained in:
2026-05-21 15:53:39 +09:00
parent a2f3910e27
commit 3444b1eeef
4 changed files with 109 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
package kr.co.vividnext.sodalive.v2.widget.feed
data class FeedRankHighlight(
val start: Int,
val endExclusive: Int
) {
fun coerceIn(text: CharSequence): FeedRankHighlight? {
if (text.isEmpty()) return null
val safeStart = start.coerceIn(0, text.length)
val safeEnd = endExclusive.coerceIn(0, text.length)
return if (safeStart < safeEnd) FeedRankHighlight(safeStart, safeEnd) else null
}
}

View File

@@ -0,0 +1,24 @@
package kr.co.vividnext.sodalive.v2.widget.feed
import android.text.SpannableString
import android.text.Spanned
import android.text.style.ForegroundColorSpan
object FeedRankTextStyler {
fun style(
text: String,
highlightRanges: List<FeedRankHighlight>,
highlightColor: Int
): SpannableString {
val spannable = SpannableString(text)
highlightRanges.mapNotNull { it.coerceIn(text) }.forEach { range ->
spannable.setSpan(
ForegroundColorSpan(highlightColor),
range.start,
range.endExclusive,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
}
return spannable
}
}