Search in sources :

Example 1 with MaterialMenuItem

use of de.madcyph3r.materialnavigationdrawer.menu.item.MaterialMenuItem in project AdvancedMaterialDrawer by madcyph3r.

the class MaterialNavigationDrawer method loadMenu.

// protected abstract MaterialMenu loadMenuType();
protected void loadMenu(MaterialMenu menu, boolean forceReload) {
    if (menu != null && (menu != currentMenu || forceReload)) {
        // set the new current menu
        currentMenu = menu;
        itemSections.removeAllViews();
        itemBottomSections.removeAllViews();
        // create Menu
        List<MaterialMenuItem> itemList = menu.getItems();
        for (int i = 0; i < itemList.size(); i++) {
            if (itemList.get(i) instanceof MaterialItemSection) {
                MaterialItemSection section = (MaterialItemSection) itemList.get(i);
                if (section.isBottom())
                    addBottomSection((MaterialItemSection) itemList.get(i));
                else
                    addSection((MaterialItemSection) itemList.get(i));
            } else if (itemList.get(i) instanceof MaterialItemCustom) {
                MaterialItemCustom custom = (MaterialItemCustom) itemList.get(i);
                if (custom.isBottom())
                    addBottomCustom((MaterialItemCustom) itemList.get(i));
                else
                    addCustom((MaterialItemCustom) itemList.get(i));
            } else if (itemList.get(i) instanceof MaterialItemDevisor) {
                MaterialItemDevisor devisor = (MaterialItemDevisor) itemList.get(i);
                if (devisor.isBottom())
                    addDevisorBottom();
                else
                    addDevisor();
            } else if (itemList.get(i) instanceof MaterialItemLabel) {
                MaterialItemLabel label = (MaterialItemLabel) itemList.get(i);
                if (label.isBottom())
                    addBottomLabel((MaterialItemLabel) itemList.get(i));
                else
                    addLabel((MaterialItemLabel) itemList.get(i));
            }
        }
        // unselect all items
        for (int i = 0; i < itemList.size(); i++) {
            try {
                ((MaterialItemSection) itemList.get(i)).unSelect();
            } catch (ClassCastException e) {
            // nothing to do here
            }
        }
    }
}
Also used : MaterialMenuItem(de.madcyph3r.materialnavigationdrawer.menu.item.MaterialMenuItem) MaterialItemDevisor(de.madcyph3r.materialnavigationdrawer.menu.item.style.MaterialItemDevisor) MaterialItemCustom(de.madcyph3r.materialnavigationdrawer.menu.item.custom.MaterialItemCustom) MaterialItemLabel(de.madcyph3r.materialnavigationdrawer.menu.item.style.MaterialItemLabel) SuppressLint(android.annotation.SuppressLint) MaterialItemSection(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSection)

Example 2 with MaterialMenuItem

use of de.madcyph3r.materialnavigationdrawer.menu.item.MaterialMenuItem in project AdvancedMaterialDrawer by madcyph3r.

the class MaterialNavigationDrawer method onBackPressed.

@Override
public void onBackPressed() {
    switch(backPattern) {
        default:
        case BACKPATTERN_BACK_ANYWHERE:
            super.onBackPressed();
            break;
        case BACKPATTERN_BACK_TO_START_INDEX:
            if (currentMenu.getStartIndex() > -1) {
                MaterialMenuItem menuItem = currentMenu.getItems().get(currentMenu.getStartIndex());
                if (menuItem instanceof MaterialItemSectionFragment) {
                    MaterialItemSectionFragment section = (MaterialItemSectionFragment) menuItem;
                    if (currentSectionFragment == section)
                        super.onBackPressed();
                    else {
                        //section.select();
                        onClick(section, section.getView());
                    }
                } else {
                    throw new RuntimeException("The index doesn't point on a MaterialFragmentSection.");
                }
            } else {
                throw new RuntimeException("There is no start index for this menu.");
            }
            break;
        case BACKPATTERN_CUSTOM:
            MaterialItemSection backedSection = backToSection(getCurrentSectionFragment());
            if (currentSectionFragment == backedSection)
                super.onBackPressed();
            else {
                if (!(backedSection instanceof MaterialItemSectionFragment)) {
                    throw new RuntimeException("The restored section must be a MaterialFragmentSection");
                }
                onClick(backedSection, backedSection.getView());
            }
            break;
        case BACKPATTERN_LAST_SECTION_FRAGMENT:
            int lastPos = sectionFragmentLastBackPatternList.size() - 1;
            // do not load the current fragment again
            if (sectionFragmentLastBackPatternList.size() > 0 && currentSectionFragment == sectionFragmentLastBackPatternList.get(lastPos)) {
                sectionFragmentLastBackPatternList.remove(lastPos);
                lastPos = sectionFragmentLastBackPatternList.size() - 1;
            }
            if (sectionFragmentLastBackPatternList.size() == 0) {
                super.onBackPressed();
            } else {
                MaterialItemSectionFragment sectionFragment = sectionFragmentLastBackPatternList.get(lastPos);
                onClick(sectionFragment, sectionFragment.getView());
                sectionFragmentLastBackPatternList.remove(lastPos);
            }
            break;
    }
}
Also used : MaterialMenuItem(de.madcyph3r.materialnavigationdrawer.menu.item.MaterialMenuItem) MaterialItemSectionFragment(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionFragment) MaterialItemSection(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSection) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)2 MaterialMenuItem (de.madcyph3r.materialnavigationdrawer.menu.item.MaterialMenuItem)2 MaterialItemSection (de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSection)2 MaterialItemCustom (de.madcyph3r.materialnavigationdrawer.menu.item.custom.MaterialItemCustom)1 MaterialItemSectionFragment (de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionFragment)1 MaterialItemDevisor (de.madcyph3r.materialnavigationdrawer.menu.item.style.MaterialItemDevisor)1 MaterialItemLabel (de.madcyph3r.materialnavigationdrawer.menu.item.style.MaterialItemLabel)1