summaryrefslogtreecommitdiffstats
path: root/app/src/main/java/org/cyanogenmod/yahooweatherprovider/ConverterUtils.java
diff options
context:
space:
mode:
authorAdnan Begovic <adnan@cyngn.com>2016-05-05 19:18:14 -0700
committerAdnan Begovic <adnan@cyngn.com>2016-05-05 19:19:52 -0700
commit8f91a81e0160a744d30a553b0a563acbf8252920 (patch)
tree6ebe1f594dba18888cac5751695777bf0d19767f /app/src/main/java/org/cyanogenmod/yahooweatherprovider/ConverterUtils.java
parent18838318e646e9d49404e4843b981ecbc46c6abd (diff)
downloadandroid_packages_apps_YahooWeatherProvider-8f91a81e0160a744d30a553b0a563acbf8252920.tar.gz
android_packages_apps_YahooWeatherProvider-8f91a81e0160a744d30a553b0a563acbf8252920.tar.bz2
android_packages_apps_YahooWeatherProvider-8f91a81e0160a744d30a553b0a563acbf8252920.zip
YahooCM: Add proper offsets for duplicate weather codes by yahoo.
Change-Id: I9cd8274606ecba47e3a127b342bdece2e6f894ae
Diffstat (limited to 'app/src/main/java/org/cyanogenmod/yahooweatherprovider/ConverterUtils.java')
-rw-r--r--app/src/main/java/org/cyanogenmod/yahooweatherprovider/ConverterUtils.java24
1 files changed, 22 insertions, 2 deletions
diff --git a/app/src/main/java/org/cyanogenmod/yahooweatherprovider/ConverterUtils.java b/app/src/main/java/org/cyanogenmod/yahooweatherprovider/ConverterUtils.java
index 6a81b4e..53b2158 100644
--- a/app/src/main/java/org/cyanogenmod/yahooweatherprovider/ConverterUtils.java
+++ b/app/src/main/java/org/cyanogenmod/yahooweatherprovider/ConverterUtils.java
@@ -27,16 +27,22 @@ import org.cyanogenmod.yahooweatherprovider.yahoo.response.Postal;
import java.util.ArrayList;
import java.util.List;
+import cyanogenmod.providers.WeatherContract;
import cyanogenmod.weather.WeatherInfo;
import cyanogenmod.weather.WeatherLocation;
+import static cyanogenmod.providers.WeatherContract.WeatherColumns.WeatherCode.ISOLATED_THUNDERSHOWERS;
+import static cyanogenmod.providers.WeatherContract.WeatherColumns.WeatherCode.NOT_AVAILABLE;
+import static cyanogenmod.providers.WeatherContract.WeatherColumns.WeatherCode.SCATTERED_SNOW_SHOWERS;
+import static cyanogenmod.providers.WeatherContract.WeatherColumns.WeatherCode.SCATTERED_THUNDERSTORMS;
+
public class ConverterUtils {
public static ArrayList<WeatherInfo.DayForecast> convertForecastsToDayForecasts(List<Forecast> forecasts) {
ArrayList<WeatherInfo.DayForecast> ret = new ArrayList<>();
for (Forecast forecast : forecasts) {
- WeatherInfo.DayForecast dayForecast = new WeatherInfo.DayForecast.Builder(
- Integer.parseInt(forecast.getCode()))
+ WeatherInfo.DayForecast dayForecast = new WeatherInfo.DayForecast.Builder(offset(
+ Integer.parseInt(forecast.getCode())))
.setHigh(Double.parseDouble(forecast.getHigh()))
.setLow(Double.parseDouble(forecast.getLow()))
.build();
@@ -96,4 +102,18 @@ public class ConverterUtils {
}
return ret;
}
+
+ public static int offset(int conditionCode) {
+ if (conditionCode <= WeatherContract.WeatherColumns.WeatherCode.SHOWERS) {
+ return conditionCode;
+ } else if (conditionCode <= SCATTERED_THUNDERSTORMS) {
+ return conditionCode - 1;
+ } else if (conditionCode <= SCATTERED_SNOW_SHOWERS) {
+ return conditionCode - 2;
+ } else if (conditionCode <= ISOLATED_THUNDERSHOWERS) {
+ return conditionCode - 3;
+ } else {
+ return NOT_AVAILABLE;
+ }
+ }
}