mirror of
https://github.com/SimpleMobileTools/Simple-Clock.git
synced 2025-06-05 22:19:17 +02:00
add proper lap sorting
This commit is contained in:
@ -1,3 +1,37 @@
|
||||
package com.simplemobiletools.clock.models
|
||||
|
||||
data class Lap(val id: Int, var lapTime: Long, var totalTime: Long)
|
||||
import com.simplemobiletools.clock.helpers.SORT_BY_LAP
|
||||
import com.simplemobiletools.clock.helpers.SORT_BY_LAP_TIME
|
||||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||
|
||||
data class Lap(val id: Int, var lapTime: Long, var totalTime: Long) : Comparable<Lap> {
|
||||
companion object {
|
||||
var sorting = 0
|
||||
}
|
||||
|
||||
override fun compareTo(other: Lap): Int {
|
||||
var result = when {
|
||||
sorting and SORT_BY_LAP != 0 -> when {
|
||||
id == other.id -> 0
|
||||
id > other.id -> 1
|
||||
else -> -1
|
||||
}
|
||||
sorting and SORT_BY_LAP_TIME != 0 -> when {
|
||||
lapTime == other.lapTime -> 0
|
||||
lapTime > other.lapTime -> 1
|
||||
else -> -1
|
||||
}
|
||||
else -> when {
|
||||
totalTime == other.totalTime -> 0
|
||||
totalTime > other.totalTime -> 1
|
||||
else -> -1
|
||||
}
|
||||
}
|
||||
|
||||
if (sorting and SORT_DESCENDING != 0) {
|
||||
result *= -1
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user