Fix city selection vs dashboard; Map/Manage updates; workspace and API logging

Made-with: Cursor
This commit is contained in:
2026-04-06 23:49:35 +02:00
parent 34ad7e4af7
commit 0a79ee5e04
7 changed files with 50 additions and 19 deletions

View File

@@ -24,6 +24,7 @@ interface CityService {
/**
* If [DashboardCityContext.cityId] is missing, tries to resolve it from the local city DB
* using the stored English name and updates preferences.
* Does not notify [observeDashboardCityContext] (avoids re-entrant emissions during dashboard load).
*/
suspend fun refreshDashboardCityIdentity()
@@ -80,9 +81,9 @@ interface CityService {
suspend fun setDetectAutomatically(enabled: Boolean)
/**
* Refreshes the selected city from location. Used when detect automatically is on.
* Refreshes the selected city from location when [getDetectAutomatically] is true.
* Resolves closest city from the cities DB and updates stored city.
* No-op if location is null or no matching city found.
* No-op if auto-detect is off, location is null, or no matching city found.
*/
suspend fun refreshCityFromLocation(location: Location?)

View File

@@ -101,6 +101,7 @@ class CityServiceImpl @Inject constructor(
}
override suspend fun refreshCityFromLocation(location: Location?) {
if (!getDetectAutomatically()) return
if (location == null) return
val cities = ensureCitiesInDb()
val resolvedCity = findClosestCity(cities, location.latitude, location.longitude)
@@ -121,7 +122,6 @@ class CityServiceImpl @Inject constructor(
val city = cityLocalDataSource.getAllCities()
.find { it.nameEn.equals(nameEn, ignoreCase = true) } ?: return
prefs.edit().putString(KEY_DASHBOARD_CITY_ID, city.id).apply()
pushContextUpdate()
}
override suspend fun getResolvedDashboardCityContext(): DashboardCityContext {

View File

@@ -114,7 +114,12 @@ class DashboardMetricsRepositoryImpl @Inject constructor(
}
private fun mapLastRow(row: CityAverageLastQuery.CityAverageLast): SensorSampleRow? {
val t = GraphqlDateTimeParser.parseToEpochMillis(row.time) ?: return null
val parsedTime = GraphqlDateTimeParser.parseToEpochMillis(row.time)
val hasAnyReading = row.Temp != null || row.Hum != null || row.Press != null ||
row.PMS1 != null || row.PMS25 != null || row.PMS10 != null ||
row.radRg != null || row.PPM != null || row.IKAV != null ||
row.CO2 != null || row.VOC != null || row.AQI != null
val t = parsedTime ?: if (hasAnyReading) System.currentTimeMillis() else return null
return SensorSampleRow(
epochMillis = t,
temp = row.Temp?.toFloat(),