summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuis Vidal <lvidal@cyngn.com>2016-04-20 17:15:35 -0700
committerLuis Vidal <lvidal@cyngn.com>2016-04-21 13:18:45 -0700
commitece43f804ef326c76973115e56e9c0de35154c15 (patch)
tree14c348a97fc26702bcbb0f3b8e0e9dc07854fd0b
parent0a7e4bb6d65285a96b63930f8c510e4c6950c415 (diff)
downloadandroid_packages_providers_WeatherProvider-ece43f804ef326c76973115e56e9c0de35154c15.tar.gz
android_packages_providers_WeatherProvider-ece43f804ef326c76973115e56e9c0de35154c15.tar.bz2
android_packages_providers_WeatherProvider-ece43f804ef326c76973115e56e9c0de35154c15.zip
Check for default WeatherInfo values
The active weather provider might not supply all the data that WeatherInfo can hold. We need to check for default values before we update our cached WeatherInfo object; Change-Id: I8ed6012b7fd37c882e5261ff3d9d63eed34a47e2 TICKET: CYNGNOS-2525
-rw-r--r--src/org/cyanogenmod/weather/provider/WeatherContentProvider.java57
1 files changed, 38 insertions, 19 deletions
diff --git a/src/org/cyanogenmod/weather/provider/WeatherContentProvider.java b/src/org/cyanogenmod/weather/provider/WeatherContentProvider.java
index a23a57c..48df53a 100644
--- a/src/org/cyanogenmod/weather/provider/WeatherContentProvider.java
+++ b/src/org/cyanogenmod/weather/provider/WeatherContentProvider.java
@@ -29,6 +29,7 @@ import cyanogenmod.weather.WeatherInfo;
import cyanogenmod.weather.WeatherInfo.DayForecast;
import java.util.ArrayList;
+import java.util.List;
import static cyanogenmod.providers.WeatherContract.WeatherColumns.CURRENT_CITY;
import static cyanogenmod.providers.WeatherContract.WeatherColumns.CURRENT_CONDITION;
@@ -189,32 +190,50 @@ public class WeatherContentProvider extends ContentProvider {
if (match == URI_TYPE_CURRENT_AND_FORECAST) {
int contentValuesCount = contentValues.length;
synchronized (WeatherContentProvider.this) {
- ArrayList<DayForecast> dayForecasts = new ArrayList<>(contentValuesCount - 1);
+ List<DayForecast> dayForecasts = new ArrayList<>(contentValuesCount - 1);
for (int indx = 1; indx < contentValuesCount; indx++) {
- dayForecasts.add(new DayForecast.Builder(
- contentValues[indx].getAsInteger(FORECAST_CONDITION_CODE))
- .setLow(contentValues[indx].getAsDouble(FORECAST_LOW))
- .setHigh(contentValues[indx].getAsDouble(FORECAST_HIGH))
- .build());
+ DayForecast.Builder forecastBuilder
+ = new DayForecast.Builder(contentValues[indx]
+ .getAsInteger(FORECAST_CONDITION_CODE));
+
+ double low = contentValues[indx].getAsDouble(FORECAST_LOW);
+ if (!Double.isNaN(low)) forecastBuilder.setLow(low);
+
+ double high = contentValues[indx].getAsDouble(FORECAST_HIGH);
+ if (!Double.isNaN(high)) forecastBuilder.setHigh(high);
+
+ dayForecasts.add(forecastBuilder.build());
}
//First row is ALWAYS current weather
- mCachedWeatherInfo = new WeatherInfo.Builder(
- contentValues[0].getAsString(CURRENT_CITY),
- contentValues[0].getAsDouble(CURRENT_TEMPERATURE),
- contentValues[0].getAsInteger(CURRENT_TEMPERATURE_UNIT))
- .setWeatherCondition(contentValues[0].getAsInteger(CURRENT_CONDITION_CODE))
- .setForecast(dayForecasts)
- .setHumidity(contentValues[0].getAsDouble(CURRENT_HUMIDITY))
- .setWind(contentValues[0].getAsDouble(CURRENT_WIND_SPEED),
- contentValues[0].getAsDouble(CURRENT_WIND_DIRECTION),
- contentValues[0].getAsInteger(CURRENT_WIND_SPEED_UNIT))
+
+ WeatherInfo.Builder builder = new WeatherInfo.Builder(
+ contentValues[0].getAsString(CURRENT_CITY),
+ contentValues[0].getAsDouble(CURRENT_TEMPERATURE),
+ contentValues[0].getAsInteger(CURRENT_TEMPERATURE_UNIT))
.setTimestamp(contentValues[0].getAsLong(CURRENT_TIMESTAMP))
- .setTodaysHigh(contentValues[0].getAsDouble(TODAYS_HIGH_TEMPERATURE))
- .setTodaysLow(contentValues[0].getAsDouble(TODAYS_LOW_TEMPERATURE))
- .build();
+ .setWeatherCondition(contentValues[0].getAsInteger(CURRENT_CONDITION_CODE))
+ .setForecast(dayForecasts);
+
+ double humidity = contentValues[0].getAsDouble(CURRENT_HUMIDITY);
+ if (!Double.isNaN(humidity)) builder.setHumidity(humidity);
+
+ double high = contentValues[0].getAsDouble(TODAYS_HIGH_TEMPERATURE);
+ if (!Double.isNaN(high)) builder.setTodaysHigh(high);
+
+ double low = contentValues[0].getAsDouble(TODAYS_LOW_TEMPERATURE);
+ if (!Double.isNaN(low)) builder.setTodaysLow(low);
+
+ double windSpeed = contentValues[0].getAsDouble(CURRENT_WIND_SPEED);
+ double windDirection = contentValues[0].getAsDouble(CURRENT_WIND_DIRECTION);
+ int windSpeedUnit = contentValues[0].getAsInteger(CURRENT_WIND_SPEED_UNIT);
+
+ if (!Double.isNaN(windSpeed) && !Double.isNaN(windDirection)) {
+ builder.setWind(windSpeed, windDirection, windSpeedUnit);
+ }
+ mCachedWeatherInfo = builder.build();
}
getContext().getContentResolver().notifyChange(
WeatherColumns.CURRENT_AND_FORECAST_WEATHER_URI, null);