use of net.osmand.plus.base.bottomsheetmenu.BottomSheetItemTitleWithDescrAndButton in project Osmand by osmandapp.
the class FavouritesBottomSheetMenuFragment method createMenuItems.
@Override
public void createMenuItems(final Bundle savedInstanceState) {
Bundle args = getArguments();
if (args != null) {
target = args.getBoolean(TARGET);
intermediate = args.getBoolean(INTERMEDIATE);
}
if (savedInstanceState != null && savedInstanceState.getBoolean(IS_SORTED)) {
sortByDist = savedInstanceState.getBoolean(SORTED_BY_TYPE);
}
favouritePoints = getMyApplication().getFavorites().getVisibleFavouritePoints();
recyclerView = new RecyclerView(getContext());
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
recyclerView = (RecyclerView) View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.recyclerview, null);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
location = getMyApplication().getLocationProvider().getLastKnownLocation();
if (location != null) {
latLon = new LatLon(location.getLatitude(), location.getLongitude());
}
adapter = new FavouritesAdapter(getContext(), favouritePoints);
sortFavourites();
final BottomSheetItemTitleWithDescrAndButton[] title = new BottomSheetItemTitleWithDescrAndButton[1];
title[0] = (BottomSheetItemTitleWithDescrAndButton) new BottomSheetItemTitleWithDescrAndButton.Builder().setButtonIcons(null, getIconForButton()).setButtonTitle(getTextForButton(sortByDist)).setonButtonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sortFavourites();
title[0].setButtonIcons(null, getIconForButton());
title[0].setButtonText(getTextForButton(sortByDist));
title[0].setDescription(getTextForButton(!sortByDist));
}
}).setDescription(getTextForButton(!sortByDist)).setTitle(getString(R.string.favourites)).setLayoutId(R.layout.bottom_sheet_item_title_with_descr_and_button).create();
items.add(title[0]);
adapter.setItemClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int position = recyclerView.getChildAdapterPosition(v);
if (position == RecyclerView.NO_POSITION) {
return;
}
selectFavorite(favouritePoints.get(position));
}
});
recyclerView.setAdapter(adapter);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
compassUpdateAllowed = newState == RecyclerView.SCROLL_STATE_IDLE;
}
});
items.add(new BaseBottomSheetItem.Builder().setCustomView(recyclerView).create());
}
Aggregations