Display toast if no nearby places found

This commit is contained in:
Josephine Lim 2017-05-15 11:18:53 +02:00
parent 9e17405b92
commit d0622d14b1

View file

@ -1,5 +1,6 @@
package fr.free.nrw.commons.nearby;
import android.content.Context;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
@ -10,6 +11,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.Toast;
import butterknife.BindView;
import butterknife.ButterKnife;
@ -51,7 +53,7 @@ public class NearbyActivity extends BaseActivity {
locationManager = new LocationServiceManager(this);
locationManager.registerLocationManager();
curLatLang = locationManager.getLatestLocation();
nearbyAsyncTask = new NearbyAsyncTask();
nearbyAsyncTask = new NearbyAsyncTask(this);
nearbyAsyncTask.execute();
}
@ -104,7 +106,7 @@ public class NearbyActivity extends BaseActivity {
}
protected void refreshView() {
nearbyAsyncTask = new NearbyAsyncTask();
nearbyAsyncTask = new NearbyAsyncTask(this);
nearbyAsyncTask.execute();
}
@ -120,6 +122,12 @@ public class NearbyActivity extends BaseActivity {
private class NearbyAsyncTask extends AsyncTask<Void, Integer, List<Place>> {
private Context mContext;
private NearbyAsyncTask (Context context) {
mContext = context;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
@ -151,6 +159,14 @@ public class NearbyActivity extends BaseActivity {
gsonPlaceList = gson.toJson(placeList);
gsonCurLatLng = gson.toJson(curLatLang);
if (placeList.size() == 0) {
CharSequence text = "No nearby places found";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(mContext, text, duration);
toast.show();
}
bundle.clear();
bundle.putString("PlaceList", gsonPlaceList);
bundle.putString("CurLatLng", gsonCurLatLng);