diff --git a/app/src/main/java/de/apps4ics/mountainnavigation/DownloadActivity.java b/app/src/main/java/de/apps4ics/mountainnavigation/DownloadActivity.java index 4f2738e..344a87e 100644 --- a/app/src/main/java/de/apps4ics/mountainnavigation/DownloadActivity.java +++ b/app/src/main/java/de/apps4ics/mountainnavigation/DownloadActivity.java @@ -62,6 +62,9 @@ boolean customLocationFound; Location customLocation; + private final static int DAILY_FORECAST_MAX = 16; //http://openweathermap.org/api + private final static int HOUR_FORECAST_MAX = 5; //http://openweathermap.org/api + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -172,12 +175,12 @@ Log.d(MainActivity.TAG, "currentSelected: " + currentSelected); Log.d(MainActivity.TAG, "nrOfForecastDays: " + nrOfForecastDays); - if(currentSelected.equals(getString(R.string.download_forecast_key))) { + if(currentSelected.equals(getString(R.string.download_forecast_daily_key))) { weatherHandler.getForecast(l, nrOfForecastDays, DownloadActivity.this); + } else if(currentSelected.equals(getString(R.string.download_forecast_hour_key))) { + weatherHandler.getForecastHour(l, nrOfForecastDays, DownloadActivity.this); } else if(currentSelected.equals(getString(R.string.download_current_key))) { weatherHandler.getCurrentWeather(l, DownloadActivity.this); - } else if(currentSelected.equals(getString(R.string.download_day_key))) { - //TODO CORE? } } }); @@ -191,8 +194,14 @@ @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { String key = currentSelected = getResources().getStringArray(R.array.download_categories_keys)[position]; - if(key.equals(getString(R.string.download_forecast_key))) { + if(key.equals(getString(R.string.download_forecast_daily_key))) { dayLayout.setVisibility(View.VISIBLE); + dayPicker.setMax(DAILY_FORECAST_MAX - 1); + if(dayPicker.getProgress() > DAILY_FORECAST_MAX - 1) dayPicker.setProgress(DAILY_FORECAST_MAX - 1); + } else if(key.equals(getString(R.string.download_forecast_hour_key))) { + dayLayout.setVisibility(View.VISIBLE); + dayPicker.setMax(HOUR_FORECAST_MAX - 1); + if(dayPicker.getProgress() > HOUR_FORECAST_MAX - 1) dayPicker.setProgress(HOUR_FORECAST_MAX - 1); } else { dayLayout.setVisibility(View.INVISIBLE); } diff --git a/app/src/main/java/de/apps4ics/mountainnavigation/MyWeather.java b/app/src/main/java/de/apps4ics/mountainnavigation/MyWeather.java index 3b9cac4..1b75c9e 100644 --- a/app/src/main/java/de/apps4ics/mountainnavigation/MyWeather.java +++ b/app/src/main/java/de/apps4ics/mountainnavigation/MyWeather.java @@ -27,6 +27,7 @@ import com.survivingwithandroid.weather.lib.WeatherCode; import com.survivingwithandroid.weather.lib.model.DayForecast; +import com.survivingwithandroid.weather.lib.model.HourForecast; import com.survivingwithandroid.weather.lib.model.Weather; import java.util.Arrays; @@ -85,6 +86,10 @@ public MyWeather() {} + public MyWeather(HourForecast hourForecast) { + this(hourForecast.weather, hourForecast.timestamp); + } + public MyWeather(DayForecast dayForecast) { this(dayForecast.weather, dayForecast.timestamp); } diff --git a/app/src/main/java/de/apps4ics/mountainnavigation/handlers/WeatherHandler.java b/app/src/main/java/de/apps4ics/mountainnavigation/handlers/WeatherHandler.java index d549f21..b547d35 100644 --- a/app/src/main/java/de/apps4ics/mountainnavigation/handlers/WeatherHandler.java +++ b/app/src/main/java/de/apps4ics/mountainnavigation/handlers/WeatherHandler.java @@ -37,8 +37,10 @@ import com.survivingwithandroid.weather.lib.model.DayForecast; import com.survivingwithandroid.weather.lib.model.HistoricalHourWeather; import com.survivingwithandroid.weather.lib.model.HistoricalWeather; +import com.survivingwithandroid.weather.lib.model.HourForecast; import com.survivingwithandroid.weather.lib.model.Weather; import com.survivingwithandroid.weather.lib.model.WeatherForecast; +import com.survivingwithandroid.weather.lib.model.WeatherHourForecast; import com.survivingwithandroid.weather.lib.provider.openweathermap.OpenweathermapProviderType; import com.survivingwithandroid.weather.lib.request.WeatherRequest; @@ -65,6 +67,7 @@ private WeatherConfig weatherConfig; private HistoricalWeather histWeather; private DayForecast[] forecasts; + private HourForecast[] hourForecasts; private Weather[] weathers; public final static int MIN_HOT_TEMP_DEFAULT = 30; public final static int MAX_COLD_TEMP_DEFAULT = 10; @@ -155,6 +158,95 @@ getFromDatabase(lat, lon, offset, callback); } + public void getForecastHour(int days, OnWeatherRetrieved callback) { + getForecastHour(MainActivity.getLocation(), days, callback); + } + + public void getForecastHour(Location l, OnWeatherRetrieved callback) { + if(l == null) return; + getForecastHour(l.getLatitude(), l.getLongitude(), callback); + } + + public void getForecastHour(Location l, int days, OnWeatherRetrieved callback) { + if(l == null) return; + getForecastHour(l.getLatitude(), l.getLongitude(), days, callback); + } + + public void getForecastHour(double lat, double lon, OnWeatherRetrieved callback) { + getForecastHour(lat, lon, MAX_DAYS_FORECAST, callback); + } + + public void getForecastHour(double lat, double lon, int days, OnWeatherRetrieved callback) { + if(MainActivity.hasInternet()) getForecastOnlineHour(lat, lon, days, callback); + else getForecastCachedHour(lat, lon, days, 0, callback); + } + + public void getForecastOnlineHour(double lat, double lon, final int days, final OnWeatherRetrieved callback) { + weatherConfig.numDays = days; + weatherClient.updateWeatherConfig(weatherConfig); + weatherClient.getHourForecastWeather(new WeatherRequest(lon, lat), new WeatherClient.HourForecastWeatherEventListener() { + @Override + public void onWeatherRetrieved(WeatherHourForecast forecast) { + List weatherList = new ArrayList<>(); + List foundForecasts = forecast.getHourForecast(); + int dayCount = Math.min(foundForecasts.size(), days); + if(dayCount == 0) return; + hourForecasts = new HourForecast[dayCount]; + weathers = new Weather[dayCount]; + for(int i=0; i weathers = new ArrayList<>(); + for(int i=0; iüberdacht - Vorhersage + Vorhersage (täglich) + Vorhersage (3 Stunden) Aktuell - Heute %1$s Tag diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ad03071..09390b8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -126,9 +126,9 @@ daysOfForecast username password - forecast + forecastDaily + forecastHour current - day 5 20 @@ -196,14 +196,14 @@ Roofed - Forecast + Forecast (daily) + Forecast (3 hour) Current - Today - @string/download_forecast_key + @string/download_forecast_daily_key + @string/download_forecast_hour_key @string/download_current_key - @string/download_day_key %1$s day