From 7c14f35bf3a748c5e6278d377c8e3417c448e02c Mon Sep 17 00:00:00 2001 From: woheller69 Date: Thu, 2 Mar 2023 08:25:12 +0100 Subject: [PATCH] Update V1.3 Improve week icons by analyzing hourly forecasts between sunrise and sunset (experimental). --- README.md | 3 +- app/build.gradle | 4 +- .../ProcessOMweatherAPIRequest.java | 62 +++++++++++++++++++ .../res/layout/list_item_course_of_day.xml | 1 - .../res/layout/list_item_week_forecast.xml | 1 - app/src/main/res/values-da/strings.xml | 2 + app/src/main/res/values-de/strings.xml | 2 + app/src/main/res/values-es/strings.xml | 2 + app/src/main/res/values-fr/strings.xml | 2 + app/src/main/res/values-it/strings.xml | 2 + app/src/main/res/values-nl/strings.xml | 2 + app/src/main/res/values-pt/strings.xml | 2 + app/src/main/res/values-sv/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + app/src/main/res/xml/pref_general.xml | 6 ++ .../metadata/android/en-US/changelogs/13.txt | 1 + 16 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 fastlane/metadata/android/en-US/changelogs/13.txt diff --git a/README.md b/README.md index 1317a99..494ff9a 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,8 @@ This application is derived from Privacy Friendly Weather (https://github.com/SecUSo/privacy-friendly-weather) a privacy friendly weather app. -The original function has been modified to support the new open source open-meteo.com API. + +The original function has been modified to support the new open source API from Open-Meteo.com with free access for non-commercial use. In addition a rain radar functionality powered by RainViewer API (https://www.rainviewer.com/api.html) is available. If permission for GPS is given the widget will automatically update position on a regular base. diff --git a/app/build.gradle b/app/build.gradle index e1bec70..58b4064 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,8 @@ android { applicationId "org.woheller69.omweather" minSdkVersion 21 targetSdkVersion 31 - versionCode 12 - versionName "1.2" + versionCode 13 + versionName "1.3" buildConfigField "String", "BASE_URL", "\"https://api.open-meteo.com/v1/\"" buildConfigField "String", "GITHUB_URL","\"https://github.com/woheller69/omweather/\"" diff --git a/app/src/main/java/org/woheller69/weather/weather_api/open_meteo/ProcessOMweatherAPIRequest.java b/app/src/main/java/org/woheller69/weather/weather_api/open_meteo/ProcessOMweatherAPIRequest.java index 4dbe1d0..bfc7bc5 100644 --- a/app/src/main/java/org/woheller69/weather/weather_api/open_meteo/ProcessOMweatherAPIRequest.java +++ b/app/src/main/java/org/woheller69/weather/weather_api/open_meteo/ProcessOMweatherAPIRequest.java @@ -3,6 +3,7 @@ import android.appwidget.AppWidgetManager; import android.content.ComponentName; import android.content.Context; +import android.content.SharedPreferences; import android.os.Handler; import android.widget.RemoteViews; import android.widget.Toast; @@ -25,8 +26,13 @@ import org.woheller69.weather.widget.WeatherWidget5day; import static org.woheller69.weather.database.SQLiteHelper.getWidgetCityID; +import androidx.preference.PreferenceManager; +import org.woheller69.weather.weather_api.IApiToDatabaseConversion.WeatherCategories; + import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * This class processes the HTTP requests that are made to the Open-Meteo API requesting the @@ -125,6 +131,16 @@ public void processSuccessScenario(String response, int cityId) { return; } + SharedPreferences prefManager = PreferenceManager.getDefaultSharedPreferences(context); + if (prefManager.getBoolean("pref_weekIDs", false)){ + weekforecasts = reanalyzeWeekIDs(weekforecasts, hourlyforecasts); + dbHelper.deleteWeekForecastsByCityId(cityId); + for (WeekForecast weekForecast: weekforecasts){ + weekForecast.setCity_id(cityId); + dbHelper.addWeekForecast(weekForecast); + } + } + possiblyUpdateWidgets(cityId, weatherData, weekforecasts,hourlyforecasts); ViewUpdater.updateCurrentWeatherData(weatherData); @@ -136,6 +152,52 @@ public void processSuccessScenario(String response, int cityId) { } } + /** + * Reanalyze weekforecasts and improve weather codes which are not representative for the day + * @param weekforecasts + * @param hourlyforecasts + * @return + */ + private List reanalyzeWeekIDs(List weekforecasts, List hourlyforecasts) { + + Map mappingTable = new HashMap<>(); + mappingTable.put(WeatherCategories.OVERCAST_CLOUDS.getNumVal(),WeatherCategories.SCATTERED_CLOUDS.getNumVal()); + mappingTable.put(WeatherCategories.MIST.getNumVal(),WeatherCategories.SCATTERED_CLOUDS.getNumVal()); + mappingTable.put(WeatherCategories.DRIZZLE_RAIN.getNumVal(),WeatherCategories.LIGHT_SHOWER_RAIN.getNumVal()); + mappingTable.put(WeatherCategories.FREEZING_DRIZZLE_RAIN.getNumVal(),WeatherCategories.LIGHT_SHOWER_RAIN.getNumVal()); + mappingTable.put(WeatherCategories.LIGHT_RAIN.getNumVal(),WeatherCategories.LIGHT_SHOWER_RAIN.getNumVal()); + mappingTable.put(WeatherCategories.LIGHT_FREEZING_RAIN.getNumVal(),WeatherCategories.LIGHT_SHOWER_RAIN.getNumVal()); + mappingTable.put(WeatherCategories.MODERATE_RAIN.getNumVal(),WeatherCategories.SHOWER_RAIN.getNumVal()); + mappingTable.put(WeatherCategories.HEAVY_RAIN.getNumVal(),WeatherCategories.SHOWER_RAIN.getNumVal()); + mappingTable.put(WeatherCategories.FREEZING_RAIN.getNumVal(),WeatherCategories.SHOWER_RAIN.getNumVal()); + mappingTable.put(WeatherCategories.LIGHT_SNOW.getNumVal(),WeatherCategories.LIGHT_SHOWER_SNOW.getNumVal()); + mappingTable.put(WeatherCategories.MODERATE_SNOW.getNumVal(),WeatherCategories.SHOWER_SNOW.getNumVal()); + mappingTable.put(WeatherCategories.HEAVY_SNOW.getNumVal(),WeatherCategories.SHOWER_SNOW.getNumVal()); + + Map sunTable = new HashMap<>(); + sunTable.put(WeatherCategories.CLEAR_SKY.getNumVal(), 0); + sunTable.put(WeatherCategories.FEW_CLOUDS.getNumVal(), 0); + sunTable.put(WeatherCategories.SCATTERED_CLOUDS.getNumVal(), 0); + + for (WeekForecast weekForecast: weekforecasts){ + Integer ID = weekForecast.getWeatherID(); + if (mappingTable.containsKey(ID)){ + int totalCount = 0; + int sunCount = 0; + long sunrise = weekForecast.getTimeSunrise()*1000L; + long sunset = weekForecast.getTimeSunset()*1000L; + for (HourlyForecast hourlyForecast: hourlyforecasts){ + if(hourlyForecast.getForecastTime() >= sunrise && hourlyForecast.getForecastTime() <= sunset){ + totalCount++; + if(sunTable.containsKey(hourlyForecast.getWeatherID())) sunCount++; + } + } + if (totalCount>0 && (float)sunCount/totalCount>0.2f) weekForecast.setWeatherID(mappingTable.get(ID)); + } + } + return weekforecasts; + } + /** * Shows an error that the data could not be retrieved. * diff --git a/app/src/main/res/layout/list_item_course_of_day.xml b/app/src/main/res/layout/list_item_course_of_day.xml index 39c4142..604dee9 100644 --- a/app/src/main/res/layout/list_item_course_of_day.xml +++ b/app/src/main/res/layout/list_item_course_of_day.xml @@ -1,6 +1,5 @@ Open-Meteo Regn radar Allow access to RainViewer.com which is not an open-source network. + Forbedre ugeikoner ved at analysere timeprognoser mellem solopgang og solnedgang (eksperimentel). + Uge ikoner diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index b3aa913..73cbe0f 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -113,5 +113,7 @@ Open-Meteo Regenradar Erlauben Sie den Zugriff auf RainViewer.com, das kein Open-Source-Netzwerk ist. + Verbessern Sie Wochensymbole, indem Sie stündliche Vorhersagen zwischen Sonnenaufgang und Sonnenuntergang analysieren (experimentell). + Wochensymbole diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index f8f9af8..e267021 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -112,5 +112,7 @@ Open-Meteo Radar de lluvia Permita el acceso a RainViewer.com, que no es una red de código abierto. + Mejore los íconos de la semana analizando los pronósticos por hora entre el amanecer y el atardecer (experimental). + Iconos de semana diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 0f62bde..d5160d3 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -113,5 +113,7 @@ Open-Meteo Radar de pluie Autorisez l\'accès à RainViewer.com qui n\'est pas un réseau open source. + Améliorez les icônes de la semaine en analysant les prévisions horaires entre le lever et le coucher du soleil (expérimental). + Icônes de la semaine \ No newline at end of file diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 38d5a33..9726812 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -110,4 +110,6 @@ Open-Meteo Radar Pioggia Consenti l\'accesso a RainViewer.com che non è una rete open source. + Migliora le icone delle settimane analizzando le previsioni orarie tra l\'alba e il tramonto (sperimentale). + Icone della settimana diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index ff7f763..4a35ecb 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -112,6 +112,8 @@ Open-Meteo Regenradar Geef toegang tot RainViewer.com, wat geen open-source netwerk is. + Verbeter weekpictogrammen door uurlijkse voorspellingen tussen zonsopgang en zonsondergang te analyseren (experimenteel). + Week pictogrammen diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 91452bd..b051656 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -110,4 +110,6 @@ Open-Meteo Radar de Chuvas Permita o acesso ao RainViewer.com, que não é uma rede de código aberto. + Melhore os ícones da semana analisando as previsões horárias entre o nascer e o pôr do sol (experimental). + Ícones da semana \ No newline at end of file diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 403fb2c..d56e0d4 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -112,6 +112,8 @@ Open-Meteo Regnradar Tillåt åtkomst till RainViewer.com som inte är ett nätverk med öppen källkod. + Förbättra veckoikoner genom att analysera timprognoser mellan soluppgång och solnedgång (experimentell). + Vecka ikoner diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9810994..7612051 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -117,4 +117,6 @@ Rain Radar Rain radar Allow access to RainViewer.com which is not an open-source network. + Improve week icons by analyzing hourly forecasts between sunrise and sunset (experimental). + Week Icons diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index 28a808e..84d6112 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -48,6 +48,12 @@ android:defaultValue="true" /> + diff --git a/fastlane/metadata/android/en-US/changelogs/13.txt b/fastlane/metadata/android/en-US/changelogs/13.txt new file mode 100644 index 0000000..8b27dd3 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/13.txt @@ -0,0 +1 @@ +New option: Improve week icons by analyzing hourly forecasts between sunrise and sunset (experimental). \ No newline at end of file