public void createItems ( ) { mItemAdapter . clear ( ) ; int profileOffset = 0 ; if ( mAccountHeader != null && mAccountHeader . getAccountHeaderBuilder ( ) . mProfileImagesVisible ) { IProfile profile = mAccountHeader . getActiveProfile ( ) ; if ( profile instanceof IDrawerItem ) { mItemAdapter . add ( generateMiniDrawerItem ( ( IDrawerItem ) profile ) ) ; profileOffset = 1 ; } } int select = - 1 ; if ( mDrawer != null ) { if ( getDrawerItems ( ) != null ) { //migrate to miniDrawerItems int length = getDrawerItems ( ) . size ( ) ; int position = 0 ; for ( int i = 0 ; i < length ; i ++ ) { IDrawerItem miniDrawerItem = generateMiniDrawerItem ( getDrawerItems ( ) . get ( i ) ) ; if ( miniDrawerItem != null ) { if ( miniDrawerItem . isSelected ( ) ) { select = position ; } mItemAdapter . add ( miniDrawerItem ) ; position = position + 1 ; } } if ( select >= 0 ) { //+1 because of the profile mAdapter . select ( select + profileOffset ) ; } } } //listener if ( mOnMiniDrawerItemOnClickListener != null ) { mAdapter . withOnClickListener ( mOnMiniDrawerItemOnClickListener ) ; } else { mAdapter . withOnClickListener ( new OnClickListener < IDrawerItem > ( ) { @ Override public boolean onClick ( View v , IAdapter < IDrawerItem > adapter , final IDrawerItem item , final int position ) { int type = getMiniDrawerType ( item ) ; //if a listener is defined and we consume the event return if ( mOnMiniDrawerItemClickListener != null && mOnMiniDrawerItemClickListener . onItemClick ( v , position , item , type ) ) { return false ; } if ( type == ITEM ) { //fire the onClickListener also if the specific drawerItem is not Selectable if ( item . isSelectable ( ) ) { //make sure we are on the original drawerItemList if ( mAccountHeader != null && mAccountHeader . isSelectionListShown ( ) ) { mAccountHeader . toggleSelectionList ( v . getContext ( ) ) ; } IDrawerItem drawerItem = mDrawer . getDrawerItem ( item . getIdentifier ( ) ) ; if ( drawerItem != null && ! drawerItem . isSelected ( ) ) { //set the selection mDrawer . setSelection ( item , true ) ; } } else if ( mDrawer . getOnDrawerItemClickListener ( ) != null ) { //get the original `DrawerItem` from the Drawer as this one will contain all information mDrawer . getOnDrawerItemClickListener ( ) . onItemClick ( v , position , DrawerUtils . getDrawerItem ( getDrawerItems ( ) , item . getIdentifier ( ) ) ) ; } } else if ( type == PROFILE ) { if ( mAccountHeader != null && ! mAccountHeader . isSelectionListShown ( ) ) { mAccountHeader . toggleSelectionList ( v . getContext ( ) ) ; } if ( mCrossFader != null ) { mCrossFader . crossfade ( ) ; } } return false ; } } ) ; } mAdapter . withOnLongClickListener ( mOnMiniDrawerItemLongClickListener ) ; mRecyclerView . scrollToPosition ( 0 ) ; }
creates the items for the MiniDrawer