removed asynkTask

This commit is contained in:
Chumva 2018-03-16 10:31:48 +02:00
parent e05a633572
commit b3acbb0d32

View file

@ -52,7 +52,7 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
favouritePoints = getMyApplication().getFavorites().getVisibleFavouritePoints();
recyclerView = new RecyclerView(getContext());
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
location = getMyApplication().getLocationProvider().getLastKnownLocation();
title = (BottomSheetItemWithTitleAndButton) new BottomSheetItemWithTitleAndButton.Builder()
.setButtonIcons(null, getIcon(sortByDist ? R.drawable.ic_action_list_sort : R.drawable.ic_action_sort_by_name,
nightMode ? R.color.route_info_go_btn_inking_dark : R.color.dash_search_icon_light))
@ -60,13 +60,10 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
.setonButtonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (location == null) {
return;
}
sortFavourites();
title.setButtonIcons(null, getIcon(sortByDist ? R.drawable.ic_action_list_sort : R.drawable.ic_action_sort_by_name,
nightMode ? R.color.route_info_go_btn_inking_dark : R.color.dash_search_icon_light));
title.setButtonText(getString(sortByDist ? R.string.sort_by_distance : R.string.sort_by_name));
sortFavourites();
}
})
.setTitle(getString(R.string.favourites))
@ -98,7 +95,6 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
.setCustomView(recyclerView)
.create());
if (savedInstanceState != null && savedInstanceState.getBoolean(IS_SORTED)) {
location = getMyApplication().getLocationProvider().getLastKnownLocation();
sortByDist = savedInstanceState.getBoolean(SORTED_BY_TYPE);
sortFavourites();
}
@ -227,16 +223,15 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
return false;
}
@SuppressLint("StaticFieldLeak")
private void sortFavourites() {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
if (location == null) {
return;
}
final Collator inst = Collator.getInstance();
final LatLon latLon = new LatLon(location.getLatitude(), location.getLongitude());
Collections.sort(favouritePoints, new Comparator<FavouritePoint>() {
@Override
public int compare(FavouritePoint lhs, FavouritePoint rhs) {
LatLon latLon = new LatLon(location.getLatitude(), location.getLongitude());
if (sortByDist) {
double ld = MapUtils.getDistance(latLon, lhs.getLatitude(),
lhs.getLongitude());
@ -249,16 +244,6 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
});
sortByDist = !sortByDist;
isSorted = true;
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
if (adapter != null) {
adapter.notifyDataSetChanged();
}
}
}.execute();
}
}