removed asynkTask
This commit is contained in:
parent
e05a633572
commit
b3acbb0d32
1 changed files with 20 additions and 35 deletions
|
@ -52,7 +52,7 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
||||||
favouritePoints = getMyApplication().getFavorites().getVisibleFavouritePoints();
|
favouritePoints = getMyApplication().getFavorites().getVisibleFavouritePoints();
|
||||||
recyclerView = new RecyclerView(getContext());
|
recyclerView = new RecyclerView(getContext());
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
|
location = getMyApplication().getLocationProvider().getLastKnownLocation();
|
||||||
title = (BottomSheetItemWithTitleAndButton) new BottomSheetItemWithTitleAndButton.Builder()
|
title = (BottomSheetItemWithTitleAndButton) new BottomSheetItemWithTitleAndButton.Builder()
|
||||||
.setButtonIcons(null, getIcon(sortByDist ? R.drawable.ic_action_list_sort : R.drawable.ic_action_sort_by_name,
|
.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))
|
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() {
|
.setonButtonClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
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,
|
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));
|
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));
|
title.setButtonText(getString(sortByDist ? R.string.sort_by_distance : R.string.sort_by_name));
|
||||||
|
sortFavourites();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setTitle(getString(R.string.favourites))
|
.setTitle(getString(R.string.favourites))
|
||||||
|
@ -98,7 +95,6 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
||||||
.setCustomView(recyclerView)
|
.setCustomView(recyclerView)
|
||||||
.create());
|
.create());
|
||||||
if (savedInstanceState != null && savedInstanceState.getBoolean(IS_SORTED)) {
|
if (savedInstanceState != null && savedInstanceState.getBoolean(IS_SORTED)) {
|
||||||
location = getMyApplication().getLocationProvider().getLastKnownLocation();
|
|
||||||
sortByDist = savedInstanceState.getBoolean(SORTED_BY_TYPE);
|
sortByDist = savedInstanceState.getBoolean(SORTED_BY_TYPE);
|
||||||
sortFavourites();
|
sortFavourites();
|
||||||
}
|
}
|
||||||
|
@ -227,38 +223,27 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
|
||||||
private void sortFavourites() {
|
private void sortFavourites() {
|
||||||
new AsyncTask<Void, Void, Void>() {
|
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
|
@Override
|
||||||
protected Void doInBackground(Void... voids) {
|
public int compare(FavouritePoint lhs, FavouritePoint rhs) {
|
||||||
final Collator inst = Collator.getInstance();
|
if (sortByDist) {
|
||||||
Collections.sort(favouritePoints, new Comparator<FavouritePoint>() {
|
double ld = MapUtils.getDistance(latLon, lhs.getLatitude(),
|
||||||
@Override
|
lhs.getLongitude());
|
||||||
public int compare(FavouritePoint lhs, FavouritePoint rhs) {
|
double rd = MapUtils.getDistance(latLon, rhs.getLatitude(),
|
||||||
LatLon latLon = new LatLon(location.getLatitude(), location.getLongitude());
|
rhs.getLongitude());
|
||||||
if (sortByDist) {
|
return Double.compare(ld, rd);
|
||||||
double ld = MapUtils.getDistance(latLon, lhs.getLatitude(),
|
|
||||||
lhs.getLongitude());
|
|
||||||
double rd = MapUtils.getDistance(latLon, rhs.getLatitude(),
|
|
||||||
rhs.getLongitude());
|
|
||||||
return Double.compare(ld, rd);
|
|
||||||
}
|
|
||||||
return inst.compare(lhs.getName(), rhs.getName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
sortByDist = !sortByDist;
|
|
||||||
isSorted = true;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Void aVoid) {
|
|
||||||
super.onPostExecute(aVoid);
|
|
||||||
if (adapter != null) {
|
|
||||||
adapter.notifyDataSetChanged();
|
|
||||||
}
|
}
|
||||||
|
return inst.compare(lhs.getName(), rhs.getName());
|
||||||
}
|
}
|
||||||
}.execute();
|
});
|
||||||
|
sortByDist = !sortByDist;
|
||||||
|
isSorted = true;
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue