diff --git a/android/src/main/kotlin/foundation/e/blissweather/worker/WorkerUtils.kt b/android/src/main/kotlin/foundation/e/blissweather/worker/WorkerUtils.kt index c618101a5aee61249538ae11b355d8fb433ecf43..3039f13e1671940c9d382750498319b412eee2c8 100644 --- a/android/src/main/kotlin/foundation/e/blissweather/worker/WorkerUtils.kt +++ b/android/src/main/kotlin/foundation/e/blissweather/worker/WorkerUtils.kt @@ -14,6 +14,7 @@ import foundation.e.blissweather.ApiSuccess import foundation.e.blissweather.api.OpenWeatherRepository import foundation.e.blissweather.models.CombinedWeatherResponse import foundation.e.blissweather.models.Coordinate +import java.util.Locale object WorkerUtils { private const val TAG = "WorkerUtils" @@ -35,6 +36,30 @@ object WorkerUtils { } } + val reverseGeocode = + when (val result = weatherRepository.getLocationNameByCoords(coords)) { + is ApiSuccess -> result.data + is ApiError -> { + Log.e(TAG, "[${result.code}] ReverseGeocode Error: ${result.message}") + null + } + is ApiException -> { + Log.e(TAG, "ReverseGeocode Error:", result.e) + null + } + } + + if (current != null && reverseGeocode != null) { + val name = + reverseGeocode[0] + .localNames + .getOrDefault(Locale.getDefault().language, reverseGeocode[0].name) + + if (name.isNotEmpty()) { + current.name = name + } + } + val forecasts = when (val result = weatherRepository.getDaysForecastByCoords(coords)) { is ApiSuccess -> result.data diff --git a/data/src/main/kotlin/foundation/e/blissweather/models/WeatherCity.kt b/data/src/main/kotlin/foundation/e/blissweather/models/WeatherCity.kt index cc4d4c327b83ccf2b22c9630095006503757ac82..0e8d6ae76effcdf98f82d00782424e8590521eb8 100644 --- a/data/src/main/kotlin/foundation/e/blissweather/models/WeatherCity.kt +++ b/data/src/main/kotlin/foundation/e/blissweather/models/WeatherCity.kt @@ -9,7 +9,9 @@ package foundation.e.blissweather.models import android.os.Parcelable import androidx.annotation.Keep +import com.squareup.moshi.Json import kotlinx.parcelize.Parcelize +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Keep @@ -21,4 +23,7 @@ data class WeatherCity( val lon: Double, val country: String?, val state: String?, + @Json(name = "local_names") + @SerialName("local_names") + val localNames: Map = emptyMap() ) : Parcelable diff --git a/data/src/main/kotlin/foundation/e/blissweather/models/WeatherData.kt b/data/src/main/kotlin/foundation/e/blissweather/models/WeatherData.kt index cfb0e3f4c1a5d7dd864c6b02bce1b926aadc4e0b..2ce51f23e1986de57553b91985beb36f31c80571 100644 --- a/data/src/main/kotlin/foundation/e/blissweather/models/WeatherData.kt +++ b/data/src/main/kotlin/foundation/e/blissweather/models/WeatherData.kt @@ -17,7 +17,7 @@ import kotlinx.serialization.Serializable data class WeatherData( @Json(name = "cod") @SerialName("cod") val code: Int, val id: Int, - val name: String, + var name: String, val main: Main, val sys: Sys, val dt: Long,