Skip to content

Instantly share code, notes, and snippets.

@sergenes
Created June 29, 2021 23:08
Show Gist options
  • Save sergenes/dfc6138d6cd521fc7d1a8999d4dbd391 to your computer and use it in GitHub Desktop.
Save sergenes/dfc6138d6cd521fc7d1a8999d4dbd391 to your computer and use it in GitHub Desktop.
data class StudyCardDeckModel(
var current: Int,
val dataSource: List<StudyCard>,
val visible: Int = 3,
val screenWidth: Int,
val screenHeight: Int
) {
private val colors = arrayOf(primaryColor, secondaryColor, tertiaryColor)
val count = dataSource.size
val visibleCards: Int = StrictMath.min(visible, dataSource.size - current)
fun cardVisible(visibleIndex: Int) = dataSource[dataSourceIndex(visibleIndex)]
private fun dataSourceIndex(visibleIndex: Int): Int {
return current + visibleIndex
}
fun colorForIndex(visibleIndex: Int): Color {
val index = dataSourceIndex(visibleIndex)
val colorIndex = index % colors.size
return colors[colorIndex]
}
@Composable
fun cardWidthPx(): Float {
return with(LocalDensity.current) { cardWidth.toPx() }
}
@Composable
fun cardHeightPx(): Float {
return with(LocalDensity.current) { cardHeight.toPx() }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment