This commit is contained in:
parent
855ce46b99
commit
522364dd84
@ -15,10 +15,12 @@ import io.hammerhead.karooext.models.DataPoint
|
|||||||
import io.hammerhead.karooext.models.DataType
|
import io.hammerhead.karooext.models.DataType
|
||||||
import io.hammerhead.karooext.models.StreamState
|
import io.hammerhead.karooext.models.StreamState
|
||||||
import io.hammerhead.karooext.models.UpdateGraphicConfig
|
import io.hammerhead.karooext.models.UpdateGraphicConfig
|
||||||
|
import io.hammerhead.karooext.models.UserProfile
|
||||||
import io.hammerhead.karooext.models.ViewConfig
|
import io.hammerhead.karooext.models.ViewConfig
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.filter
|
||||||
import kotlinx.coroutines.flow.filterNotNull
|
import kotlinx.coroutines.flow.filterNotNull
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@ -27,22 +29,25 @@ abstract class BaseDataType(
|
|||||||
private val applicationContext: Context,
|
private val applicationContext: Context,
|
||||||
dataTypeId: String
|
dataTypeId: String
|
||||||
) : DataTypeImpl("karoo-headwind", dataTypeId) {
|
) : DataTypeImpl("karoo-headwind", dataTypeId) {
|
||||||
abstract fun getValue(data: WeatherData): Double?
|
abstract fun getValue(data: WeatherData, userProfile: UserProfile): Double?
|
||||||
|
|
||||||
open fun getFormatDataType(): String? = null
|
open fun getFormatDataType(): String? = null
|
||||||
|
|
||||||
override fun startStream(emitter: Emitter<StreamState>) {
|
override fun startStream(emitter: Emitter<StreamState>) {
|
||||||
Log.d(KarooHeadwindExtension.TAG, "start $dataTypeId stream")
|
Log.d(KarooHeadwindExtension.TAG, "start $dataTypeId stream")
|
||||||
val job = CoroutineScope(Dispatchers.IO).launch {
|
val job = CoroutineScope(Dispatchers.IO).launch {
|
||||||
val currentWeatherData = applicationContext.streamCurrentWeatherData(karooSystemService)
|
data class StreamData(val weatherData: WeatherData, val userProfile: UserProfile)
|
||||||
val userProfile = karooSystemService.streamUserProfile()
|
|
||||||
|
val currentWeatherData = combine(applicationContext.streamCurrentWeatherData(karooSystemService).filterNotNull(), karooSystemService.streamUserProfile()) { weatherData, userProfile ->
|
||||||
|
StreamData(weatherData, userProfile)
|
||||||
|
}
|
||||||
|
|
||||||
val refreshRate = karooSystemService.getRefreshRateInMilliseconds(applicationContext)
|
val refreshRate = karooSystemService.getRefreshRateInMilliseconds(applicationContext)
|
||||||
|
|
||||||
currentWeatherData.filterNotNull()
|
currentWeatherData.filterNotNull()
|
||||||
.throttle(refreshRate)
|
.throttle(refreshRate)
|
||||||
.collect { data ->
|
.collect { (data, userProfile) ->
|
||||||
val value = getValue(data)
|
val value = getValue(data, userProfile)
|
||||||
Log.d(KarooHeadwindExtension.TAG, "$dataTypeId: $value")
|
Log.d(KarooHeadwindExtension.TAG, "$dataTypeId: $value")
|
||||||
|
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
|
|||||||
@ -3,9 +3,10 @@ package de.timklge.karooheadwind.datatypes
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import de.timklge.karooheadwind.weatherprovider.WeatherData
|
import de.timklge.karooheadwind.weatherprovider.WeatherData
|
||||||
import io.hammerhead.karooext.KarooSystemService
|
import io.hammerhead.karooext.KarooSystemService
|
||||||
|
import io.hammerhead.karooext.models.UserProfile
|
||||||
|
|
||||||
class CloudCoverDataType(karooSystemService: KarooSystemService, context: Context) : BaseDataType(karooSystemService, context, "cloudCover"){
|
class CloudCoverDataType(karooSystemService: KarooSystemService, context: Context) : BaseDataType(karooSystemService, context, "cloudCover"){
|
||||||
override fun getValue(data: WeatherData): Double? {
|
override fun getValue(data: WeatherData, userProfile: UserProfile): Double? {
|
||||||
return data.cloudCover
|
return data.cloudCover
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ abstract class ForecastDataType(private val karooSystem: KarooSystemService, typ
|
|||||||
WeatherData(
|
WeatherData(
|
||||||
time = forecastTime,
|
time = forecastTime,
|
||||||
temperature = forecastTemperature,
|
temperature = forecastTemperature,
|
||||||
relativeHumidity = 20.0,
|
relativeHumidity = 20,
|
||||||
precipitation = forecastPrecipitation,
|
precipitation = forecastPrecipitation,
|
||||||
cloudCover = 3.0,
|
cloudCover = 3.0,
|
||||||
sealevelPressure = 1013.25,
|
sealevelPressure = 1013.25,
|
||||||
@ -142,7 +142,7 @@ abstract class ForecastDataType(private val karooSystem: KarooSystemService, typ
|
|||||||
current = WeatherData(
|
current = WeatherData(
|
||||||
time = timeAtFullHour,
|
time = timeAtFullHour,
|
||||||
temperature = 20.0,
|
temperature = 20.0,
|
||||||
relativeHumidity = 20.0,
|
relativeHumidity = 20,
|
||||||
precipitation = 0.0,
|
precipitation = 0.0,
|
||||||
cloudCover = 3.0,
|
cloudCover = 3.0,
|
||||||
sealevelPressure = 1013.25,
|
sealevelPressure = 1013.25,
|
||||||
|
|||||||
@ -44,7 +44,6 @@ fun GraphicalForecast(
|
|||||||
provider = ImageProvider(getWeatherIcon(current, isNight)),
|
provider = ImageProvider(getWeatherIcon(current, isNight)),
|
||||||
contentDescription = "Current weather information",
|
contentDescription = "Current weather information",
|
||||||
contentScale = ContentScale.Fit,
|
contentScale = ContentScale.Fit,
|
||||||
colorFilter = ColorFilter.tint(ColorProvider(Color.Black, Color.White))
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import io.hammerhead.karooext.KarooSystemService
|
|||||||
import io.hammerhead.karooext.models.UserProfile
|
import io.hammerhead.karooext.models.UserProfile
|
||||||
|
|
||||||
class PrecipitationDataType(karooSystemService: KarooSystemService, context: Context) : BaseDataType(karooSystemService, context, "precipitation"){
|
class PrecipitationDataType(karooSystemService: KarooSystemService, context: Context) : BaseDataType(karooSystemService, context, "precipitation"){
|
||||||
override fun getValue(data: WeatherData): Double {
|
override fun getValue(data: WeatherData, userProfile: UserProfile): Double {
|
||||||
return millimetersInUserUnit(data.precipitation, userProfile.preferredUnit.distance == UserProfile.PreferredUnit.UnitType.IMPERIAL)
|
return millimetersInUserUnit(data.precipitation, userProfile.preferredUnit.distance == UserProfile.PreferredUnit.UnitType.IMPERIAL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,9 +3,10 @@ package de.timklge.karooheadwind.datatypes
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import de.timklge.karooheadwind.weatherprovider.WeatherData
|
import de.timklge.karooheadwind.weatherprovider.WeatherData
|
||||||
import io.hammerhead.karooext.KarooSystemService
|
import io.hammerhead.karooext.KarooSystemService
|
||||||
|
import io.hammerhead.karooext.models.UserProfile
|
||||||
|
|
||||||
class RelativeHumidityDataType(karooSystemService: KarooSystemService, context: Context) : BaseDataType(karooSystemService, context, "relativeHumidity"){
|
class RelativeHumidityDataType(karooSystemService: KarooSystemService, context: Context) : BaseDataType(karooSystemService, context, "relativeHumidity"){
|
||||||
override fun getValue(data: WeatherData): Double? {
|
override fun getValue(data: WeatherData, userProfile: UserProfile): Double? {
|
||||||
return data.relativeHumidity
|
return data.relativeHumidity.toDouble()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,9 +3,10 @@ package de.timklge.karooheadwind.datatypes
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import de.timklge.karooheadwind.weatherprovider.WeatherData
|
import de.timklge.karooheadwind.weatherprovider.WeatherData
|
||||||
import io.hammerhead.karooext.KarooSystemService
|
import io.hammerhead.karooext.KarooSystemService
|
||||||
|
import io.hammerhead.karooext.models.UserProfile
|
||||||
|
|
||||||
class SealevelPressureDataType(karooSystemService: KarooSystemService, context: Context) : BaseDataType(karooSystemService, context, "sealevelPressure"){
|
class SealevelPressureDataType(karooSystemService: KarooSystemService, context: Context) : BaseDataType(karooSystemService, context, "sealevelPressure"){
|
||||||
override fun getValue(data: WeatherData): Double? {
|
override fun getValue(data: WeatherData, userProfile: UserProfile): Double? {
|
||||||
return data.sealevelPressure
|
return data.sealevelPressure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,9 +3,10 @@ package de.timklge.karooheadwind.datatypes
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import de.timklge.karooheadwind.weatherprovider.WeatherData
|
import de.timklge.karooheadwind.weatherprovider.WeatherData
|
||||||
import io.hammerhead.karooext.KarooSystemService
|
import io.hammerhead.karooext.KarooSystemService
|
||||||
|
import io.hammerhead.karooext.models.UserProfile
|
||||||
|
|
||||||
class SurfacePressureDataType(karooSystemService: KarooSystemService, context: Context) : BaseDataType(karooSystemService, context, "surfacePressure"){
|
class SurfacePressureDataType(karooSystemService: KarooSystemService, context: Context) : BaseDataType(karooSystemService, context, "surfacePressure"){
|
||||||
override fun getValue(data: WeatherData): Double? {
|
override fun getValue(data: WeatherData, userProfile: UserProfile): Double? {
|
||||||
return data.surfacePressure
|
return data.surfacePressure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -166,7 +166,8 @@ class TailwindAndRideSpeedDataType(
|
|||||||
WindDirectionIndicatorSetting.WIND_DIRECTION -> streamData.absoluteWindDirection + 180
|
WindDirectionIndicatorSetting.WIND_DIRECTION -> streamData.absoluteWindDirection + 180
|
||||||
}
|
}
|
||||||
|
|
||||||
val text = streamData.rideSpeed?.let { String.format(Locale.current.platformLocale, "%.1f", it) } ?: ""
|
val rideSpeedInUserUnit = msInUserUnit(streamData.rideSpeed ?: 0.0, streamData.isImperial)
|
||||||
|
val text = String.format(Locale.current.platformLocale, "%.1f", rideSpeedInUserUnit)
|
||||||
|
|
||||||
val wideMode = config.gridSize.first == 60
|
val wideMode = config.gridSize.first == 60
|
||||||
|
|
||||||
|
|||||||
@ -4,9 +4,10 @@ import android.content.Context
|
|||||||
import de.timklge.karooheadwind.weatherprovider.WeatherData
|
import de.timklge.karooheadwind.weatherprovider.WeatherData
|
||||||
import io.hammerhead.karooext.KarooSystemService
|
import io.hammerhead.karooext.KarooSystemService
|
||||||
import io.hammerhead.karooext.models.DataType
|
import io.hammerhead.karooext.models.DataType
|
||||||
|
import io.hammerhead.karooext.models.UserProfile
|
||||||
|
|
||||||
class TemperatureDataType(karooSystemService: KarooSystemService, context: Context) : BaseDataType(karooSystemService, context, "temperature"){
|
class TemperatureDataType(karooSystemService: KarooSystemService, context: Context) : BaseDataType(karooSystemService, context, "temperature"){
|
||||||
override fun getValue(data: WeatherData): Double {
|
override fun getValue(data: WeatherData, userProfile: UserProfile): Double {
|
||||||
return data.temperature
|
return data.temperature
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -88,7 +88,7 @@ class WeatherDataType(
|
|||||||
emit(StreamData(
|
emit(StreamData(
|
||||||
WeatherData(
|
WeatherData(
|
||||||
Instant.now().epochSecond, 0.0,
|
Instant.now().epochSecond, 0.0,
|
||||||
20.0, 50.0, 3.0, 0.0, 1013.25, 980.0, 15.0, 30.0, 30.0,
|
20, 50.0, 3.0, 0.0, 1013.25, 980.0, 15.0, 30.0, 30.0,
|
||||||
WeatherInterpretation.getKnownWeatherCodes().random(), isForecast = false,
|
WeatherInterpretation.getKnownWeatherCodes().random(), isForecast = false,
|
||||||
isNight = listOf(true, false).random()
|
isNight = listOf(true, false).random()
|
||||||
), HeadwindSettings(), isVisible = true))
|
), HeadwindSettings(), isVisible = true))
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import io.hammerhead.karooext.internal.ViewEmitter
|
|||||||
import io.hammerhead.karooext.models.ShowCustomStreamState
|
import io.hammerhead.karooext.models.ShowCustomStreamState
|
||||||
import io.hammerhead.karooext.models.StreamState
|
import io.hammerhead.karooext.models.StreamState
|
||||||
import io.hammerhead.karooext.models.UpdateGraphicConfig
|
import io.hammerhead.karooext.models.UpdateGraphicConfig
|
||||||
|
import io.hammerhead.karooext.models.UserProfile
|
||||||
import io.hammerhead.karooext.models.ViewConfig
|
import io.hammerhead.karooext.models.ViewConfig
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@ -51,7 +52,7 @@ class WindDirectionDataType(val karooSystem: KarooSystemService, context: Contex
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getValue(data: WeatherData): Double {
|
override fun getValue(data: WeatherData, userProfile: UserProfile): Double {
|
||||||
return data.windDirection
|
return data.windDirection
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,9 +3,10 @@ package de.timklge.karooheadwind.datatypes
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import de.timklge.karooheadwind.weatherprovider.WeatherData
|
import de.timklge.karooheadwind.weatherprovider.WeatherData
|
||||||
import io.hammerhead.karooext.KarooSystemService
|
import io.hammerhead.karooext.KarooSystemService
|
||||||
|
import io.hammerhead.karooext.models.UserProfile
|
||||||
|
|
||||||
class WindGustsDataType(karooSystemService: KarooSystemService, context: Context) : BaseDataType(karooSystemService, context, "windGusts"){
|
class WindGustsDataType(karooSystemService: KarooSystemService, context: Context) : BaseDataType(karooSystemService, context, "windGusts"){
|
||||||
override fun getValue(data: WeatherData): Double {
|
override fun getValue(data: WeatherData, userProfile: UserProfile): Double {
|
||||||
return data.windGusts
|
return data.windGusts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,9 +3,10 @@ package de.timklge.karooheadwind.datatypes
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import de.timklge.karooheadwind.weatherprovider.WeatherData
|
import de.timklge.karooheadwind.weatherprovider.WeatherData
|
||||||
import io.hammerhead.karooext.KarooSystemService
|
import io.hammerhead.karooext.KarooSystemService
|
||||||
|
import io.hammerhead.karooext.models.UserProfile
|
||||||
|
|
||||||
class WindSpeedDataType(karooSystemService: KarooSystemService, context: Context) : BaseDataType(karooSystemService, context, "windSpeed"){
|
class WindSpeedDataType(karooSystemService: KarooSystemService, context: Context) : BaseDataType(karooSystemService, context, "windSpeed"){
|
||||||
override fun getValue(data: WeatherData): Double {
|
override fun getValue(data: WeatherData, userProfile: UserProfile): Double {
|
||||||
return data.windSpeed
|
return data.windSpeed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ fun WeatherWidget(
|
|||||||
isImperial: Boolean,
|
isImperial: Boolean,
|
||||||
isNight: Boolean
|
isNight: Boolean
|
||||||
) {
|
) {
|
||||||
val fontSize = 20.sp
|
val fontSize = 18.sp
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth().padding(5.dp),
|
modifier = Modifier.fillMaxWidth().padding(5.dp),
|
||||||
@ -106,7 +106,6 @@ fun WeatherWidget(
|
|||||||
)
|
)
|
||||||
|
|
||||||
Column(horizontalAlignment = Alignment.End) {
|
Column(horizontalAlignment = Alignment.End) {
|
||||||
// Temperature (larger)
|
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
|
|||||||
@ -33,7 +33,7 @@ data class OpenWeatherMapForecastData(
|
|||||||
|
|
||||||
return WeatherData(
|
return WeatherData(
|
||||||
temperature = temp,
|
temperature = temp,
|
||||||
relativeHumidity = humidity.toDouble(),
|
relativeHumidity = humidity,
|
||||||
precipitation = rain?.h1 ?: 0.0,
|
precipitation = rain?.h1 ?: 0.0,
|
||||||
cloudCover = clouds.toDouble(),
|
cloudCover = clouds.toDouble(),
|
||||||
surfacePressure = pressure.toDouble(),
|
surfacePressure = pressure.toDouble(),
|
||||||
|
|||||||
@ -23,7 +23,7 @@ data class OpenWeatherMapWeatherData(
|
|||||||
|
|
||||||
fun toWeatherData(): WeatherData = WeatherData(
|
fun toWeatherData(): WeatherData = WeatherData(
|
||||||
temperature = temp,
|
temperature = temp,
|
||||||
relativeHumidity = humidity.toDouble(),
|
relativeHumidity = humidity,
|
||||||
precipitation = rain?.h1 ?: 0.0,
|
precipitation = rain?.h1 ?: 0.0,
|
||||||
cloudCover = clouds.toDouble(),
|
cloudCover = clouds.toDouble(),
|
||||||
surfacePressure = pressure.toDouble(),
|
surfacePressure = pressure.toDouble(),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user