Skip to content

Commit

Permalink
refactor: 24H and 48H intervals (#1500)
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-0410 authored Dec 23, 2024
1 parent ed45d0f commit 45e50b8
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions app/src/main/java/com/geeksville/mesh/model/MetricsViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 45e50b8

Please sign in to comment.