Search in sources :

Example 1 with BottomSheetItemWithCompoundButton

use of net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton in project Osmand by osmandapp.

the class SelectWptCategoriesBottomSheetDialogFragment method createMenuItems.

@Override
public void createMenuItems(Bundle savedInstanceState) {
    gpxFile = getGpxFile();
    if (gpxFile == null) {
        return;
    }
    items.add(new TitleItem(getGpxName(gpxFile)));
    items.add(new DescriptionItem(getString(R.string.select_waypoints_category_description)));
    final BottomSheetItemWithCompoundButton[] selectAllItem = new BottomSheetItemWithCompoundButton[1];
    selectAllItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder().setChecked(true).setDescription(getString(R.string.shared_string_total) + ": " + gpxFile.getPoints().size()).setIcon(getContentIcon(R.drawable.ic_action_group_select_all)).setTitle(getString(R.string.shared_string_select_all)).setLayoutId(R.layout.bottom_sheet_item_with_descr_and_checkbox_56dp).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            boolean checked = !selectAllItem[0].isChecked();
            selectAllItem[0].setChecked(checked);
            for (BottomSheetItemWithCompoundButton item : categoryItems) {
                item.setChecked(checked);
            }
        }
    }).create();
    items.add(selectAllItem[0]);
    items.add(new DividerItem(getContext()));
    Map<String, List<WptPt>> pointsByCategories = gpxFile.getPointsByCategories();
    for (String category : pointsByCategories.keySet()) {
        final BottomSheetItemWithCompoundButton[] categoryItem = new BottomSheetItemWithCompoundButton[1];
        categoryItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder().setChecked(true).setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    selectedCategories.add((String) categoryItem[0].getTag());
                } else {
                    selectedCategories.remove((String) categoryItem[0].getTag());
                }
            }
        }).setDescription(String.valueOf(pointsByCategories.get(category).size())).setIcon(getContentIcon(R.drawable.ic_action_folder)).setTitle(category.equals("") ? getString(R.string.waypoints) : category).setLayoutId(R.layout.bottom_sheet_item_with_descr_and_checkbox_56dp).setTag(category).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                categoryItem[0].setChecked(!categoryItem[0].isChecked());
                selectAllItem[0].setChecked(isAllChecked());
            }
        }).create();
        items.add(categoryItem[0]);
        categoryItems.add(categoryItem[0]);
        selectedCategories.add(category);
    }
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) TitleItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem) View(android.view.View) ArrayList(java.util.ArrayList) List(java.util.List) DividerItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem) BottomSheetItemWithCompoundButton(net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton) BottomSheetItemWithCompoundButton(net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton) CompoundButton(android.widget.CompoundButton) DescriptionItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.DescriptionItem)

Aggregations

View (android.view.View)1 CompoundButton (android.widget.CompoundButton)1 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BottomSheetItemWithCompoundButton (net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton)1 DescriptionItem (net.osmand.plus.base.bottomsheetmenu.simpleitems.DescriptionItem)1 DividerItem (net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem)1 TitleItem (net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem)1