Do not clear view on flow close
This commit is contained in:
parent
b7000428ae
commit
543bcaf478
@ -38,7 +38,7 @@ android {
|
||||
}
|
||||
release {
|
||||
signingConfig = signingConfigs.getByName("release")
|
||||
// isMinifyEnabled = false
|
||||
isMinifyEnabled = false
|
||||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ fun Context.streamCurrentWeatherData(): Flow<OpenMeteoCurrentWeatherResponse> {
|
||||
val data = settingsJson[currentDataKey]
|
||||
data?.let { d -> jsonWithUnknownKeys.decodeFromString<OpenMeteoCurrentWeatherResponse>(d) }
|
||||
} catch (e: Throwable) {
|
||||
Log.e(KarooHeadwindExtension.TAG, "Failed to read preferences", e)
|
||||
Log.e(KarooHeadwindExtension.TAG, "Failed to read weather data", e)
|
||||
null
|
||||
}
|
||||
}.filterNotNull().distinctUntilChanged().filter { it.current.time * 1000 >= System.currentTimeMillis() - (1000 * 60 * 60 * 12) }
|
||||
@ -107,7 +107,7 @@ fun Context.streamWidgetSettings(): Flow<HeadwindWidgetSettings> {
|
||||
jsonWithUnknownKeys.decodeFromString<HeadwindWidgetSettings>(HeadwindWidgetSettings.defaultWidgetSettings)
|
||||
}
|
||||
} catch(e: Throwable){
|
||||
Log.e(KarooHeadwindExtension.TAG, "Failed to read preferences", e)
|
||||
Log.e(KarooHeadwindExtension.TAG, "Failed to read widget preferences", e)
|
||||
jsonWithUnknownKeys.decodeFromString<HeadwindWidgetSettings>(HeadwindWidgetSettings.defaultWidgetSettings)
|
||||
}
|
||||
}.distinctUntilChanged()
|
||||
|
||||
@ -95,12 +95,7 @@ class HeadwindDirectionDataType(
|
||||
}
|
||||
|
||||
val viewJob = CoroutineScope(Dispatchers.IO).launch {
|
||||
flow.onCompletion {
|
||||
// Clear view on completion
|
||||
val result = glance.compose(context, DpSize.Unspecified) { }
|
||||
emitter.updateView(result.remoteViews)
|
||||
}
|
||||
.collect { streamData ->
|
||||
flow.collect { streamData ->
|
||||
Log.d(KarooHeadwindExtension.TAG, "Updating headwind direction view")
|
||||
val windSpeed = streamData.windSpeed
|
||||
val windDirection = when (streamData.settings.windDirectionIndicatorSetting){
|
||||
|
||||
@ -86,11 +86,6 @@ class WeatherDataType(
|
||||
context.streamCurrentWeatherData()
|
||||
.combine(context.streamSettings(karooSystem)) { data, settings -> StreamData(data, settings) }
|
||||
.combine(karooSystem.streamUserProfile()) { data, profile -> data.copy(profile = profile) }
|
||||
.onCompletion {
|
||||
// Clear view on completion
|
||||
val result = glance.compose(context, DpSize.Unspecified) { }
|
||||
emitter.updateView(result.remoteViews)
|
||||
}
|
||||
.collect { (data, settings, userProfile) ->
|
||||
Log.d(KarooHeadwindExtension.TAG, "Updating weather view")
|
||||
val interpretation = WeatherInterpretation.fromWeatherCode(data.current.weatherCode)
|
||||
|
||||
@ -130,11 +130,6 @@ class WeatherForecastDataType(
|
||||
.combine(context.streamSettings(karooSystem)) { data, settings -> StreamData(data, settings) }
|
||||
.combine(karooSystem.streamUserProfile()) { data, profile -> data.copy(profile = profile) }
|
||||
.combine(context.streamWidgetSettings()) { data, widgetSettings -> data.copy(widgetSettings = widgetSettings) }
|
||||
.onCompletion {
|
||||
// Clear view on completion
|
||||
val result = glance.compose(context, DpSize.Unspecified) { }
|
||||
emitter.updateView(result.remoteViews)
|
||||
}
|
||||
.collect { (data, settings, widgetSettings, userProfile) ->
|
||||
Log.d(KarooHeadwindExtension.TAG, "Updating weather view")
|
||||
|
||||
|
||||
@ -32,6 +32,7 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import de.timklge.karooheadwind.datatypes.GpsCoordinates
|
||||
import de.timklge.karooheadwind.getGpsCoordinateFlow
|
||||
import de.timklge.karooheadwind.saveSettings
|
||||
@ -130,7 +131,7 @@ fun MainScreen() {
|
||||
var selectedRoundLocationSetting by remember { mutableStateOf(RoundLocationSetting.KM_2) }
|
||||
|
||||
val stats by ctx.streamStats().collectAsState(HeadwindStats())
|
||||
val location by karooSystem.getGpsCoordinateFlow(ctx).collectAsState(initial = null)
|
||||
val location by karooSystem.getGpsCoordinateFlow(ctx).collectAsStateWithLifecycle(null)
|
||||
|
||||
var savedDialogVisible by remember { mutableStateOf(false) }
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user