Add status label to main activity that indicates background service status for debugging (#66)
This commit is contained in:
parent
107c7a575d
commit
ab8d7bec3c
@ -94,6 +94,8 @@ class KarooHeadwindExtension : KarooExtension("karoo-headwind", BuildConfig.VERS
|
|||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
|
||||||
karooSystem = KarooSystemService(applicationContext)
|
karooSystem = KarooSystemService(applicationContext)
|
||||||
|
ServiceStatusSingleton.getInstance().setServiceStatus(true)
|
||||||
|
|
||||||
|
|
||||||
updateLastKnownGpsJob = CoroutineScope(Dispatchers.IO).launch {
|
updateLastKnownGpsJob = CoroutineScope(Dispatchers.IO).launch {
|
||||||
karooSystem.updateLastKnownGps(this@KarooHeadwindExtension)
|
karooSystem.updateLastKnownGps(this@KarooHeadwindExtension)
|
||||||
|
|||||||
@ -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<Boolean> = MutableStateFlow(false)
|
||||||
|
|
||||||
|
fun getServiceStatus(): StateFlow<Boolean> {
|
||||||
|
return serviceStatus
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setServiceStatus(status: Boolean) {
|
||||||
|
serviceStatus.value = status
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -27,11 +27,11 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
|||||||
import de.timklge.karooheadwind.HeadwindStats
|
import de.timklge.karooheadwind.HeadwindStats
|
||||||
import de.timklge.karooheadwind.KarooHeadwindExtension
|
import de.timklge.karooheadwind.KarooHeadwindExtension
|
||||||
import de.timklge.karooheadwind.R
|
import de.timklge.karooheadwind.R
|
||||||
|
import de.timklge.karooheadwind.ServiceStatusSingleton
|
||||||
import de.timklge.karooheadwind.TemperatureUnit
|
import de.timklge.karooheadwind.TemperatureUnit
|
||||||
import de.timklge.karooheadwind.WeatherInterpretation
|
import de.timklge.karooheadwind.WeatherInterpretation
|
||||||
import de.timklge.karooheadwind.datatypes.ForecastDataType
|
import de.timklge.karooheadwind.datatypes.ForecastDataType
|
||||||
import de.timklge.karooheadwind.datatypes.WeatherDataType.Companion.timeFormatter
|
import de.timklge.karooheadwind.datatypes.WeatherDataType.Companion.timeFormatter
|
||||||
import de.timklge.karooheadwind.datatypes.WeatherForecastDataType
|
|
||||||
import de.timklge.karooheadwind.datatypes.getShortDateFormatter
|
import de.timklge.karooheadwind.datatypes.getShortDateFormatter
|
||||||
import de.timklge.karooheadwind.getGpsCoordinateFlow
|
import de.timklge.karooheadwind.getGpsCoordinateFlow
|
||||||
import de.timklge.karooheadwind.streamCurrentWeatherData
|
import de.timklge.karooheadwind.streamCurrentWeatherData
|
||||||
@ -113,7 +113,14 @@ fun WeatherScreen(onFinish: () -> Unit) {
|
|||||||
val lastPositionDistanceStr =
|
val lastPositionDistanceStr =
|
||||||
lastPosition?.let { dist -> " (${dist.roundToInt()} km away)" } ?: ""
|
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(
|
val successfulTime = LocalDateTime.ofInstant(
|
||||||
Instant.ofEpochMilli(
|
Instant.ofEpochMilli(
|
||||||
stats.lastSuccessfulWeatherRequest ?: 0
|
stats.lastSuccessfulWeatherRequest ?: 0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user