Skip to content

Commit

Permalink
Update for OneCallAPI 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
woheller69 committed Aug 21, 2022
1 parent d1fe149 commit e7683be
Show file tree
Hide file tree
Showing 20 changed files with 97 additions and 80 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ If permission for GPS is given the widget will automatically update position on

As One Call API only allows 1000 calls per day an own OpenWeatherMap API key is mandatory.

For subscriptions later than Aug 15, 2022 you need a free subscription and OneCallAPI 3.0 with a limit of 1000 (free) calls per day.

Please register for free account at: https://home.openweathermap.org/users/sign_up

[<img src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png" height="75">](https://f-droid.org/de/packages/org.woheller69.weather/)
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ android {

buildConfigField "String", "DEFAULT_API_KEY", "\"00000000000000000000000000000000\""
buildConfigField "String", "BASE_URL", "\"https://api.openweathermap.org/data/2.5/\""
buildConfigField "String", "BASE_URL_3", "\"https://api.openweathermap.org/data/3.0/\""
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;

import org.woheller69.weather.BuildConfig;
Expand Down Expand Up @@ -135,7 +134,7 @@ public String getDistanceUnit(Context applicationContext) {

public String getOWMApiKey(Context context){
String prefValue = preferences.getString("API_key_value", BuildConfig.DEFAULT_API_KEY);
if (prefValue.equals(context.getString(R.string.settings__API_key_default))) {
if (prefValue.equals(context.getString(R.string.settings_API_key_default))) {
new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(context, context.getResources().getString(R.string.settings_title_API_key), Toast.LENGTH_LONG).show());
return BuildConfig.DEFAULT_API_KEY;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ public void updateForecastData(List<Forecast> forecasts) {

// function for week forecast list
public void updateWeekForecastData(List<WeekForecast> forecasts) {
if (forecasts.isEmpty()) {
forecastData = new float[][]{new float[]{0,0,0,0,0,0,0,0,0,0,0}}; //initialize array with one empty row which will not be displayed
return;
}
if (forecasts.isEmpty()) return;

int cityId = forecasts.get(0).getCity_id();

Expand All @@ -111,9 +108,9 @@ public void updateWeekForecastData(List<WeekForecast> forecasts) {

//temp max 0, temp min 1, humidity 2, pressure 3, precipitation 4, wind 5, wind direction 6, uv_index 7, forecast time 8, weather ID 9, number of FCs for day 10

forecastData = new float[9][11]; //must be [9], otherwise last day not displayed
forecastData = new float[forecasts.size()][11];

for (int i=0;i<=7;i++){
for (int i=0;i<forecasts.size();i++){
forecastData[i][0]=forecasts.get(i).getMaxTemperature();
forecastData[i][1]=forecasts.get(i).getMinTemperature();
forecastData[i][2]=forecasts.get(i).getHumidity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class WeekWeatherAdapter extends RecyclerView.Adapter<WeekWeatherAdapter.
this.context = context;
this.cityID = cityID;
this.forecastData = forecastData;
if (forecastData.length!=0 && forecastData[0]!=null) {
if (forecastData!=null && forecastData.length!=0 && forecastData[0]!=null) {
this.courseOfDayHeaderDate = new Date((long) forecastData[0][8]); //init with date of first weekday
} else this.courseOfDayHeaderDate = new Date(); //fallback if no data available
}
Expand Down Expand Up @@ -129,7 +129,10 @@ public void onBindViewHolder(WeekForecastViewHolder holder, int position) {

@Override
public int getItemCount() {
return forecastData.length - 1;
if (forecastData!=null)
return forecastData.length;
else
return 0;
}

class WeekForecastViewHolder extends RecyclerView.ViewHolder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.content.Context;
import androidx.preference.PreferenceManager;

import android.content.SharedPreferences;
import android.text.TextUtils;

import org.woheller69.weather.BuildConfig;
Expand Down Expand Up @@ -87,9 +89,10 @@ protected String getUrlForQueryingForecast(Context context, float lat, float lon
protected String getUrlForQueryingOneCallAPI(Context context, float lat, float lon) {
AppPreferencesManager prefManager =
new AppPreferencesManager(PreferenceManager.getDefaultSharedPreferences(context));
SharedPreferences sharedPreferences=PreferenceManager.getDefaultSharedPreferences(context);
return String.format(
"%sonecall?lat=%s&lon=%s&units=metric&exclude=alerts&appid=%s",
BuildConfig.BASE_URL,
sharedPreferences.getBoolean("oneCall3",false) ? BuildConfig.BASE_URL_3 : BuildConfig.BASE_URL,
lat,
lon,
prefManager.getOWMApiKey(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ public void onEnabled(Context context) {

int widgetCityID=getWidgetCityID(context);

List<Forecast> forecasts=dbHelper.getForecastsByCityId(widgetCityID);
List<WeekForecast> weekforecasts=dbHelper.getWeekForecastsByCityId(widgetCityID);

int[] widgetIDs = AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, WeatherWidget5day.class));
Expand Down
16 changes: 13 additions & 3 deletions app/src/main/res/layout/tutorial_slide4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
android:layout_width="@dimen/img_width_height"
android:layout_height="@dimen/img_width_height"
android:background="@drawable/splash_icon" />
<Space
<androidx.legacy.widget.Space
android:layout_width="1dp"
android:layout_height="20dp"/>

Expand All @@ -35,8 +35,18 @@
android:textAlignment="center"
android:textColor="@android:color/white"
android:textSize="@dimen/slide_desc" />

<Space
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:paddingLeft="@dimen/desc_padding"
android:paddingRight="@dimen/desc_padding"
android:text="@string/settings_register_summary"
android:textAlignment="center"
android:textColor="@android:color/white"
android:textSize="@dimen/slide_desc" />
<androidx.legacy.widget.Space
android:layout_width="1dp"
android:layout_height="60dp"/>

Expand Down
12 changes: 3 additions & 9 deletions app/src/main/res/values-da/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<string name="activity_manage">Administrer lokationer</string>
<string name="activity_radius_search">Radiussøgning</string>
<string name="action_refresh">Opdater</string>
<string name="action_rainviewer" translatable="false">Rain Viewer</string>
<string name="navigation_drawer_open">Åbn navigationsskuffen</string>
<string name="navigation_drawer_close">Luk navigationsskuffen</string>
<string name="next">Næste</string>
Expand All @@ -18,7 +17,6 @@
<string name="slide1_text">RadarWeather er en app til at tjekke det aktuelle vejr og vejrudsigter for dine steder.</string>
<string name="slide2_heading">Hvordan</string>
<string name="slide2_text">Du kan vælge dine egne steder og få detaljerede oplysninger om det aktuelle vejr. En regnradar er også tilgængelig.</string>
<string name="slide3_heading" translatable="false">Github</string>
<string name="slide3_text">Kildekoden til denne app er tilgængelig på GitHub. For yderligere forklaringer, se om siden.</string>
<string name="card_details_heading">Nu</string>
<string name="card_details_humidity">Fugtighed:</string>
Expand All @@ -37,11 +35,9 @@
<string name="about_privacy_heading">Privatlivsoplysninger</string>
<string name="about_permission_internet_description">Tilslutning til netværket: Denne tilladelse er nødvendig, fordi vejrdata hentes ved at sende anmodninger til servere på internettet. Uden denne tilladelse kan der ikke modtages vejrdata. Valgfrit: autorisation til GPS.</string>
<string name="about">Om</string>
<string name="version_number" translatable="false">Version</string>
<string name="about_license">Licens</string>
<string name="about_license_text">Denne applikation er afledt af Privacy Friendly Weather, udviklet af forskningsgruppen SECUSO. Kildekode licenseret under GPLv3. Appen bruger ikoner fra Google Material Design Icons licenseret under Apache License Version 2.0, Leaflet-biblioteket, som er licenseret under 2-klausul BSD-licens, Leaflet.TileLayer.ColorFilter-pluginet, som er licenseret under MIT-licens, RainViewer API, som er gratis, Android SQLiteAssetHelper-biblioteket (com.readystatesoftware.sqliteasset) som er licenseret under Apache-licensversion 2.0, AutoSuggestTextViewAPICall som er licenseret under Apache-licensversion 2.0 og WilliamChart-biblioteket (com.db.chart), som er licenseret under Apache Licens version 2.0.</string>
<string name="about_more_info">Mere information kan findes på:</string>
<string name="about_github" translatable="false"><a href="https://github.com/woheller69/weather">Github-Repo</a></string>
<string name="activity_settings_title">Indstillinger</string>
<string name="settings_title_units">Enheder</string>
<string name="settings_summary_temperature">Indstil enheden til at bruge til at vise temperaturer</string>
Expand All @@ -55,7 +51,6 @@
<string name="settings_title_API">API nøgle</string>
<string name="settings_description_API">RadarWeather modtager data fra den gratis tjeneste på openweathermap.org. Denne service er begrænset til 1000 opkald pr. dag. Indtast venligst din egen API-nøgle</string>
<string name="settings_title_API_key">Indtast API-nøgle</string>
<string name="settings__API_key_default" translatable="false"/>
<string name="abbreviation_monday">Ma.</string>
<string name="abbreviation_tuesday">Ti.</string>
<string name="abbreviation_wednesday">On.</string>
Expand Down Expand Up @@ -113,7 +108,7 @@
<string name="settings_forecast_option_1">5 dage /3 timer</string>
<string name="settings_forecast_option_2">2 dage /1 t 3 dag /3 timer</string>
<string name="settings_forecastChoice">Vejrudsigt</string>
<string name="registerOWM">Vejrinformation hentes fra OpenWeatherMap. Indtast venligst din API-nøgle i indstillinger. Hvis du endnu ikke har en API-nøgle, skal du trykke på knappen nedenfor for gratis registrering:</string>
<string name="registerOWM">Vejrinformation hentes fra OpenWeatherMap. Indtast venligst din API-nøgle i indstillinger. Hvis du endnu ikke har en API-nøgle, skal du trykke på knappen nedenfor for gratis registrering.</string>
<string name="registerOWMbutton">Tilmeld dig gratis</string>
<string name="monday">Mandag</string>
<string name="tuesday">Tirsdag</string>
Expand All @@ -140,10 +135,8 @@
<string name="edit_location_hint_latitude">Breddegrad</string>
<string name="edit_location_hint_longitude">Længde</string>
<string name="edit_location_hint_country_code">Landekode</string>
<string name="edit_location_hint_ID" translatable="false">ID</string>
<string name="edit_location_range_error">Værdi uden for rækkevidde</string>
<string name="settings_search_option_1">Intern byliste</string>
<string name="settings_search_option_2" translatable="false">Photon API</string>
<string name="settings_search_summary">Søg efter steder via Photon API eller intern byliste</string>
<string name="settings_search">Søg</string>
<string name="dialog_add_tv">For bedre søgeresultater skal du aktivere onlinesøgning via photon API i indstillinger</string>
Expand All @@ -162,7 +155,8 @@
<string name="dialog_StarOnGitHub">Kan du lide denne app? Stjerne det venligst på GitHub.</string>
<string name="settings_show_pressure">Vis lufttryk</string>
<string name="settings_GPS_manual">Kun manuel opdatering</string>
<string name="settings_register_summary">Du har brug for et gratis abonnement og OneCallAPI 3.0 med en grænse på 1000 (gratis) opkald pr. dag.</string>

<!-- Generated by Automatic String Resource Translation -->
<!-- Generated by Automatic String Resource Translation -->
<!-- https://asrt.gluege.boerde.de -->
</resources>
10 changes: 9 additions & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<string name="long_press_text">Halten und ziehen Sie, um die Städte zu sortieren.</string>
<string name="swipe_to_delete">Wischen Sie zum Löschen</string>
<string name="RainViewer">Regenradar</string>
<string name="registerOWM">Die Wetterinformationen stammen von OpenWeatherMap. Bitte geben Sie Ihren API Key in den Einstellungen ein. Wenn Sie noch keinen API Key haben, drücken Sie den Button unterhalb, um sich kostenlos zu registrieren:</string>
<string name="registerOWM">Die Wetterinformationen stammen von OpenWeatherMap. Bitte geben Sie Ihren API Key in den Einstellungen ein. Wenn Sie noch keinen API Key haben, drücken Sie den Button unterhalb, um sich kostenlos zu registrieren.</string>
<string name="registerOWMbutton">Kostenfrei registrieren</string>

<string name="monday">Montag</string>
Expand Down Expand Up @@ -149,4 +149,12 @@
<string name="dialog_StarOnGitHub">Mögen Sie diese App? Bitte vergeben Sie einen Stern auf GitHub.</string>
<string name="settings_show_pressure">Luftdruck anzeigen</string>
<string name="settings_GPS_manual">Nur manuell aktualisieren</string>
<string name="settings_interval_quarter">15 min</string>
<string name="settings_interval_half">30 min</string>
<string name="settings_interval_one">1 h</string>
<string name="settings_interval_two">2 h</string>
<string name="settings_interval_six">6 h</string>
<string name="settings_interval_twelve">12 h</string>
<string name="settings_interval_twentyfour">24 h</string>
<string name="settings_register_summary">Sie benötigen ein kostenloses Abonnement und OneCallAPI 3.0 mit einem Limit von 1000 (kostenlosen) Anrufen pro Tag.</string>
</resources>
10 changes: 9 additions & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<string name="settings_forecast_option_1">5 días /3h</string>
<string name="settings_forecast_option_2">2 días /1h + 3 días /3h</string>
<string name="settings_forecastChoice">Previsión del tiempo</string>
<string name="registerOWM">La información meteorológica se obtiene de OpenWeatherMap. Ingrese su clave API en la configuración. Si aún no tiene una clave API, presione el botón a continuación para registrarse gratis:</string>
<string name="registerOWM">La información meteorológica se obtiene de OpenWeatherMap. Ingrese su clave API en la configuración. Si aún no tiene una clave API, presione el botón a continuación para registrarse gratis.</string>
<string name="registerOWMbutton">Registrate gratis</string>
<string name="monday">lunes</string>
<string name="tuesday">martes</string>
Expand Down Expand Up @@ -148,4 +148,12 @@
<string name="dialog_StarOnGitHub">¿Te gusta esta app? Asigne una estrella en GitHub.</string>
<string name="settings_show_pressure">Mostrar presión de aire</string>
<string name="settings_GPS_manual">Solo actualización manual</string>
<string name="settings_interval_quarter">15 min</string>
<string name="settings_interval_half">30 min</string>
<string name="settings_interval_one">1 h</string>
<string name="settings_interval_two">2 h</string>
<string name="settings_interval_six">6 h</string>
<string name="settings_interval_twelve">12 h</string>
<string name="settings_interval_twentyfour">24 h</string>
<string name="settings_register_summary">Necesita una suscripción gratuita y OneCallAPI 3.0 con un límite de 1000 llamadas (gratuitas) por día.</string>
</resources>
10 changes: 9 additions & 1 deletion app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<string name="long_press_text">Maintenez et faites glisser pour trier les villes.</string>
<string name="swipe_to_delete">Balayez pour effacer</string>
<string name="RainViewer">Radar de pluie</string>
<string name="registerOWM">Les informations météorologiques proviennent du OpenWeatherMap. Veuillez saisir votre clé API dans les paramètres. Si vous n\'avez pas encore de clé API, appuyez sur le bouton ci-dessous pour vous inscrire gratuitement:</string>
<string name="registerOWM">Les informations météorologiques proviennent du OpenWeatherMap. Veuillez saisir votre clé API dans les paramètres. Si vous n\'avez pas encore de clé API, appuyez sur le bouton ci-dessous pour vous inscrire gratuitement.</string>
<string name="registerOWMbutton">Inscription gratuite</string>

<string name="monday">Lundi</string>
Expand Down Expand Up @@ -152,4 +152,12 @@
<string name="dialog_StarOnGitHub">Aimez-vous cette application? Veuillez attribuer une étoile sur GitHub.</string>
<string name="settings_show_pressure">Afficher la pression atmosphérique</string>
<string name="settings_GPS_manual">Mise à jour manuelle uniquement</string>
<string name="settings_interval_quarter">15 min</string>
<string name="settings_interval_half">30 min</string>
<string name="settings_interval_one">1 h</string>
<string name="settings_interval_two">2 h</string>
<string name="settings_interval_six">6 h</string>
<string name="settings_interval_twelve">12 h</string>
<string name="settings_interval_twentyfour">24 h</string>
<string name="settings_register_summary">Vous avez besoin d\'un abonnement gratuit et de OneCallAPI 3.0 avec une limite de 1000 appels (gratuits) par jour.</string>
</resources>
Loading

0 comments on commit e7683be

Please sign in to comment.