add proper lap sorting

This commit is contained in:
tibbi
2018-03-08 13:11:16 +01:00
parent 79a4f9494f
commit 916e7db548
4 changed files with 51 additions and 5 deletions

View File

@ -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
}
}