Fix remaining distance bar shows label "null" if distance is unknown (#50)

This commit is contained in:
timklge 2025-08-09 15:12:43 +02:00 committed by GitHub
parent f25ab5d7db
commit 304a984110
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -201,7 +201,7 @@ class Window(
data class BarProgress( data class BarProgress(
val progress: Double?, val progress: Double?,
val label: String, val label: String?,
) )
private fun getRouteProgress(userProfile: UserProfile, riddenDistance: Double?, routeEndAt: Double?, distanceToDestination: Double?): BarProgress { private fun getRouteProgress(userProfile: UserProfile, riddenDistance: Double?, routeEndAt: Double?, distanceToDestination: Double?): BarProgress {
@ -211,7 +211,7 @@ class Window(
else -> riddenDistance?.times(0.001)?.roundToInt() // Kilometers else -> riddenDistance?.times(0.001)?.roundToInt() // Kilometers
} }
return BarProgress(routeProgress, "$routeProgressInUserUnit") return BarProgress(routeProgress, routeProgressInUserUnit?.toString())
} }
private fun getRemainingRouteProgress(userProfile: UserProfile, riddenDistance: Double?, routeEndAt: Double?, distanceToDestination: Double?): BarProgress { private fun getRemainingRouteProgress(userProfile: UserProfile, riddenDistance: Double?, routeEndAt: Double?, distanceToDestination: Double?): BarProgress {
@ -221,7 +221,7 @@ class Window(
else -> distanceToDestination?.times(0.001)?.roundToInt() // Kilometers else -> distanceToDestination?.times(0.001)?.roundToInt() // Kilometers
} }
return BarProgress(routeProgress, "$distanceToDestinationInUserUnit") return BarProgress(routeProgress, distanceToDestinationInUserUnit?.toString())
} }
private suspend fun streamRouteProgress( private suspend fun streamRouteProgress(
@ -275,7 +275,7 @@ class Window(
powerbarsWithRouteProgressSource.forEach { powerbar -> powerbarsWithRouteProgressSource.forEach { powerbar ->
powerbar.progressColor = context.getColor(R.color.zone0) powerbar.progressColor = context.getColor(R.color.zone0)
powerbar.progress = barProgress.progress powerbar.progress = barProgress.progress
powerbar.label = barProgress.label powerbar.label = barProgress.label ?: ""
powerbar.invalidate() powerbar.invalidate()
} }
} }