diff --git a/app/src/main/kotlin/de/timklge/karooheadwind/KarooHeadwindExtension.kt b/app/src/main/kotlin/de/timklge/karooheadwind/KarooHeadwindExtension.kt index 47de888..8e13d31 100644 --- a/app/src/main/kotlin/de/timklge/karooheadwind/KarooHeadwindExtension.kt +++ b/app/src/main/kotlin/de/timklge/karooheadwind/KarooHeadwindExtension.kt @@ -94,6 +94,8 @@ class KarooHeadwindExtension : KarooExtension("karoo-headwind", BuildConfig.VERS super.onCreate() karooSystem = KarooSystemService(applicationContext) + ServiceStatusSingleton.getInstance().setServiceStatus(true) + updateLastKnownGpsJob = CoroutineScope(Dispatchers.IO).launch { karooSystem.updateLastKnownGps(this@KarooHeadwindExtension) diff --git a/app/src/main/kotlin/de/timklge/karooheadwind/ServiceStatusSingleton.kt b/app/src/main/kotlin/de/timklge/karooheadwind/ServiceStatusSingleton.kt new file mode 100644 index 0000000..68afbaa --- /dev/null +++ b/app/src/main/kotlin/de/timklge/karooheadwind/ServiceStatusSingleton.kt @@ -0,0 +1,28 @@ +package de.timklge.karooheadwind + +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow + +class ServiceStatusSingleton private constructor() { + companion object { + private var instance: ServiceStatusSingleton? = null + + @Synchronized + fun getInstance(): ServiceStatusSingleton { + if (instance == null) { + instance = ServiceStatusSingleton() + } + return instance as ServiceStatusSingleton + } + } + + private val serviceStatus: MutableStateFlow = MutableStateFlow(false) + + fun getServiceStatus(): StateFlow { + return serviceStatus + } + + fun setServiceStatus(status: Boolean) { + serviceStatus.value = status + } +} \ No newline at end of file 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 d069886..b7f1b16 100644 --- a/app/src/main/kotlin/de/timklge/karooheadwind/screens/WeatherScreen.kt +++ b/app/src/main/kotlin/de/timklge/karooheadwind/screens/WeatherScreen.kt @@ -27,11 +27,11 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import de.timklge.karooheadwind.HeadwindStats import de.timklge.karooheadwind.KarooHeadwindExtension import de.timklge.karooheadwind.R +import de.timklge.karooheadwind.ServiceStatusSingleton import de.timklge.karooheadwind.TemperatureUnit import de.timklge.karooheadwind.WeatherInterpretation import de.timklge.karooheadwind.datatypes.ForecastDataType import de.timklge.karooheadwind.datatypes.WeatherDataType.Companion.timeFormatter -import de.timklge.karooheadwind.datatypes.WeatherForecastDataType import de.timklge.karooheadwind.datatypes.getShortDateFormatter import de.timklge.karooheadwind.getGpsCoordinateFlow import de.timklge.karooheadwind.streamCurrentWeatherData @@ -113,7 +113,14 @@ fun WeatherScreen(onFinish: () -> Unit) { val lastPositionDistanceStr = lastPosition?.let { dist -> " (${dist.roundToInt()} km away)" } ?: "" - if (stats.failedWeatherRequest != null && (stats.lastSuccessfulWeatherRequest == null || stats.failedWeatherRequest!! > stats.lastSuccessfulWeatherRequest!!)) { + val serviceStatus by ServiceStatusSingleton.getInstance().getServiceStatus().collectAsStateWithLifecycle(false) + + if (!serviceStatus){ + Text( + modifier = Modifier.padding(5.dp), + text = "Attempting to connect to weather background service..." + ) + } else if (stats.failedWeatherRequest != null && (stats.lastSuccessfulWeatherRequest == null || stats.failedWeatherRequest!! > stats.lastSuccessfulWeatherRequest!!)) { val successfulTime = LocalDateTime.ofInstant( Instant.ofEpochMilli( stats.lastSuccessfulWeatherRequest ?: 0