diff --git a/app/src/main/kotlin/de/timklge/karooheadwind/datatypes/TailwindAndRideSpeedDataType.kt b/app/src/main/kotlin/de/timklge/karooheadwind/datatypes/TailwindAndRideSpeedDataType.kt index 4247cf8..940c265 100644 --- a/app/src/main/kotlin/de/timklge/karooheadwind/datatypes/TailwindAndRideSpeedDataType.kt +++ b/app/src/main/kotlin/de/timklge/karooheadwind/datatypes/TailwindAndRideSpeedDataType.kt @@ -44,8 +44,9 @@ import kotlin.math.absoluteValue import kotlin.math.cos import kotlin.math.roundToInt -fun interpolateColor(color1: Color, color2: Color, factor: Float): Color { - return Color(ColorUtils.blendARGB(color1.toArgb(), color2.toArgb(), factor)) +fun interpolateColor(color1: Color, color2: Color, lowerBound: Double, upperBound: Double, actualValue: Double): Color { + val factor = if (upperBound == lowerBound) 0.0 else ((actualValue - lowerBound) / (upperBound - lowerBound)).coerceIn(0.0, 1.0) + return Color(ColorUtils.blendARGB(color1.toArgb(), color2.toArgb(), factor.toFloat())) } fun interpolateWindColor(windSpeedInKmh: Double, night: Boolean, context: Context): Color { @@ -55,11 +56,11 @@ fun interpolateWindColor(windSpeedInKmh: Double, night: Boolean, context: Contex val orange = Color(ContextCompat.getColor(context, if(night) R.color.orange else R.color.hOrange)) return when { - windSpeedInKmh <= -15 -> green - windSpeedInKmh >= 30 -> red - windSpeedInKmh in -15.0..0.0 -> interpolateColor(green, default, (windSpeedInKmh + 15).toFloat() / 15) - windSpeedInKmh in 0.0..15.0 -> interpolateColor(default, orange, windSpeedInKmh.toFloat() / 15) - else -> interpolateColor(orange, red, (windSpeedInKmh - 15).toFloat() / 15) + windSpeedInKmh <= -10 -> green + windSpeedInKmh >= 15 -> red + windSpeedInKmh in -10.0..0.0 -> interpolateColor(green, default, -10.0, 0.0, windSpeedInKmh) + windSpeedInKmh in 0.0..10.0 -> interpolateColor(default, orange, 0.0, 10.0, windSpeedInKmh) + else -> interpolateColor(orange, red, 10.0, 15.0, windSpeedInKmh) } } diff --git a/app/src/main/kotlin/de/timklge/karooheadwind/screens/WeatherScreen.kt b/app/src/main/kotlin/de/timklge/karooheadwind/screens/WeatherScreen.kt index 425c240..9b997a8 100644 --- a/app/src/main/kotlin/de/timklge/karooheadwind/screens/WeatherScreen.kt +++ b/app/src/main/kotlin/de/timklge/karooheadwind/screens/WeatherScreen.kt @@ -118,7 +118,7 @@ fun WeatherScreen(onFinish: () -> Unit) { if (!serviceStatus){ Text( modifier = Modifier.padding(5.dp), - text = "Attempting to connect to weather background service..." + text = "Attempting to connect to weather background service... Please reboot your Karoo if this takes too long." ) } else if (stats.failedWeatherRequest != null && (stats.lastSuccessfulWeatherRequest == null || stats.failedWeatherRequest!! > stats.lastSuccessfulWeatherRequest!!)) { val successfulTime = LocalDateTime.ofInstant(