-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
getPosition(SOME_ITEM_ID)
returning -1
when account switcher menu is shown
#2826
Comments
Poking at the code some more it looks like there's This is fun MaterialDrawerSliderView.getPosition(identifier: Long): Int {
return this.getPositionByIdentifier(identifier)
} and this is
The call to In practice, it appears to count the displayed items. I checked this by adding this code to an activity that contains a drawer: lifecycleScope.launch {
while(true) {
delay(5000)
Timber.w("Drawer item count: ${binding.mainDrawer.adapter.itemCount}")
}
} then checking the logs while toggling the account switcher arrow. Showing the contents of the primary item adapter this logged the item count as 28. After clicking the account switcher toggle this logged the item count as 3. 28 is consistent with the number of items in the primary adapter, and 3 is consistent with the number of items in the secondary (account) adapter (after adding 1 to account for the item in the header adapter). |
Previous code would crash if the app resumed when the account selector was open, as `getPosition` would not return the position of a primary item (see mikepenz/MaterialDrawer#2826 for details). Fix this by directly checking the primary `itemAdapter` instead of using `getPosition`.
Previous code would crash if the app resumed when the account selector was open, as `getPosition` would not return the position of a primary item (see mikepenz/MaterialDrawer#2826 for details). Fix this by directly checking the primary `itemAdapter` instead of using `getPosition`.
Good day @nikclayton The As you already highlighted the When the state is restored it will be applied respectively: https://github.com/mikepenz/MaterialDrawer/blob/develop/materialdrawer/src/main/java/com/mikepenz/materialdrawer/widget/MaterialDrawerSliderView.kt#L512-L523 |
Right. But the problem is that, when the app relaunches and the state is restored, I need to modify the primary menu items. This is because the primary menu contains items based on data from the user's server. The user may have updated these items on the server (eg., via a web app) and it's important those changes are reflected in the menu when the user resumes. I can update just the primary menu using |
I understand. Updating the items via the Practically having extension functions that solely base on the You can retrieve the info if the drawer is currently switched |
Edit: This is with version 9.0.2.
This sequence of events:
AccountHeaderView
has been attached.At this point I think the drawer reloads the saved state, which seems to include the state that the account menu is being shown instead of the regular menu.
This means calls like
slider.getPosition(SOME_ITEM_ID)
return-1
instead of the actual position ofSOME_ITEM_ID
in the main drawer.Interestingly, in the same scenario
slider.itemAdapter.getAdapterPosition(SOME_ITEM_ID)
does return a positive position (although it appears to be one less than the actual position).Not sure if this is a bug, and
slider.getPosition()
should not return-1
in this case, or if this is expected behaviour and there's some mechanism to "wait until the account switcher menu is closed, then update the main drawer items" on resume that I'm missing.The text was updated successfully, but these errors were encountered: