Fix headwind forecast field does not show preview (#165)

This commit is contained in:
timklge 2025-08-15 21:20:56 +02:00 committed by GitHub
parent 917770e45a
commit 1fe7eb1a16
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -55,7 +55,6 @@ class HeadwindForecastDataType(karooSystem: KarooSystemService) : LineGraphForec
} }
val headwindPoints = try { val headwindPoints = try {
if (upcomingRoute != null){
(0..<HEADWIND_SAMPLE_COUNT).mapNotNull { i -> (0..<HEADWIND_SAMPLE_COUNT).mapNotNull { i ->
val t = i / HEADWIND_SAMPLE_COUNT.toDouble() val t = i / HEADWIND_SAMPLE_COUNT.toDouble()
@ -67,6 +66,11 @@ class HeadwindForecastDataType(karooSystem: KarooSystemService) : LineGraphForec
y = headwindSpeed) y = headwindSpeed)
} }
if (upcomingRoute == null) {
Log.e(KarooHeadwindExtension.TAG, "Upcoming route is null")
return@mapNotNull null
}
val beforeLineData = lineData.getOrNull(floor((lineData.size) * t).toInt().coerceAtLeast(0)) ?: lineData.firstOrNull() val beforeLineData = lineData.getOrNull(floor((lineData.size) * t).toInt().coerceAtLeast(0)) ?: lineData.firstOrNull()
val afterLineData = lineData.getOrNull(ceil((lineData.size) * t).toInt().coerceAtLeast(0)) ?: lineData.lastOrNull() val afterLineData = lineData.getOrNull(ceil((lineData.size) * t).toInt().coerceAtLeast(0)) ?: lineData.lastOrNull()
@ -115,9 +119,6 @@ class HeadwindForecastDataType(karooSystem: KarooSystemService) : LineGraphForec
y = headwindSpeedInUserUnit.toFloat() y = headwindSpeedInUserUnit.toFloat()
) )
} }
} else {
emptyList()
}
} catch(e: Exception) { } catch(e: Exception) {
Log.e(KarooHeadwindExtension.TAG, "Error calculating headwind points", e) Log.e(KarooHeadwindExtension.TAG, "Error calculating headwind points", e)
emptyList() emptyList()