Garmin: Fix daily weather missing current day

This commit is contained in:
José Rebelo 2024-09-03 23:03:46 +01:00
parent c04d3adf7c
commit bd5b54c3b4
2 changed files with 26 additions and 1 deletions

View File

@ -200,6 +200,30 @@ public class WeatherSpec implements Parcelable, Serializable {
dest.writeList(hourly);
}
/**
* Convert the current day's forecast to a {@link Daily} object.
*/
public Daily todayAsDaily() {
final Daily daily = new Daily();
daily.minTemp = this.todayMinTemp;
daily.maxTemp = this.todayMaxTemp;
daily.conditionCode = this.currentConditionCode;
daily.humidity = this.currentHumidity;
daily.windSpeed = this.windSpeed;
daily.windDirection = this.windDirection;
daily.uvIndex = this.uvIndex;
daily.precipProbability = this.precipProbability;
daily.sunRise = this.sunRise;
daily.sunSet = this.sunSet;
daily.moonRise = this.moonRise;
daily.moonSet = this.moonSet;
daily.moonPhase = this.moonPhase;
daily.airQuality = this.airQuality;
return daily;
}
@Deprecated // kept for backwards compatibility with old weather apps
public static class Forecast implements Parcelable, Serializable {
private static final long serialVersionUID = 1L;

View File

@ -57,7 +57,8 @@ public class WeatherHandler {
final List<WeatherForecastDay> ret = new ArrayList<>(duration);
final GregorianCalendar date = new GregorianCalendar();
date.setTime(new Date(weatherSpec.timestamp * 1000L));
for (int i = 0; i < Math.min(duration, weatherSpec.forecasts.size()); i++) {
ret.add(new WeatherForecastDay(date, weatherSpec.todayAsDaily(), tempUnit, speedUnit));
for (int i = 0; i < Math.min(duration, weatherSpec.forecasts.size()) - 1; i++) {
date.add(Calendar.DAY_OF_MONTH, 1);
ret.add(new WeatherForecastDay(date, weatherSpec.forecasts.get(i), tempUnit, speedUnit));
}