fix(content-ranking): 카드 UI 크기를 반응형 적용한다

This commit is contained in:
2026-07-10 10:16:36 +09:00
parent e77d0a1d5b
commit abd084cff8
4 changed files with 204 additions and 33 deletions

View File

@@ -2,6 +2,7 @@ package kr.co.vividnext.sodalive.v2.widget.contentranking
import android.app.Application
import android.content.Context
import android.content.res.Configuration
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
@@ -144,6 +145,83 @@ class ContentRankingCardViewTest {
assertEquals(View.VISIBLE, view.findViewById<View>(R.id.iv_content_ranking_background).visibility)
}
@Test
fun `large card는 402dp 미만에서 실제 text size를 축소한다`() {
val view = inflateView<ContentRankingLargeCardView>(
layoutResId = R.layout.view_content_ranking_large_card,
screenWidthDp = 360
)
view.bind(sampleItem(rank = 1))
assertTextSizeSp(view.findViewById(R.id.tv_content_ranking_rank), 96f * 360f / 402f)
assertTextSizeSp(view.findViewById(R.id.tv_content_ranking_title), 22f * 360f / 402f)
assertTextSizeSp(view.findViewById(R.id.tv_content_ranking_creator), 12f * 360f / 402f)
assertTextSizeSp(view.findViewById(R.id.tv_content_ranking_delta_amount), 16f * 360f / 402f)
}
@Test
fun `medium grid card는 402dp 미만에서 실제 text size를 축소한다`() {
val view = inflateView<ContentRankingMediumGridCardView>(
layoutResId = R.layout.view_content_ranking_medium_grid_card,
screenWidthDp = 360
)
view.setCardSize(ContentRankingCardSize(widthPx = 185, heightPx = 185))
view.bind(sampleItem(rank = 2))
assertTextSizeSp(view.findViewById(R.id.tv_content_ranking_rank), 54f * 360f / 402f)
assertTextSizeSp(view.findViewById(R.id.tv_content_ranking_title), 22f * 360f / 402f)
assertTextSizeSp(view.findViewById(R.id.tv_content_ranking_creator), 12f * 360f / 402f)
assertTextSizeSp(view.findViewById(R.id.tv_content_ranking_delta_amount), 16f * 360f / 402f)
}
@Test
fun `small grid card는 402dp 미만에서 조건부 baseline text size를 축소한다`() {
val view = inflateView<ContentRankingSmallGridCardView>(
layoutResId = R.layout.view_content_ranking_small_grid_card,
screenWidthDp = 360
)
view.setCardSize(ContentRankingCardSize(widthPx = 122, heightPx = 122))
view.bind(sampleItem(rank = 8))
assertTextSizeSp(view.findViewById(R.id.tv_content_ranking_rank), 36f * 360f / 402f)
assertTextSizeSp(view.findViewById(R.id.tv_content_ranking_title), 14f * 360f / 402f)
assertTextSizeSp(view.findViewById(R.id.tv_content_ranking_creator), 12f * 360f / 402f)
assertTextSizeSp(view.findViewById(R.id.tv_content_ranking_delta_amount), 16f * 360f / 402f)
}
@Test
fun `small grid card는 card size 적용 전 bind에서도 402dp 미만 text size를 축소한다`() {
val view = inflateView<ContentRankingSmallGridCardView>(
layoutResId = R.layout.view_content_ranking_small_grid_card,
screenWidthDp = 360
)
view.bind(sampleItem(rank = 8))
assertTextSizeSp(view.findViewById(R.id.tv_content_ranking_rank), 36f * 360f / 402f)
assertTextSizeSp(view.findViewById(R.id.tv_content_ranking_title), 14f * 360f / 402f)
assertTextSizeSp(view.findViewById(R.id.tv_content_ranking_creator), 12f * 360f / 402f)
assertTextSizeSp(view.findViewById(R.id.tv_content_ranking_delta_amount), 16f * 360f / 402f)
}
@Test
fun `horizontal card는 402dp 미만에서 실제 text size를 축소한다`() {
val view = inflateView<ContentRankingHorizontalCardView>(
layoutResId = R.layout.view_content_ranking_horizontal_card,
screenWidthDp = 360
)
view.bind(sampleItem(rank = 11))
assertTextSizeSp(view.findViewById(R.id.tv_content_ranking_rank), 40f * 360f / 402f)
assertTextSizeSp(view.findViewById(R.id.tv_content_ranking_title), 18f * 360f / 402f)
assertTextSizeSp(view.findViewById(R.id.tv_content_ranking_creator), 14f * 360f / 402f)
assertTextSizeSp(view.findViewById(R.id.tv_content_ranking_delta_amount), 16f * 360f / 402f)
}
@Test
fun `large view holder는 배경 blur와 전경 non blur coverImage를 모두 로드한다`() {
val source = projectFile(
@@ -161,11 +239,28 @@ class ContentRankingCardViewTest {
)
}
private inline fun <reified T : View> inflateView(layoutResId: Int): T {
val context = ApplicationProvider.getApplicationContext<Context>()
private inline fun <reified T : View> inflateView(
layoutResId: Int,
screenWidthDp: Int? = null
): T {
val baseContext = ApplicationProvider.getApplicationContext<Context>()
val context = if (screenWidthDp == null) {
baseContext
} else {
baseContext.createConfigurationContext(
Configuration(baseContext.resources.configuration).apply { this.screenWidthDp = screenWidthDp }
)
}
return LayoutInflater.from(context).inflate(layoutResId, null, false) as T
}
private fun assertTextSizeSp(
view: TextView,
expectedSp: Float
) {
assertEquals(expectedSp, view.textSize / view.resources.displayMetrics.scaledDensity, 0.0001f)
}
private fun assertRankTextBox(
view: TextView,
expectedWidth: Int,