feat(ranking): 반응형 폭 스케일을 추가한다

This commit is contained in:
2026-07-10 10:16:01 +09:00
parent 2b2cb66dfc
commit 63a7c28e96
2 changed files with 42 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
package kr.co.vividnext.sodalive.v2.widget.ranking
import android.content.res.Resources
object RankingResponsiveScale {
private const val BASE_WIDTH_DP = 402
fun fromResources(resources: Resources): Float = fromScreenWidthDp(resources.configuration.screenWidthDp)
fun fromScreenWidthDp(screenWidthDp: Int): Float {
return when {
screenWidthDp <= 0 -> 1f
screenWidthDp >= BASE_WIDTH_DP -> 1f
else -> screenWidthDp / BASE_WIDTH_DP.toFloat()
}
}
}

View File

@@ -0,0 +1,25 @@
package kr.co.vividnext.sodalive.v2.widget.ranking
import org.junit.Assert.assertEquals
import org.junit.Test
class RankingResponsiveScaleTest {
@Test
fun `402dp 이상이면 scale 1을 반환한다`() {
assertEquals(1f, RankingResponsiveScale.fromScreenWidthDp(402), 0.0001f)
assertEquals(1f, RankingResponsiveScale.fromScreenWidthDp(430), 0.0001f)
}
@Test
fun `402dp 미만이면 device width와 기준 폭 비율을 반환한다`() {
assertEquals(360f / 402f, RankingResponsiveScale.fromScreenWidthDp(360), 0.0001f)
assertEquals(401f / 402f, RankingResponsiveScale.fromScreenWidthDp(401), 0.0001f)
}
@Test
fun `screen width를 확인할 수 없으면 scale 1을 반환한다`() {
assertEquals(1f, RankingResponsiveScale.fromScreenWidthDp(0), 0.0001f)
assertEquals(1f, RankingResponsiveScale.fromScreenWidthDp(-1), 0.0001f)
}
}