mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Merge pull request #287 from misaochan/cancel-asynctask
Fix crash with Nearby when back button pressed or no network
This commit is contained in:
commit
c04dc99105
2 changed files with 21 additions and 4 deletions
|
|
@ -109,6 +109,15 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
|
||||||
|
if(nearbyAsyncTask != null && nearbyAsyncTask.getStatus() != AsyncTask.Status.FINISHED) {
|
||||||
|
nearbyAsyncTask.cancel(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class NearbyAsyncTask extends AsyncTask<Void, Integer, List<Place>> {
|
private class NearbyAsyncTask extends AsyncTask<Void, Integer, List<Place>> {
|
||||||
|
|
||||||
private final TaskListener listener;
|
private final TaskListener listener;
|
||||||
|
|
@ -138,6 +147,11 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(List<Place> result) {
|
protected void onPostExecute(List<Place> result) {
|
||||||
super.onPostExecute(result);
|
super.onPostExecute(result);
|
||||||
|
|
||||||
|
if(isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
progressBar.setVisibility(View.GONE);
|
progressBar.setVisibility(View.GONE);
|
||||||
|
|
||||||
mAdapter = new NearbyAdapter(getActivity(), places);
|
mAdapter = new NearbyAdapter(getActivity(), places);
|
||||||
|
|
@ -304,10 +318,12 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 500; i++) {
|
if (places.size() > 0) {
|
||||||
Place place = places.get(i);
|
for (int i = 0; i < 100; i++) {
|
||||||
String distance = formatDistanceBetween(mLatestLocation, place.location);
|
Place place = places.get(i);
|
||||||
place.setDistance(distance);
|
String distance = formatDistanceBetween(mLatestLocation, place.location);
|
||||||
|
place.setDistance(distance);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return places;
|
return places;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ public class NearbyPlaces {
|
||||||
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
||||||
StrictMode.setThreadPolicy(policy);
|
StrictMode.setThreadPolicy(policy);
|
||||||
|
|
||||||
|
|
||||||
URL file = new URL("https://tools.wmflabs.org/wiki-needs-pictures/data/data.csv");
|
URL file = new URL("https://tools.wmflabs.org/wiki-needs-pictures/data/data.csv");
|
||||||
|
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(file.openStream()));
|
BufferedReader in = new BufferedReader(new InputStreamReader(file.openStream()));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue