Also grow grade powerbar on descents, do not show if grade < 0.5 % (#51)
This commit is contained in:
parent
f99a82ec74
commit
f25ab5d7db
@ -38,6 +38,7 @@ import kotlinx.coroutines.flow.map
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
import kotlin.math.absoluteValue
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
fun remap(value: Double?, fromMin: Double, fromMax: Double, toMin: Double, toMax: Double): Double? {
|
fun remap(value: Double?, fromMin: Double, fromMax: Double, toMin: Double, toMax: Double): Double? {
|
||||||
@ -364,12 +365,17 @@ class Window(
|
|||||||
|
|
||||||
powerbarsWithGradeSource.forEach { powerbar ->
|
powerbarsWithGradeSource.forEach { powerbar ->
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
|
if (value.absoluteValue >= 0.5) {
|
||||||
val minGradient = streamData.settings?.minGradient ?: PowerbarSettings.defaultMinGradient
|
val minGradient = streamData.settings?.minGradient ?: PowerbarSettings.defaultMinGradient
|
||||||
val maxGradient = streamData.settings?.maxGradient ?: PowerbarSettings.defaultMaxGradient
|
val maxGradient = streamData.settings?.maxGradient ?: PowerbarSettings.defaultMaxGradient
|
||||||
|
|
||||||
|
powerbar.progress = remap(value.absoluteValue, minGradient.toDouble(), maxGradient.toDouble(), 0.0, 1.0)
|
||||||
|
} else {
|
||||||
|
powerbar.progress = null
|
||||||
|
}
|
||||||
|
|
||||||
val colorRes = getInclineIndicatorColor(value.toFloat()) ?: R.color.zone0
|
val colorRes = getInclineIndicatorColor(value.toFloat()) ?: R.color.zone0
|
||||||
powerbar.progressColor = context.getColor(colorRes)
|
powerbar.progressColor = context.getColor(colorRes)
|
||||||
powerbar.progress = remap(value.toDouble(), minGradient.toDouble(), maxGradient.toDouble(), 0.0, 1.0)
|
|
||||||
powerbar.label = "${String.format(Locale.getDefault(), "%.1f", value)}%"
|
powerbar.label = "${String.format(Locale.getDefault(), "%.1f", value)}%"
|
||||||
|
|
||||||
Log.d(TAG, "Grade: $value")
|
Log.d(TAG, "Grade: $value")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user