Reputation: 2719
This question very specific to https://github.com/mikepenz/MaterialDrawer customization.
I need to customize my account header as follows:
I managed to get DrawerClickListener#onItemClick callback by redirecting the profile listing listener. But the header selection lost on orientation change. [I have set with saved instance state]. Also the onItemClick delivers null IDrawerItem as it is not part of Adapter.
Am I making it too complicated or PrimaryDrawerItem itself can be extended to look like profile item?
Upvotes: 1
Views: 1221
Reputation: 994
Drawer Itemclick Listener
you have to declare the method inside setupNavigation. In navigation footer items , declare
List<IDrawerItem> stockyItems = new ArrayList<>();
then write withOnDrawerItemClickListener for your button
PrimaryDrawerItem primaryDrawerItem = new PrimaryDrawerItem()
.withName("Settings")
.withIcon(R.drawable.ic_settings)
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
Intent intent = new Intent(MainActivity.this, Settings.class);
startActivity(intent);
finish();
return true;
}
});
at the end you have to pass the object
stockyItems.add(primaryDrawerItem);
Done
Upvotes: 0
Reputation: 12868
Your question is split up in multiple questions. So let me start with the first question.
- There going to be only one account at any time
If you build
your AccountHeader
you can just provide one profile. After the header was built, you can update and modify this single profile at any time, just by calling:
//create the profile
final IProfile profile = new ProfileDrawerItem().withName("Mike Penz").withEmail("[email protected]").withIcon("https://avatars3.githubusercontent.com/u/1476232?v=3&s=460").withIdentifier(100);
//build your drawer or do your logic
...
//modify the profile
profile.withName("new name");
//notify the header about the changed profile
headerResult.updateProfile(profile);
- Clicking on header (whole area) should give me DrawerClickListener#onItemClick callback
If you click somewhere in the AccountHeader
this will trigger a OnAccountHeaderSelectionViewClickListener
.withOnAccountHeaderSelectionViewClickListener(new AccountHeader.OnAccountHeaderSelectionViewClickListener() {
@Override
public boolean onClick(View view, IProfile profile) {
return false;
}
})
- Layout should be rendered like profile with extra fields
Please add some more details as the question does not seem clear.
- Loading ImageHolder to be changed to load url based images
The Sample app contains a CustomDrawerItem
which loads the icon via url: CustomUrlPrimaryDrawerItem
Upvotes: 1