summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdnan Begovic <adnan@cyngn.com>2016-05-06 02:18:14 (GMT)
committerAdnan Begovic <adnan@cyngn.com>2016-05-06 02:19:52 (GMT)
commit8f91a81e0160a744d30a553b0a563acbf8252920 (patch)
tree6ebe1f594dba18888cac5751695777bf0d19767f
parent18838318e646e9d49404e4843b981ecbc46c6abd (diff)
downloadandroid_packages_apps_YahooWeatherProvider-8f91a81e0160a744d30a553b0a563acbf8252920.zip
android_packages_apps_YahooWeatherProvider-8f91a81e0160a744d30a553b0a563acbf8252920.tar.gz
android_packages_apps_YahooWeatherProvider-8f91a81e0160a744d30a553b0a563acbf8252920.tar.bz2
YahooCM: Add proper offsets for duplicate weather codes by yahoo.
Change-Id: I9cd8274606ecba47e3a127b342bdece2e6f894ae
-rw-r--r--app/src/main/java/org/cyanogenmod/yahooweatherprovider/ConverterUtils.java24
-rw-r--r--app/src/main/java/org/cyanogenmod/yahooweatherprovider/YahooWeatherProviderService.java6
-rw-r--r--app/src/test/java/org/cyanogenmod/yahooweatherprovider/ExampleUnitTest.java15
3 files changed, 26 insertions, 19 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;
+ }
+ }
}
diff --git a/app/src/main/java/org/cyanogenmod/yahooweatherprovider/YahooWeatherProviderService.java b/app/src/main/java/org/cyanogenmod/yahooweatherprovider/YahooWeatherProviderService.java
index 7fcfbf0..dd6d327 100644
--- a/app/src/main/java/org/cyanogenmod/yahooweatherprovider/YahooWeatherProviderService.java
+++ b/app/src/main/java/org/cyanogenmod/yahooweatherprovider/YahooWeatherProviderService.java
@@ -248,7 +248,8 @@ public class YahooWeatherProviderService extends WeatherProviderService
WeatherContract.WeatherColumns.TempUnit.FAHRENHEIT);
// Set current weather condition code
- weatherInfoBuilder.setWeatherCondition(Integer.parseInt(condition.getCode()));
+ weatherInfoBuilder.setWeatherCondition(
+ ConverterUtils.offset(Integer.parseInt(condition.getCode())));
// Set humidity
weatherInfoBuilder.setHumidity(Double.parseDouble(atmosphere.getHumidity()));
@@ -262,7 +263,8 @@ public class YahooWeatherProviderService extends WeatherProviderService
weatherInfoBuilder.setTodaysHigh(Double.parseDouble(forecasts[0].getHigh()));
weatherInfoBuilder.setTodaysLow(Double.parseDouble(forecasts[0].getHigh()));
- ArrayList<WeatherInfo.DayForecast> forecastList = ConverterUtils.convertForecastsToDayForecasts(
+ ArrayList<WeatherInfo.DayForecast> forecastList =
+ ConverterUtils.convertForecastsToDayForecasts(
Arrays.asList(forecasts));
// Remove today
forecastList.remove(0);
diff --git a/app/src/test/java/org/cyanogenmod/yahooweatherprovider/ExampleUnitTest.java b/app/src/test/java/org/cyanogenmod/yahooweatherprovider/ExampleUnitTest.java
deleted file mode 100644
index 56c97d1..0000000
--- a/app/src/test/java/org/cyanogenmod/yahooweatherprovider/ExampleUnitTest.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package org.cyanogenmod.yahooweatherprovider;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * To work on unit tests, switch the Test Artifact in the Build Variants view.
- */
-public class ExampleUnitTest {
- @Test
- public void addition_isCorrect() throws Exception {
- assertEquals(4, 2 + 2);
- }
-} \ No newline at end of file