Added TaskListener interface

This commit is contained in:
misaochan 2016-09-06 18:32:22 +12:00
parent 0a32db5c0b
commit 26ab3faf1e

View file

@ -44,6 +44,12 @@ public class NearbyListFragment extends ListFragment {
public NearbyListFragment() { public NearbyListFragment() {
} }
public interface TaskListener {
void onTaskStarted();
void onTaskFinished(List<Place> result);
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -77,12 +83,10 @@ public class NearbyListFragment extends ListFragment {
public void onViewCreated(View view, Bundle savedInstanceState) { public void onViewCreated(View view, Bundle savedInstanceState) {
progressBar.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE);
mLatestLocation = ((NearbyActivity) getActivity()).getmLatestLocation(); mLatestLocation = ((NearbyActivity) getActivity()).getmLatestLocation();
nearbyAsyncTask = new NearbyAsyncTask(); nearbyAsyncTask = new NearbyAsyncTask();
nearbyAsyncTask.execute(); nearbyAsyncTask.execute();
Log.d(TAG, "Adapter set to ListView"); Log.d(TAG, "Adapter set to ListView");
} }
@ -91,10 +95,19 @@ public class NearbyListFragment extends ListFragment {
isTaskRunning = true; isTaskRunning = true;
progressDialog = ProgressDialog.show(getActivity(), "Loading", "Please wait a moment!"); progressDialog = ProgressDialog.show(getActivity(), "Loading", "Please wait a moment!");
} }
private class NearbyAsyncTask extends AsyncTask<Void, Integer, List<Place>> { private class NearbyAsyncTask extends AsyncTask<Void, Integer, List<Place>> {
private final TaskListener listener;
public NearbyAsyncTask (TaskListener listener) {
this.listener = listener;
}
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
super.onPreExecute(); super.onPreExecute();
listener.onTaskStarted();
lockScreenOrientation(); lockScreenOrientation();
} }
@ -141,6 +154,7 @@ public class NearbyListFragment extends ListFragment {
} }
} }
}); });
listener.onTaskFinished(result);
mAdapter.notifyDataSetChanged(); mAdapter.notifyDataSetChanged();
} }
} }