diff --git a/onebusaway-android/src/main/java/org/onebusaway/android/ui/HomeActivity.java b/onebusaway-android/src/main/java/org/onebusaway/android/ui/HomeActivity.java index 9e13964ea..8386dbc7f 100644 --- a/onebusaway-android/src/main/java/org/onebusaway/android/ui/HomeActivity.java +++ b/onebusaway-android/src/main/java/org/onebusaway/android/ui/HomeActivity.java @@ -581,6 +581,11 @@ private void goToNavDrawerItem(int item) { startActivity(i); break; } + if (mCurrentNavDrawerPosition != NAVDRAWER_ITEM_NEARBY) { + WeatherUtils.toggleWeatherViewVisibility(false,weatherView); + }else{ + setWeatherData(); + } invalidateOptionsMenu(); } @@ -1997,7 +2002,7 @@ public void onValidRegion(boolean isValid) { if(isValid){ makeWeatherRequest(); }else{ - weatherView.setVisibility(View.GONE); + WeatherUtils.toggleWeatherViewVisibility(false,weatherView); weatherResponse = null; } } @@ -2007,6 +2012,8 @@ private void initWeatherView(){ } private void setWeatherData() { + if(weatherResponse == null || mCurrentNavDrawerPosition != NAVDRAWER_ITEM_NEARBY) return; + WeatherUtils.toggleWeatherViewVisibility(true,weatherView); TextView tempTxtView = findViewById(R.id.weatherTextView); ImageView weatherImageView = findViewById(R.id.weatherStateImageView); String weatherIcon = weatherResponse.getCurrent_forecast().getIcon(); @@ -2045,7 +2052,6 @@ private void makeWeatherRequest(){ @Override public void onWeatherResponseReceived(ObaWeatherResponse response) { if(response != null && response.getCurrent_forecast() != null){ - weatherView.setVisibility(View.VISIBLE); weatherResponse = response; setWeatherData(); } diff --git a/onebusaway-android/src/main/java/org/onebusaway/android/ui/weather/WeatherUtils.java b/onebusaway-android/src/main/java/org/onebusaway/android/ui/weather/WeatherUtils.java index ae28356f7..908ee5462 100644 --- a/onebusaway-android/src/main/java/org/onebusaway/android/ui/weather/WeatherUtils.java +++ b/onebusaway-android/src/main/java/org/onebusaway/android/ui/weather/WeatherUtils.java @@ -1,6 +1,7 @@ package org.onebusaway.android.ui.weather; import android.content.SharedPreferences; +import android.view.View; import android.widget.ImageView; import android.widget.TextView; @@ -39,6 +40,16 @@ public static void setWeatherTemp(TextView weatherTempTxtView, double temp) { weatherTempTxtView.setText(temperatureText); } + public static void toggleWeatherViewVisibility(boolean shouldShow, View weatherView) { + if (weatherView != null) { + if (shouldShow) { + weatherView.setVisibility(View.VISIBLE); + } else { + weatherView.setVisibility(View.GONE); + } + } + } + private static int getWeatherDrawableRes(String condition) { switch (condition) {