feat(banner): 배너 카운터와 상태 계약을 추가한다

This commit is contained in:
2026-05-27 22:27:40 +09:00
parent 91a7eb3f4c
commit 02f85f808d
4 changed files with 117 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
package kr.co.vividnext.sodalive.v2.widget.banner
object BannerCounterFormatter {
fun format(currentIndex: Int, count: Int): String {
return "%02d / %02d".format(currentIndex + 1, count)
}
}

View File

@@ -0,0 +1,33 @@
package kr.co.vividnext.sodalive.v2.widget.banner
data class BannerState(
val displayMode: BannerDisplayMode,
val currentIndex: Int,
private val count: Int
) {
fun nextIndex(): Int = (currentIndex + 1) % count
fun previousIndex(): Int = (currentIndex - 1 + count) % count
companion object {
fun from(count: Int, currentIndex: Int): BannerState {
val displayMode = when (count) {
0 -> BannerDisplayMode.Hidden
1 -> BannerDisplayMode.Single
else -> BannerDisplayMode.Carousel
}
val correctedIndex = if (currentIndex in 0 until count) currentIndex else 0
return BannerState(
displayMode = displayMode,
currentIndex = correctedIndex,
count = count
)
}
}
}
enum class BannerDisplayMode {
Hidden,
Single,
Carousel
}