refactor: 24H and 48H intervals (#1500)

This commit is contained in:
Robert-0410 2024-12-23 02:26:58 -08:00 committed by GitHub
parent ed45d0ff96
commit 45e50b829a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -135,9 +135,10 @@ enum class TimeFrame(
*/
fun lineInterval(): Long {
return when (this.ordinal) {
TWENTY_FOUR_HOURS.ordinal,
TWENTY_FOUR_HOURS.ordinal ->
TimeUnit.HOURS.toSeconds(6)
FORTY_EIGHT_HOURS.ordinal ->
TimeUnit.HOURS.toSeconds(1)
TimeUnit.HOURS.toSeconds(12)
ONE_WEEK.ordinal,
TWO_WEEKS.ordinal ->
TimeUnit.DAYS.toSeconds(1)
@ -152,18 +153,7 @@ enum class TimeFrame(
* @param time in seconds
*/
fun dp(screenWidth: Int, time: Long): Dp {
val timePerScreen = when (this.ordinal) {
TWENTY_FOUR_HOURS.ordinal,
FORTY_EIGHT_HOURS.ordinal ->
TimeUnit.HOURS.toSeconds(1)
ONE_WEEK.ordinal,
TWO_WEEKS.ordinal ->
TimeUnit.DAYS.toSeconds(1)
else ->
TimeUnit.DAYS.toSeconds(7)
}
val timePerScreen = this.lineInterval()
val multiplier = time / timePerScreen
val dp = (screenWidth * multiplier).toInt().dp
return dp.takeIf { it != 0.dp } ?: screenWidth.dp