mikepenz/MaterialDrawer

ExpandableDrawerItem stops expanding when replaced by other

rckahale opened this issue · 2 comments

Firstly ...Very useful and feature rich library. Thanks for making it.

  • Briefly describe the issue
    I am facing an issue while toggling the [ExpandableDrawerItem1(id:55), SecondaryDrawerItem1(id:501)...Group1] items combination with another [ExpandableDrawerItem2(id:66), SecondaryDrawerItem2(id:601)...Group2] combination. The toggling happens from the OnCheckedChangeListener of SwitchDrawerItem.

  • How can the issue be reproduced / sample code

Currently I am using

MaterialDrawerSliderView?.itemAdapter?.removeByIdentifier(55)
MaterialDrawerSliderView?.itemAdapter?.removeByIdentifier(501) 
MaterialDrawerSliderView?.itemAdapter?.add(1, Group2)

and vice versa for other toggle state

which works, with the following exceptions.


SwitchDrawerItem!!.withOnCheckedChangeListener(object: OnCheckedChangeListener {
            override fun onCheckedChanged(
                drawerItem: IDrawerItem<*>,
                buttonView: CompoundButton,
                isChecked: Boolean
            ) {
				// var slider: MaterialDrawerSliderView? = null
					if (isChecked) {
						slider?.itemAdapter?.removeByIdentifier(66)
						slider?.itemAdapter?.removeByIdentifier(601) 
						slider?.itemAdapter?.add(1, Group1)   // Group1 = ExpandableDrawerItem
					
					} else {
						slider?.itemAdapter?.removeByIdentifier(55)
						slider?.itemAdapter?.removeByIdentifier(501) 
						slider?.itemAdapter?.add(1, Group2)   // Group2 = ExpandableDrawerItem
					
					}
 					
					slider?.adapter?.notifyDataSetChanged()
            }
        })

If I toggle by keeping ExpandableDrawerItem in expanded state, it does not work more than 1 or 2 set of times. Later it doesn't even expand...simply closes the drawer. I guess, this is because the isExpanded boolean flags have reached some inconsistent state.
For ExpandableDrawerItem in closed state, it does not cause this issue.

I suppose, assigning new IDs on every toggle may be a fix, but it would be very tedious to attach the listeners and do subsequent operations.

Do tell me if there is a better way to achieve this.

Details

  • [ 8.4.0] Used library version of MaterialDrawer
  • [3.6.1] Used gradle build tools version
  • [3.6] Android Studio version

Checklist

@rckahale sorry for the late answer.

If you try it in the sample pap can you reproduce the issue?

the removeByIdentifier is a function of the FastAdapter and less specific of the MaterialDrawer

Please report if the answer helped. closing for inactivity