Skip to content

Commit

Permalink
YahooCM: Hardcode forecast day count.
Browse files Browse the repository at this point in the history
  Add todo for future user configuration.

Change-Id: I20690e9771448635766e84d591047217b94b64e4
  • Loading branch information
Adnan Begovic committed May 6, 2016
1 parent 636b71a commit a8980db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Expand Up @@ -38,15 +38,21 @@

public class ConverterUtils {

public static ArrayList<WeatherInfo.DayForecast> convertForecastsToDayForecasts(List<Forecast> forecasts) {
public static ArrayList<WeatherInfo.DayForecast> convertForecastsToDayForecasts(
List<Forecast> forecasts, int max) {
ArrayList<WeatherInfo.DayForecast> ret = new ArrayList<>();
int i = 0;
for (Forecast forecast : forecasts) {
if (i > max) {
break;
}
WeatherInfo.DayForecast dayForecast = new WeatherInfo.DayForecast.Builder(offset(
Integer.parseInt(forecast.getCode())))
.setHigh(Double.parseDouble(forecast.getHigh()))
.setLow(Double.parseDouble(forecast.getLow()))
.build();
ret.add(dayForecast);
i++;
}
return ret;
}
Expand Down
Expand Up @@ -64,6 +64,9 @@ public class YahooWeatherProviderService extends WeatherProviderService
private static final int SERVICE_REQUEST_CANCELLED = -1;
private static final int SERVICE_REQUEST_SUBMITTED = 0;

//TODO, add a setting for this
private static final int MAX_FORECAST_DAYS = 5;

@Inject
public YahooWeatherServiceManager mYahooWeatherServiceManager;

Expand Down Expand Up @@ -265,7 +268,7 @@ private void processWeatherRequest(YQLResponse yqlResponse, ServiceRequest servi

ArrayList<WeatherInfo.DayForecast> forecastList =
ConverterUtils.convertForecastsToDayForecasts(
Arrays.asList(forecasts));
Arrays.asList(forecasts), MAX_FORECAST_DAYS);
// Remove today
forecastList.remove(0);

Expand Down

0 comments on commit a8980db

Please sign in to comment.