Skip to content

Commit

Permalink
Do not clear view on flow close
Browse files Browse the repository at this point in the history
  • Loading branch information
timklge committed Dec 31, 2024
1 parent b700042 commit 543bcaf
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ android {
}
release {
signingConfig = signingConfigs.getByName("release")
// isMinifyEnabled = false
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/de/timklge/karooheadwind/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) }

Expand Down

0 comments on commit 543bcaf

Please sign in to comment.