I have an app where you can log in, so I want to display different drawer menu options based on if you did so. Untill now I've been trying and I was able to remove items when the user is not logged. However I'm struggling to recover those removed items once log in is performed. Here is the condition where I do this:
navController.addOnDestinationChangedListener { _, destination, _ ->
if (destination.id == R.id.firstFragment ||
destination.id == R.id.loginFragment ||
destination.id == R.id.registerFragment
) {
//drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
navView.menu.removeItem(R.id.firstFragment) //This works
} else {
//drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED)
navView.menu.add(R.id.firstFragment) //This doesn't work
}
}