feat(widget): 랭킹 카드 순위 변동 숨김을 적용한다

This commit is contained in:
2026-06-08 15:22:10 +09:00
parent 4a21827b47
commit 6d980e319b
4 changed files with 119 additions and 6 deletions

View File

@@ -77,6 +77,9 @@ class CreatorRankingCompactCardView @JvmOverloads constructor(
}
private fun bindDelta(item: CreatorRankingItem) {
requireNotNull(deltaGroup).visibility = if (item.showRankChange) View.VISIBLE else View.GONE
if (!item.showRankChange) return
val presentation = CreatorRankingDeltaPresentation.from(item.rankChangeType, item.rankChangeAmount)
applyDeltaContainer(presentation)
requireNotNull(deltaIcon).apply {
@@ -130,7 +133,10 @@ class CreatorRankingCompactCardView @JvmOverloads constructor(
leftMargin = (10 * scale).roundToInt()
topMargin = (70 * scale).roundToInt()
}
requireNotNull(nameText).layoutParams = LayoutParams((165 * scale).roundToInt(), ViewGroup.LayoutParams.WRAP_CONTENT).apply {
requireNotNull(nameText).layoutParams = LayoutParams(
(165 * scale).roundToInt(),
ViewGroup.LayoutParams.WRAP_CONTENT
).apply {
leftMargin = ((size.widthPx - (165 * scale)) / 2f).roundToInt()
topMargin = (145 * scale).roundToInt()
}
@@ -138,7 +144,10 @@ class CreatorRankingCompactCardView @JvmOverloads constructor(
private fun positionSmall(size: CreatorRankingCardSize) {
val scale = size.widthPx / 122f
requireNotNull(rankText).layoutParams = LayoutParams((42 * scale).roundToInt(), (56 * scale).roundToInt()).apply {
requireNotNull(rankText).layoutParams = LayoutParams(
(42 * scale).roundToInt(),
(56 * scale).roundToInt()
).apply {
leftMargin = (8 * scale).roundToInt()
}
findViewById<View>(R.id.ll_creator_ranking_delta).layoutParams = LayoutParams(
@@ -148,7 +157,10 @@ class CreatorRankingCompactCardView @JvmOverloads constructor(
leftMargin = (10 * scale).roundToInt()
topMargin = (49 * scale).roundToInt()
}
requireNotNull(nameText).layoutParams = LayoutParams((102 * scale).roundToInt(), ViewGroup.LayoutParams.WRAP_CONTENT).apply {
requireNotNull(nameText).layoutParams = LayoutParams(
(102 * scale).roundToInt(),
ViewGroup.LayoutParams.WRAP_CONTENT
).apply {
leftMargin = ((size.widthPx - (102 * scale)) / 2f).roundToInt()
topMargin = (98 * scale).roundToInt()
}

View File

@@ -69,6 +69,10 @@ class CreatorRankingHorizontalCardView @JvmOverloads constructor(
}
private fun bindDelta(item: CreatorRankingItem) {
val deltaGroup = findViewById<View>(R.id.ll_creator_ranking_delta)
deltaGroup.visibility = if (item.showRankChange) View.VISIBLE else View.GONE
if (!item.showRankChange) return
val presentation = CreatorRankingDeltaPresentation.from(item.rankChangeType, item.rankChangeAmount)
applyDeltaContainer(presentation)
requireNotNull(deltaIcon).apply {
@@ -101,7 +105,10 @@ class CreatorRankingHorizontalCardView @JvmOverloads constructor(
private fun positionViews(size: CreatorRankingCardSize) {
val scale = size.widthPx / 374f
requireNotNull(rankGroup).layoutParams = LayoutParams((49 * scale).roundToInt(), ViewGroup.LayoutParams.WRAP_CONTENT).apply {
requireNotNull(rankGroup).layoutParams = LayoutParams(
(49 * scale).roundToInt(),
ViewGroup.LayoutParams.WRAP_CONTENT
).apply {
leftMargin = (14 * scale).roundToInt()
topMargin = (14 * scale).roundToInt()
}
@@ -110,7 +117,10 @@ class CreatorRankingHorizontalCardView @JvmOverloads constructor(
leftMargin = (77 * scale).roundToInt()
topMargin = (10 * scale).roundToInt()
}
requireNotNull(nameText).layoutParams = LayoutParams((189 * scale).roundToInt(), ViewGroup.LayoutParams.WRAP_CONTENT).apply {
requireNotNull(nameText).layoutParams = LayoutParams(
(189 * scale).roundToInt(),
ViewGroup.LayoutParams.WRAP_CONTENT
).apply {
leftMargin = (171 * scale).roundToInt()
topMargin = (39 * scale).roundToInt()
}

View File

@@ -77,6 +77,9 @@ class CreatorRankingLargeCardView @JvmOverloads constructor(
}
private fun bindDelta(item: CreatorRankingItem) {
requireNotNull(deltaGroup).visibility = if (item.showRankChange) View.VISIBLE else View.GONE
if (!item.showRankChange) return
val presentation = CreatorRankingDeltaPresentation.from(item.rankChangeType, item.rankChangeAmount)
applyDeltaContainer(presentation)
requireNotNull(deltaIcon).apply {
@@ -114,7 +117,10 @@ class CreatorRankingLargeCardView @JvmOverloads constructor(
topMargin = 0
}
requireNotNull(rankText).applyCreatorRankingRankGradient()
requireNotNull(nameText).layoutParams = LayoutParams((334 * scale).roundToInt(), ViewGroup.LayoutParams.WRAP_CONTENT).apply {
requireNotNull(nameText).layoutParams = LayoutParams(
(334 * scale).roundToInt(),
ViewGroup.LayoutParams.WRAP_CONTENT
).apply {
leftMargin = ((size.widthPx - (334 * scale)) / 2f).roundToInt()
topMargin = (305 * scale).roundToInt()
}

View File

@@ -1,8 +1,20 @@
package kr.co.vividnext.sodalive.v2.widget.creatorranking
import android.app.Application
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import androidx.test.core.app.ApplicationProvider
import kr.co.vividnext.sodalive.R
import kr.co.vividnext.sodalive.v2.widget.ranking.RankingChangeType.Increase
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], application = Application::class)
class CreatorRankingAdapterLayoutTest {
@Test
@@ -25,4 +37,77 @@ class CreatorRankingAdapterLayoutTest {
assertEquals(6, spanLookup.getSpanSize(position))
}
}
@Test
fun `large card는 순위 변동 숨김이면 delta를 숨긴다`() {
val view = inflateView<CreatorRankingLargeCardView>(R.layout.view_creator_ranking_large_card)
view.bind(sampleItem(showRankChange = false))
assertEquals(View.GONE, view.findViewById<View>(R.id.ll_creator_ranking_delta).visibility)
}
@Test
fun `large card는 순위 변동 표시이면 delta를 보여준다`() {
val view = inflateView<CreatorRankingLargeCardView>(R.layout.view_creator_ranking_large_card)
view.bind(sampleItem(showRankChange = true))
assertEquals(View.VISIBLE, view.findViewById<View>(R.id.ll_creator_ranking_delta).visibility)
}
@Test
fun `compact card는 순위 변동 숨김이면 delta를 숨긴다`() {
val view = inflateView<CreatorRankingCompactCardView>(R.layout.view_creator_ranking_compact_card)
view.bind(sampleItem(showRankChange = false))
assertEquals(View.GONE, view.findViewById<View>(R.id.ll_creator_ranking_delta).visibility)
}
@Test
fun `compact card는 순위 변동 표시이면 delta를 보여준다`() {
val view = inflateView<CreatorRankingCompactCardView>(R.layout.view_creator_ranking_compact_card)
view.bind(sampleItem(showRankChange = true))
assertEquals(View.VISIBLE, view.findViewById<View>(R.id.ll_creator_ranking_delta).visibility)
}
@Test
fun `horizontal card는 순위 변동 숨김이면 delta를 숨긴다`() {
val view = inflateView<CreatorRankingHorizontalCardView>(R.layout.view_creator_ranking_horizontal_card)
view.bind(sampleItem(rank = 11, showRankChange = false))
assertEquals(View.GONE, view.findViewById<View>(R.id.ll_creator_ranking_delta).visibility)
}
@Test
fun `horizontal card는 순위 변동 표시이면 delta를 보여준다`() {
val view = inflateView<CreatorRankingHorizontalCardView>(R.layout.view_creator_ranking_horizontal_card)
view.bind(sampleItem(rank = 11, showRankChange = true))
assertEquals(View.VISIBLE, view.findViewById<View>(R.id.ll_creator_ranking_delta).visibility)
}
private inline fun <reified T : View> inflateView(layoutResId: Int): T {
val context = ApplicationProvider.getApplicationContext<Context>()
return LayoutInflater.from(context).inflate(layoutResId, null, false) as T
}
private fun sampleItem(
rank: Int = 1,
showRankChange: Boolean = true
) = CreatorRankingItem(
creatorId = 1L,
rank = rank,
rankChangeType = Increase,
rankChangeAmount = 4,
creatorName = "크리에이터 이름",
imageUrl = "https://example.com/image.png",
isBlocked = false,
showRankChange = showRankChange
)
}