diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyListFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyListFragment.java index ee527b072..484d7677c 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyListFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyListFragment.java @@ -2,6 +2,7 @@ package fr.free.nrw.commons.nearby; import android.content.Context; +import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.support.v7.widget.RecyclerView; @@ -72,13 +73,9 @@ public class NearbyListFragment extends ListFragment { mLatestLocation = ((NearbyActivity) getActivity()).getmLatestLocation(); //Hardcoding mLatestLocation to Michigan for testing //mLatestLocation = new LatLng(44.182205, -84.506836); - - places = loadAttractionsFromLocation(mLatestLocation); - mAdapter = new NearbyAdapter(getActivity(), places); - - ListView listview = (ListView) view.findViewById(R.id.listview); - //setListAdapter(mAdapter); - listview.setAdapter(mAdapter); + + getNearbyPlaces nearbyList = new getNearbyPlaces(); + nearbyList.execute(); Log.d(TAG, "Adapter set to ListView"); mAdapter.notifyDataSetChanged(); @@ -113,6 +110,36 @@ public class NearbyListFragment extends ListFragment { return places; } + private class getNearbyPlaces extends AsyncTask> { + @Override + protected void onPreExecute() { + super.onPreExecute(); + } + + @Override + protected void onProgressUpdate(String... values) { + super.onProgressUpdate(values); + } + + @Override + protected List doInBackground(Void... params) { + places = loadAttractionsFromLocation(mLatestLocation); + return places; + } + + @Override + protected void onPostExecute(List result) { + super.onPostExecute(result); + + mAdapter = new NearbyAdapter(getActivity(), places); + + ListView listview = (ListView) getView().findViewById(R.id.listview); + //setListAdapter(mAdapter); + listview.setAdapter(mAdapter); + + } + } + private class NearbyAdapter extends ArrayAdapter { public List placesList; diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyPlaces.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyPlaces.java index be52f1dfe..66484de12 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyPlaces.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyPlaces.java @@ -14,7 +14,7 @@ public class NearbyPlaces { static List places = null; - public static synchronized List get() { + public static List get() { if(places != null) { return places; }