Reduce forecast datafield update frequency, reduce image resolution (#103)
@ -39,6 +39,7 @@ import de.timklge.karooheadwind.streamSettings
|
||||
import de.timklge.karooheadwind.streamUpcomingRoute
|
||||
import de.timklge.karooheadwind.streamUserProfile
|
||||
import de.timklge.karooheadwind.streamWidgetSettings
|
||||
import de.timklge.karooheadwind.throttle
|
||||
import io.hammerhead.karooext.KarooSystemService
|
||||
import io.hammerhead.karooext.extension.DataTypeImpl
|
||||
import io.hammerhead.karooext.internal.ViewEmitter
|
||||
@ -52,6 +53,7 @@ import kotlinx.coroutines.awaitCancellation
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.launch
|
||||
@ -59,6 +61,7 @@ import java.time.Instant
|
||||
import java.time.ZoneId
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.temporal.ChronoUnit
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
abstract class ForecastDataType(private val karooSystem: KarooSystemService, typeId: String) : DataTypeImpl("karoo-headwind", typeId) {
|
||||
@ -191,8 +194,16 @@ abstract class ForecastDataType(private val karooSystem: KarooSystemService, typ
|
||||
context.streamCurrentForecastWeatherData(),
|
||||
settingsAndProfileStream,
|
||||
context.streamWidgetSettings(),
|
||||
karooSystem.getHeadingFlow(context),
|
||||
karooSystem.streamUpcomingRoute()
|
||||
karooSystem.getHeadingFlow(context).throttle(60_000L),
|
||||
karooSystem.streamUpcomingRoute().distinctUntilChanged { old, new ->
|
||||
val oldDistance = old?.distanceAlongRoute
|
||||
val newDistance = new?.distanceAlongRoute
|
||||
|
||||
if (oldDistance == null && newDistance == null) return@distinctUntilChanged true
|
||||
if (oldDistance == null || newDistance == null) return@distinctUntilChanged false
|
||||
|
||||
abs(oldDistance - newDistance) < 100
|
||||
}
|
||||
) { weatherData, settings, widgetSettings, heading, upcomingRoute ->
|
||||
StreamData(
|
||||
data = weatherData,
|
||||
|
||||
|
Before Width: | Height: | Size: 980 B After Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 6.3 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 6.3 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 6.1 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 6.4 KiB |
|
Before Width: | Height: | Size: 7.7 KiB After Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 6.4 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 5.9 KiB |