private void updateWeatherInfo(WeatherForecast weatherForecast) { if (!weatherForecast.isSuccessed()) { notifier.alert(getString(R.string.weather_not_updated), Toast.LENGTH_LONG); return; } weatherContainer.setVisibility(View.VISIBLE); this.weatherForecast = weatherForecast; swipeIndicatorPresenter = new SwipeIndicatorPresenter(indicatorLayout, weatherForecast.getForecastList().size()); updateUI(); viewPager.setAdapter(new WeatherPagerAdapter(this, weatherForecast.getForecastList())); viewPager.setOnPageChangeListener( new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int i, float v, int i2) {} @Override public void onPageSelected(int i) { updateUI(i); } @Override public void onPageScrollStateChanged(int i) {} }); }
@Override public void onLoaded(WeatherForecast result) { if (!result.isSuccessed()) { Bundle data = new Bundle(); data.putCharSequence(ErrorActivity.ERROR_DESCRIPTION, getString(R.string.no_cache)); NavigationService.navigate(ForecastPageActivity.this, ErrorActivity.class); finish(); } updateWeatherInfo(result); }
private void updateUI(final int position) { if (!weatherForecast.isSuccessed() || weatherForecast == WeatherForecast.NULL) return; swipeIndicatorPresenter.setCurrentActivePosition(position); int size = weatherForecast.getForecastList().size(); if (position == 0) ibPrevious.setAlpha(128); else if (position == size - 1) ibNext.setAlpha(128); else { ibPrevious.setAlpha(255); ibNext.setAlpha(255); } WeatherModel model = weatherForecast.getForecastList().get(position); DateUtils utils = new DateUtils(); String nameOfDay = utils.getDayName(model.getDate()); tvDate.setText(nameOfDay); int currentTemp = Integer.parseInt(model.getMaxTemperature()); if (currentTemp < 0) tvMinus.setVisibility(View.VISIBLE); else { int invis = mConfiguration.isTablet() ? View.GONE : View.INVISIBLE; tvMinus.setVisibility(invis); } currentTemp = Math.abs(currentTemp); // int margin = resolveMargin(currentTemp); tvCurrentTemp.setText("" + currentTemp); // setMarginParams(margin, tvCurrentTemp); if (mConfiguration.isTablet()) { String locationName = mConfiguration.getLocationName(); locationName = (locationName == null) ? "" : locationName; tvLocation.setText(locationName); } tvNightTemp.setText(model.getMinTemperature()); if (position == 0) { tvHumidity.setText(model.getHumidity() + " %"); ivHumidity.setImageResource(getHumidityResource((model.getHumidity()))); } else { tvHumidity.setText(model.getPrecipitation()); ivHumidity.setImageResource(R.drawable.precipmm); } tvWindSpeed.setText(model.getWindSpeed()); tvWindDirection.setText(model.getWindDirection().getDisplayName()); ivLunarState.setImageResource( ResourcesCodeUtils.getLunarStateImageResource(model.getLunarState())); WeatherState weatherState = model.getState(); tvWeatherDescription.setText(weatherState.getDisplayName()); int backgroundColor = ResourcesCodeUtils.getWeatherBackgroundColor(weatherState); OWAnimationUtils.rotate(ivWindDirection, Float.parseFloat(model.getWindDegree()) + 180); weatherContainer.setBackgroundColor(getResources().getColor(backgroundColor)); }