Search in sources :

Example 1 with BottomSheetItemTitleWithDescrAndButton

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());
}
Also used : BottomSheetItemTitleWithDescrAndButton(net.osmand.plus.base.bottomsheetmenu.BottomSheetItemTitleWithDescrAndButton) BaseBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem) Bundle(android.os.Bundle) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) FavouritePoint(net.osmand.data.FavouritePoint) LatLon(net.osmand.data.LatLon) ContextThemeWrapper(android.view.ContextThemeWrapper) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

Bundle (android.os.Bundle)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 ContextThemeWrapper (android.view.ContextThemeWrapper)1 View (android.view.View)1 FavouritePoint (net.osmand.data.FavouritePoint)1 LatLon (net.osmand.data.LatLon)1 BaseBottomSheetItem (net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem)1 BottomSheetItemTitleWithDescrAndButton (net.osmand.plus.base.bottomsheetmenu.BottomSheetItemTitleWithDescrAndButton)1