StationsActivity: Fix NullPointerException in handleIntent().

This commit is contained in:
Andreas Schildbach 2018-11-26 17:37:14 +01:00
parent a4fba695a4
commit 5170775169

View file

@ -594,43 +594,42 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
final Location[] locations = LocationUriParser.parseLocations(intentUri.toString()); final Location[] locations = LocationUriParser.parseLocations(intentUri.toString());
fixedLocation = locations != null && locations.length >= 1 ? locations[0] : null; fixedLocation = locations != null && locations.length >= 1 ? locations[0] : null;
if (fixedLocation != null) { if (fixedLocation != null && fixedLocation.hasCoord())
mapView.animateToLocation(fixedLocation.getLatAsDouble(), fixedLocation.getLonAsDouble()); mapView.animateToLocation(fixedLocation.getLatAsDouble(), fixedLocation.getLonAsDouble());
findViewById(R.id.stations_location_clear).setOnClickListener(new OnClickListener() { findViewById(R.id.stations_location_clear).setOnClickListener(new OnClickListener() {
public void onClick(final View v) { public void onClick(final View v) {
fixedLocation = null; fixedLocation = null;
if (deviceLocation != null) { if (deviceLocation != null) {
mapView.animateToLocation(deviceLocation.getLatAsDouble(), deviceLocation.getLonAsDouble()); mapView.animateToLocation(deviceLocation.getLatAsDouble(), deviceLocation.getLonAsDouble());
final float[] distanceBetweenResults = new float[2]; final float[] distanceBetweenResults = new float[2];
// remove non-favorites and re-calculate distances // remove non-favorites and re-calculate distances
for (final Iterator<Station> i = stations.iterator(); i.hasNext();) { for (final Iterator<Station> i = stations.iterator(); i.hasNext();) {
final Station station = i.next(); final Station station = i.next();
final Integer favState = favorites.get(station.location.id); final Integer favState = favorites.get(station.location.id);
if (favState == null || favState != FavoriteStationsProvider.TYPE_FAVORITE) { if (favState == null || favState != FavoriteStationsProvider.TYPE_FAVORITE) {
i.remove(); i.remove();
stationsMap.remove(station.location.id); stationsMap.remove(station.location.id);
} else if (station.location.hasCoord()) { } else if (station.location.hasCoord()) {
android.location.Location.distanceBetween(deviceLocation.getLatAsDouble(), android.location.Location.distanceBetween(deviceLocation.getLatAsDouble(),
deviceLocation.getLonAsDouble(), station.location.getLatAsDouble(), deviceLocation.getLonAsDouble(), station.location.getLatAsDouble(),
station.location.getLonAsDouble(), distanceBetweenResults); station.location.getLonAsDouble(), distanceBetweenResults);
station.setDistanceAndBearing(distanceBetweenResults[0], distanceBetweenResults[1]); station.setDistanceAndBearing(distanceBetweenResults[0], distanceBetweenResults[1]);
}
} }
stationListAdapter.notifyDataSetChanged();
} }
stationListAdapter.notifyDataSetChanged();
handler.post(initStationsRunnable);
updateGUI();
} }
});
handler.post(initStationsRunnable); handler.post(initStationsRunnable);
} updateGUI();
}
});
handler.post(initStationsRunnable);
} }
final String query = intent.getStringExtra(SearchManager.QUERY); final String query = intent.getStringExtra(SearchManager.QUERY);