diff --git a/app/src/main/java/ru/gelin/android/weather/notification/ParcelableWeather2.java b/app/src/main/java/ru/gelin/android/weather/notification/ParcelableWeather2.java index 5f5f5dd01..77e403dc9 100644 --- a/app/src/main/java/ru/gelin/android/weather/notification/ParcelableWeather2.java +++ b/app/src/main/java/ru/gelin/android/weather/notification/ParcelableWeather2.java @@ -56,6 +56,10 @@ public class ParcelableWeather2 implements Parcelable { conditionBundle.getStringArray("weather_condition_types"); weatherSpec.currentTemp = conditionBundle.getInt("weather_current_temp"); + weatherSpec.windDirection = mapDirToDeg(conditionBundle.getString("weather_wind_direction")); + weatherSpec.windSpeed = getSpeedInKMH(conditionBundle.getInt("weather_wind_speed"), + conditionBundle.getString("weather_wind_speed_unit")); + String[] currentConditionType = conditionBundle.getStringArray("weather_condition_types"); if (currentConditionType != null) { weatherSpec.currentConditionCode = weatherConditionTypesToOpenWeatherMapIds(currentConditionType[0]); @@ -254,4 +258,28 @@ public class ParcelableWeather2 implements Parcelable { return 3200; } -} + private int getSpeedInKMH(int speed, String incomingUnit) { + float kmhSpeed = 0; + switch (incomingUnit) { + case "MPS": + kmhSpeed = speed * 3.6f; + break; + case "MPH": + kmhSpeed = speed * 1.6093f; + break; + case "KPH": + kmhSpeed = speed; + break; + } + return Math.round(kmhSpeed); + } + + private int mapDirToDeg(String dir) { + return Math.round(WindDirection.valueOf(dir).ordinal() * 22.5f); + } + + private enum WindDirection { // see upstream code, we can't be more precise than getting the quadrant + N, NNE, NE, ENE, E, ESE, SE, SSE, S, SSW, SW, WSW, W, WNW, NW, NNW + } + +} \ No newline at end of file