diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/ForecastBuilder.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/ForecastBuilder.java index 7b927e29f9b7d5538fc993277b94d27fa04a4255..a5108c649673f9db88d41adc474a2682036b8bdd 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/ForecastBuilder.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/ForecastBuilder.java @@ -73,7 +73,15 @@ public class ForecastBuilder { // City TextView textCity = weatherPanel.findViewById(R.id.weather_city); - textCity.setText(Preferences.getCachedCity(context, w.getCity())); + String city; + + if (Preferences.useCustomWeatherLocation(context)) { + city = w.getCity(); + } else { + city = Preferences.getCachedCity(context, w.getCity()); + } + + textCity.setText(city); // Weather Condition TextView weatherCondition = weatherPanel.findViewById(R.id.weather_condition); diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java index 9a10a3a2d80197c71c11476cd88814693000a82e..8801e2d81aa3841bd68e0e6d5afa04088a4cf758 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java @@ -176,6 +176,8 @@ public class WeatherUpdater { if (!Preferences.useCustomWeatherLocation(mWeakContext.get())) { reverseGeocodeLocation(getMostRecentLocation()); + } else { + Log.w(TAG, "Do not reverse geocode location. User is using a custom location."); } } @@ -233,32 +235,36 @@ public class WeatherUpdater { } JsonObject locales; + JsonObject root; + String defaultCityName; try { final String json = body.string(); final JsonArray array = new JsonParser().parse(json).getAsJsonArray(); - locales = array.get(0).getAsJsonObject().getAsJsonObject("local_names"); + + root = array.get(0).getAsJsonObject(); + locales = root.getAsJsonObject("local_names"); + defaultCityName = root.get("name").getAsString(); } catch (IOException | IllegalStateException | JsonSyntaxException exception) { Log.e(TAG, "Exception caught", exception); return; } + if (defaultCityName == null) { + Log.e(TAG, "Could not get default city name"); + return; + } + if (locales == null) { Log.e(TAG, "Could not get locales"); + notifyUi(defaultCityName); return; } String countryCode = Locale.getDefault().getCountry().toLowerCase(Locale.ROOT); - if (!locales.has(countryCode)) { - final JsonElement jsonElement = locales.get("en"); - if (jsonElement == null) { - return; - } - - countryCode = jsonElement.getAsString(); - } - final JsonElement jsonElement = locales.get(countryCode); if (jsonElement == null) { + Log.e(TAG, "Could not get city name in country code: " + countryCode); + notifyUi(defaultCityName); return; }