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);
}
}
Aggregations