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,16 +223,15 @@ 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) {
|
||||||
@Override
|
return;
|
||||||
protected Void doInBackground(Void... voids) {
|
}
|
||||||
final Collator inst = Collator.getInstance();
|
final Collator inst = Collator.getInstance();
|
||||||
|
final LatLon latLon = new LatLon(location.getLatitude(), location.getLongitude());
|
||||||
Collections.sort(favouritePoints, new Comparator<FavouritePoint>() {
|
Collections.sort(favouritePoints, new Comparator<FavouritePoint>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(FavouritePoint lhs, FavouritePoint rhs) {
|
public int compare(FavouritePoint lhs, FavouritePoint rhs) {
|
||||||
LatLon latLon = new LatLon(location.getLatitude(), location.getLongitude());
|
|
||||||
if (sortByDist) {
|
if (sortByDist) {
|
||||||
double ld = MapUtils.getDistance(latLon, lhs.getLatitude(),
|
double ld = MapUtils.getDistance(latLon, lhs.getLatitude(),
|
||||||
lhs.getLongitude());
|
lhs.getLongitude());
|
||||||
|
@ -249,16 +244,6 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
|
||||||
});
|
});
|
||||||
sortByDist = !sortByDist;
|
sortByDist = !sortByDist;
|
||||||
isSorted = true;
|
isSorted = true;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Void aVoid) {
|
|
||||||
super.onPostExecute(aVoid);
|
|
||||||
if (adapter != null) {
|
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}.execute();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue