Skip to content

Commit

Permalink
Update V1.3
Browse files Browse the repository at this point in the history
Improve week icons by analyzing hourly forecasts between sunrise and sunset (experimental).
  • Loading branch information
woheller69 committed Mar 2, 2023
1 parent 1a78062 commit 7c14f35
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/05.png" width="150"/> <img src="fastlane/metadata/android/en-US/images/phoneScreenshots/06.png" width="150"/>

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.
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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/\""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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<WeekForecast> reanalyzeWeekIDs(List<WeekForecast> weekforecasts, List<HourlyForecast> hourlyforecasts) {

Map<Integer,Integer> 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<Integer,Integer> 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.
*
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/list_item_course_of_day.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_city_weather_details_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/list_item_week_forecast.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_city_weather_details_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-da/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
<string name="slide3_heading">Open-Meteo</string>
<string name="RainViewer">Regn radar</string>
<string name="nonFreeNet">Allow access to RainViewer.com which is not an open-source network.</string>
<string name="summary_reanalyze">Forbedre ugeikoner ved at analysere timeprognoser mellem solopgang og solnedgang (eksperimentel).</string>
<string name="settings_reanalyze">Uge ikoner</string>
<!-- Generated by Automatic String Resource Translation -->
<!-- https://asrt.gluege.boerde.de -->
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,7 @@
<string name="slide3_heading">Open-Meteo</string>
<string name="RainViewer">Regenradar</string>
<string name="nonFreeNet">Erlauben Sie den Zugriff auf RainViewer.com, das kein Open-Source-Netzwerk ist.</string>
<string name="summary_reanalyze">Verbessern Sie Wochensymbole, indem Sie stündliche Vorhersagen zwischen Sonnenaufgang und Sonnenuntergang analysieren (experimentell).</string>
<string name="settings_reanalyze">Wochensymbole</string>

</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,7 @@
<string name="slide3_heading">Open-Meteo</string>
<string name="RainViewer">Radar de lluvia</string>
<string name="nonFreeNet">Permita el acceso a RainViewer.com, que no es una red de código abierto.</string>
<string name="summary_reanalyze">Mejore los íconos de la semana analizando los pronósticos por hora entre el amanecer y el atardecer (experimental).</string>
<string name="settings_reanalyze">Iconos de semana</string>

</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,7 @@
<string name="slide3_heading">Open-Meteo</string>
<string name="RainViewer">Radar de pluie</string>
<string name="nonFreeNet">Autorisez l\'accès à RainViewer.com qui n\'est pas un réseau open source.</string>
<string name="summary_reanalyze">Améliorez les icônes de la semaine en analysant les prévisions horaires entre le lever et le coucher du soleil (expérimental).</string>
<string name="settings_reanalyze">Icônes de la semaine</string>

</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,6 @@
<string name="slide3_heading">Open-Meteo</string>
<string name="RainViewer">Radar Pioggia</string>
<string name="nonFreeNet">Consenti l\'accesso a RainViewer.com che non è una rete open source.</string>
<string name="summary_reanalyze">Migliora le icone delle settimane analizzando le previsioni orarie tra l\'alba e il tramonto (sperimentale).</string>
<string name="settings_reanalyze">Icone della settimana</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
<string name="slide3_heading">Open-Meteo</string>
<string name="RainViewer">Regenradar</string>
<string name="nonFreeNet">Geef toegang tot RainViewer.com, wat geen open-source netwerk is.</string>
<string name="summary_reanalyze">Verbeter weekpictogrammen door uurlijkse voorspellingen tussen zonsopgang en zonsondergang te analyseren (experimenteel).</string>
<string name="settings_reanalyze">Week pictogrammen</string>

<!-- Generated by Automatic String Resource Translation -->
<!-- https://asrt.gluege.boerde.de -->
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,6 @@
<string name="slide3_heading">Open-Meteo</string>
<string name="RainViewer">Radar de Chuvas</string>
<string name="nonFreeNet">Permita o acesso ao RainViewer.com, que não é uma rede de código aberto.</string>
<string name="summary_reanalyze">Melhore os ícones da semana analisando as previsões horárias entre o nascer e o pôr do sol (experimental).</string>
<string name="settings_reanalyze">Ícones da semana</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-sv/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
<string name="slide3_heading">Open-Meteo</string>
<string name="RainViewer">Regnradar</string>
<string name="nonFreeNet">Tillåt åtkomst till RainViewer.com som inte är ett nätverk med öppen källkod.</string>
<string name="summary_reanalyze">Förbättra veckoikoner genom att analysera timprognoser mellan soluppgång och solnedgång (experimentell).</string>
<string name="settings_reanalyze">Vecka ikoner</string>
<!-- Generated by Automatic String Resource Translation -->
<!-- https://asrt.gluege.boerde.de -->
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,6 @@
<string name="RainViewer">Rain Radar</string>
<string name="action_rainviewer" translatable="false">Rain radar</string>
<string name="nonFreeNet">Allow access to RainViewer.com which is not an open-source network.</string>
<string name="summary_reanalyze">Improve week icons by analyzing hourly forecasts between sunrise and sunset (experimental).</string>
<string name="settings_reanalyze">Week Icons</string>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/xml/pref_general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
android:defaultValue="true"
/>

<SwitchPreference
android:key="pref_weekIDs"
android:title="@string/settings_reanalyze"
android:summary="@string/summary_reanalyze"
android:defaultValue="false"
/>
</PreferenceCategory>

<PreferenceCategory android:title="@string/settings_title_units">
Expand Down
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/13.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
New option: Improve week icons by analyzing hourly forecasts between sunrise and sunset (experimental).

0 comments on commit 7c14f35

Please sign in to comment.