From 08351c6b9cfa0b5eeebfc9dac6aa8969e600b6c5 Mon Sep 17 00:00:00 2001 From: Nishith Khanna Date: Tue, 19 Mar 2024 11:57:44 +0530 Subject: [PATCH 1/3] Send language code via OpenWeatherApi for translated weather description --- .../api/OpenWeatherRepositoryImpl.kt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/data/src/main/kotlin/foundation/e/blissweather/api/OpenWeatherRepositoryImpl.kt b/data/src/main/kotlin/foundation/e/blissweather/api/OpenWeatherRepositoryImpl.kt index 39540f5..be949fb 100644 --- a/data/src/main/kotlin/foundation/e/blissweather/api/OpenWeatherRepositoryImpl.kt +++ b/data/src/main/kotlin/foundation/e/blissweather/api/OpenWeatherRepositoryImpl.kt @@ -15,6 +15,7 @@ import foundation.e.blissweather.models.Units import foundation.e.blissweather.models.WeatherCity import foundation.e.blissweather.models.WeatherData import foundation.e.blissweather.models.WeatherDayResponse +import java.util.Locale import javax.inject.Inject class OpenWeatherRepositoryImpl @@ -38,33 +39,38 @@ constructor( } } + private val lang: String + get() = Locale.getDefault().language + override suspend fun getWeatherByCoords( coord: Coordinate, ): ApiResult = handleApi { - baseApi.getWeatherByCoords(coord.lat, coord.lon, apiKey, unit) + baseApi.getWeatherByCoords(coord.lat, coord.lon, apiKey, unit, lang) } override suspend fun getDaysForecastByCoords( coord: Coordinate, ): ApiResult = handleApi { - baseApi.getForecastByCoords(coord.lat, coord.lon, apiKey, unit) + baseApi.getForecastByCoords(coord.lat, coord.lon, apiKey, unit, lang) } override suspend fun getWeatherByLocationName( name: String, - ): ApiResult = handleApi { baseApi.getWeatherByLocationName(name, apiKey, unit) } + ): ApiResult = handleApi { + baseApi.getWeatherByLocationName(name, apiKey, unit, lang) + } override suspend fun getLocationCoordsByName( name: String, limit: Int, ): ApiResult> = handleApi { - geoApi.getLocationCoordsByName(name, limit, apiKey, unit) + geoApi.getLocationCoordsByName(name, limit, apiKey, unit, lang) } override suspend fun getLocationNameByCoords( coord: Coordinate, limit: Int, ): ApiResult> = handleApi { - geoApi.getLocationNameByCoords(coord.lat, coord.lon, limit, apiKey, unit) + geoApi.getLocationNameByCoords(coord.lat, coord.lon, limit, apiKey, unit, lang) } } -- GitLab From f7748f4870731c0f68050dc599112138584caf1d Mon Sep 17 00:00:00 2001 From: Nishith Khanna Date: Tue, 19 Mar 2024 11:58:29 +0530 Subject: [PATCH 2/3] Get localised day of the week for weather forecast view --- .../foundation/e/blissweather/widget/WidgetViewUtils.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/android/src/main/kotlin/foundation/e/blissweather/widget/WidgetViewUtils.kt b/android/src/main/kotlin/foundation/e/blissweather/widget/WidgetViewUtils.kt index fc0e41c..369394d 100644 --- a/android/src/main/kotlin/foundation/e/blissweather/widget/WidgetViewUtils.kt +++ b/android/src/main/kotlin/foundation/e/blissweather/widget/WidgetViewUtils.kt @@ -111,9 +111,7 @@ fun RemoteViews.updateWeatherView( val dayName = calendar .apply { set(Calendar.DAY_OF_WEEK, nextDay) } - .time - .toString() - .substring(0, 3) + .getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.getDefault()) val dayRes = context.resources.getIdentifier( -- GitLab From 6f811e9578163244a531109f2cd97e6b885c1785 Mon Sep 17 00:00:00 2001 From: Nishith Khanna Date: Tue, 19 Mar 2024 11:59:55 +0530 Subject: [PATCH 3/3] Update widget whenever locale is changed --- android/src/main/AndroidManifest.xml | 1 + .../e/blissweather/widget/WeatherAppWidgetProvider.kt | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index b78aff7..259c191 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -37,6 +37,7 @@ android:label="@string/weather"> + { + ACTION_WEATHER_REFRESH, + Intent.ACTION_LOCALE_CHANGED -> { onDisabled(context) onEnabled(context) } -- GitLab