Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sub item doesn't deselect if the list was collapsed when new click performed #2184

Closed
ghost opened this issue Jan 23, 2018 · 3 comments
Closed

Comments

@ghost
Copy link

ghost commented Jan 23, 2018

If the sub item was selected, and then we collapse the list and click on the other main item, both items will be selected (the new one and the old sub item)

How to reproduce (sample app):

  1. Open navigation drawer
  2. Expand "Collapsable Badge", select the first item - "CollapsableItem"
  3. Collapse the list by clicking on "Collapsable Badge"
  4. Click on "Contract"
  5. Expand "Collapsable Badge"
  6. Both "CollapsableItem" and "Contract" item will be selected

My temporary workaround - I deselect all sub items when the click was performed on the main items:

             .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                    @Override
                    public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                        if (nonNull(drawerItem) && drawerItem instanceof AbstractBadgeableDrawerItem) {
                            long clickedIdentifier = drawerItem.getIdentifier();
                            if (!isSubItem(clickedIdentifier)) {
                                deselectAllSubItems();
                            }
                            (...)
                        }
                        return false;
                    }

   private void deselectAllSubItems() {
        List<IDrawerItem> drawerItems = drawerResult.getDrawerItems();
        for (IDrawerItem drawerItem : drawerItems) {
            if (drawerItem instanceof ExpandableDrawerItem) {
                ExpandableDrawerItem expandableDrawerItem = (ExpandableDrawerItem) drawerItem;
                List<IDrawerItem> subItems = expandableDrawerItem.getSubItems();
                if (nonNull(subItems)) {
                    for (IDrawerItem subItem : subItems) {
                        subItem.withSetSelected(false);
                    }
                }
            }
        }
    }

   private boolean isSubItem(long itemId) {
        List<IDrawerItem> drawerItems = drawerResult.getDrawerItems();
        for (IDrawerItem drawerItem : drawerItems) {
            if (drawerItem instanceof ExpandableDrawerItem) {
                ExpandableDrawerItem expandableDrawerItem = (ExpandableDrawerItem) drawerItem;
                List<IDrawerItem> subItems = expandableDrawerItem.getSubItems();
                if (nonNull(subItems)) {
                    for (IDrawerItem subItem : subItems) {
                        if (subItem.getIdentifier() == itemId)
                            return true;
                    }
                }
            }
        }
        return false;
    }
@ghost ghost changed the title Sub item doesn't deselect if the list was collapsed Sub item doesn't deselect if the list was collapsed when new click performed Jan 23, 2018
@mikepenz
Copy link
Owner

@masterleclerc there will be some enhancements in the next update (via a new FastAdapter version) to expandables. Please stay tuned ;)

@mikepenz
Copy link
Owner

Should be solved in the latest release v6.0.3 with the latest FastAdapter 3.2.1

@ghost
Copy link
Author

ghost commented Jan 31, 2018

I can still reproduce the problem in v6.0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant