Add managed location to weather plugin API

This commit is contained in:
MM20
2024-05-03 13:02:17 +02:00
parent b0f9ffd473
commit 1d6688831c
19 changed files with 256 additions and 100 deletions
@@ -393,6 +393,7 @@ data class LatLon(
data class ProviderSettings(
val locationId: String? = null,
val locationName: String? = null,
val managedLocation: Boolean = false,
)
@Serializable
@@ -20,6 +20,10 @@ sealed interface WeatherLocation {
override val name: String,
val locationId: String,
) : WeatherLocation
data object Managed : WeatherLocation {
override val name: String = "Managed by plugin"
}
}
data class WeatherSettingsData(
@@ -51,6 +55,10 @@ class WeatherSettings internal constructor(
val location = launcherDataStore.data.map {
val providerSettings = it.weatherProviderSettings[it.weatherProvider]
if (providerSettings?.managedLocation == true) {
return@map WeatherLocation.Managed
}
val id = providerSettings?.locationId
val name = providerSettings?.locationName
@@ -87,6 +95,7 @@ class WeatherSettings internal constructor(
providerSettings.copy(
locationId = null,
locationName = null,
managedLocation = false,
)
)
}
@@ -104,7 +113,27 @@ class WeatherSettings internal constructor(
it.weatherProvider,
providerSettings.copy(
locationId = location.locationId,
locationName = location.name
locationName = location.name,
managedLocation = false,
)
)
}
)
}
is WeatherLocation.Managed -> {
it.copy(
weatherLocation = null,
weatherLocationName = null,
weatherAutoLocation = true,
weatherLastUpdate = 0L,
weatherProviderSettings = it.weatherProviderSettings.toMutableMap().apply {
put(
it.weatherProvider,
providerSettings.copy(
locationId = null,
locationName = null,
managedLocation = true,
)
)
}