Skip to content

Commit

Permalink
Fixed OneBusAway#1187 - Weather Feature Crash
Browse files Browse the repository at this point in the history
Signed-off-by: Amr Hossam <amrhossam.dev@gmail.com>
  • Loading branch information
amrhossamdev committed Mar 29, 2024
1 parent b67e8f5 commit 79e7240
Showing 1 changed file with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -599,14 +599,14 @@ private void showMapFragment() {
Log.d(TAG, "Creating new BaseMapFragment");
mMapFragment = BaseMapFragment.newInstance();
mMapFragment.setOnLocationPermissionResultListener(result -> {
if (mInitialStartup) {
// Whether or not the user granted permissions, check region status
// (they'll be asked to manually pick region if they denied)
mInitialStartup = false;
PreferenceUtils.saveBoolean(INITIAL_STARTUP, false);
checkRegionStatus();
}
});
if (mInitialStartup) {
// Whether or not the user granted permissions, check region status
// (they'll be asked to manually pick region if they denied)
mInitialStartup = false;
PreferenceUtils.saveBoolean(INITIAL_STARTUP, false);
checkRegionStatus();
}
});
fm.beginTransaction()
.add(R.id.main_fragment_container, mMapFragment, BaseMapFragment.TAG)
.commit();
Expand Down Expand Up @@ -1506,7 +1506,7 @@ private void setFABLocation(boolean leftHandMode) {
}
}
}

/**
* Moves both Floating Action Buttons as response to sliding panel height changes.
* <p>
Expand Down Expand Up @@ -1997,14 +1997,25 @@ private void initWeatherView(){
weatherView = findViewById(R.id.weatherView);
}

private void setWeatherData(){
private void setWeatherData() {
TextView tempTxtView = findViewById(R.id.weatherTextView);
ImageView weatherImageView = findViewById(R.id.weatherStateImageView);
String weatherIcon = weatherResponse.getCurrent_forecast().getIcon();
String weatherSummary = weatherResponse.getCurrent_forecast().getSummary();
double weatherTemp = weatherResponse.getCurrent_forecast().getTemperature();

WeatherUtils.setWeatherImage(weatherImageView,weatherResponse.getCurrent_forecast().getIcon(),this);
WeatherUtils.setWeatherTemp(tempTxtView,weatherResponse.getCurrent_forecast().getTemperature());
if (weatherIcon != null && !weatherIcon.isEmpty()) {
WeatherUtils.setWeatherImage(weatherImageView, weatherIcon, this);
}else{
weatherImageView.setVisibility(View.GONE);
}
WeatherUtils.setWeatherTemp(tempTxtView, weatherTemp);
// Show weather state when click.
weatherView.setOnClickListener(view -> Toast.makeText(getApplicationContext(),weatherResponse.getCurrent_forecast().getSummary().trim(),Toast.LENGTH_SHORT).show());
weatherView.setOnClickListener(view -> {
if (weatherSummary != null) {
Toast.makeText(getApplicationContext(), weatherResponse.getCurrent_forecast().getSummary().trim(), Toast.LENGTH_SHORT).show();
}
});
}

private void makeWeatherRequest(){
Expand All @@ -2026,7 +2037,9 @@ private void makeWeatherRequest(){
public void onWeatherResponseReceived(ObaWeatherResponse response) {
weatherView.setVisibility(View.VISIBLE);
weatherResponse = response;
setWeatherData();
if(weatherResponse != null && weatherResponse.getCurrent_forecast() != null){
setWeatherData();
}
}

@Override
Expand Down

0 comments on commit 79e7240

Please sign in to comment.