mikepenz / MaterialDrawer

The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.
https://mikepenz.dev
Apache License 2.0
11.67k stars 2.05k forks source link

ExpandableDrawerItem stops expanding when replaced by other #2720

Closed rckahale closed 3 years ago

rckahale commented 3 years ago

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

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

Checklist

mikepenz commented 3 years ago

@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

mikepenz commented 3 years ago

Please report if the answer helped. closing for inactivity