Reduce scope of places field

This commit is contained in:
veyndan 2017-04-16 21:35:09 +01:00
parent 6c4751d7b7
commit 2df1cdfbd9

View file

@ -40,8 +40,6 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
private boolean isTaskRunning = false; private boolean isTaskRunning = false;
private List<Place> places;
private static final String TAG = NearbyListFragment.class.getName(); private static final String TAG = NearbyListFragment.class.getName();
public NearbyListFragment() { public NearbyListFragment() {
@ -145,15 +143,14 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
@Override @Override
protected List<Place> doInBackground(Void... params) { protected List<Place> doInBackground(Void... params) {
places = loadAttractionsFromLocation( return loadAttractionsFromLocation(
((NearbyActivity)getActivity()).getLocationManager().getLatestLocation() ((NearbyActivity)getActivity()).getLocationManager().getLatestLocation()
); );
return places;
} }
@Override @Override
protected void onPostExecute(List<Place> result) { protected void onPostExecute(List<Place> places) {
super.onPostExecute(result); super.onPostExecute(places);
if (isCancelled()) { if (isCancelled()) {
return; return;
@ -164,14 +161,14 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
listview.setAdapter(adapter); listview.setAdapter(adapter);
listener.onTaskFinished(result); listener.onTaskFinished(places);
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
} }
@OnItemClick(R.id.listview) @OnItemClick(R.id.listview)
void onItemClicked(int position) { void onItemClicked(int position) {
Place place = places.get(position); Place place = (Place) listview.getItemAtPosition(position);
LatLng placeLatLng = place.location; LatLng placeLatLng = place.location;
double latitude = placeLatLng.latitude; double latitude = placeLatLng.latitude;