diff --git a/app/build.gradle b/app/build.gradle index 34eec08..32b882c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "org.woheller69.solxpect" minSdkVersion 26 targetSdk 34 - versionCode 23 - versionName "2.3" + versionCode 24 + versionName "2.4" buildConfigField "String", "BASE_URL", "\"https://api.open-meteo.com/v1/\"" buildConfigField "String", "TILES_URL","\"https://tile.openstreetmap.org/\"" diff --git a/app/src/main/java/org/woheller69/weather/ui/RecycleList/CityWeatherAdapter.java b/app/src/main/java/org/woheller69/weather/ui/RecycleList/CityWeatherAdapter.java index e6f36dd..ab01a9c 100644 --- a/app/src/main/java/org/woheller69/weather/ui/RecycleList/CityWeatherAdapter.java +++ b/app/src/main/java/org/woheller69/weather/ui/RecycleList/CityWeatherAdapter.java @@ -100,18 +100,26 @@ public void updateForecastData(List hourlyForecasts) { courseDayList = new ArrayList<>(); float energyCumulated=0; - for (HourlyForecast f : hourlyForecasts) { - energyCumulated+=f.getPower(); - f.setEnergyCum(energyCumulated); - if (sp.getBoolean("pref_debug",false)) { - courseDayList.add(f); - } else { - if (f.getForecastTime() >= System.currentTimeMillis()) { - courseDayList.add(f); - } - } + boolean isDebugMode = sp.getBoolean("pref_debug", false); + int stepCounter = 0; // Counter to track the number of steps taken in the loop + + for (HourlyForecast f : hourlyForecasts) { + float power = f.getPower(); + if (stepCounter > 0) energyCumulated += power; //Ignore first value because power values are for preceding hour + f.setEnergyCum(energyCumulated); + + // In debug mode show all values, otherwise only future values + if (isDebugMode || f.getForecastTime() >= System.currentTimeMillis()) { + courseDayList.add(f); } - notifyDataSetChanged(); + + stepCounter++; + // if not in debug mode: Reset energyCumulated after every 24 hours if next step is 01:00 am because values are for previous hour + if (!isDebugMode && stepCounter % 24 == 1) { + energyCumulated = 0; + } + } + notifyDataSetChanged(); } // function for week forecast list 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 85207d2..a433b74 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 @@ -198,7 +198,7 @@ private List reanalyzeWeekIDs(List weekforecasts, Li float totalEnergy = 0; Long timeNoon = weekForecast.getForecastTime(); for (HourlyForecast hourlyForecast: hourlyforecasts){ - if ((hourlyForecast.getForecastTime()>=timeNoon-12*3600*1000L) && (hourlyForecast.getForecastTime()< timeNoon + 12*3600*1000L)){ + if ((hourlyForecast.getForecastTime()>=timeNoon-11*3600*1000L) && (hourlyForecast.getForecastTime()< timeNoon + 13*3600*1000L)){ //values are for preceding hour! totalEnergy+=hourlyForecast.getPower(); } } diff --git a/fastlane/metadata/android/en-US/changelogs/24.txt b/fastlane/metadata/android/en-US/changelogs/24.txt new file mode 100644 index 0000000..4471a88 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/24.txt @@ -0,0 +1,2 @@ +Reset cumulated values every 24h +Bugfix \ No newline at end of file