private void initDrawer() {
boolean isUserLoggedIn = ApplicationManager.userCredentials != null;
String studentName = "";
String codeUniversel = "";
ProfilManager profilManager = new ProfilManager(this);
Etudiant etudiant = profilManager.getEtudiant();
if (etudiant != null) {
String prenom = etudiant.prenom != null ? etudiant.prenom.trim() : "";
String nom = etudiant.nom != null ? etudiant.nom.trim() : "";
studentName = prenom + " " + nom;
codeUniversel = etudiant.codePerm != null ? etudiant.codePerm : "";
}
headerResult = new AccountHeaderBuilder()
.withActivity(this)
.withHeaderBackground(R.drawable.ets_background_grayscale)
.withSelectionListEnabledForSingleProfile(false)
.addProfiles(
new ProfileDrawerItem()
.withName(codeUniversel)
.withEmail(studentName)
.withSelectedTextColor(ContextCompat.getColor(this, R.color.red))
.withIcon(R.drawable.ic_user)
.withSelectable(isUserLoggedIn)
).withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
@Override
public boolean onProfileChanged(View view, IProfile profile, boolean current) {
goToFragment(new ProfilFragment(), ProfilFragment.class.getName());
activityDrawer.deselect();
return false;
}
}).build();
DrawerBuilder drawerBuilder = new DrawerBuilder()
.withActivity(this)
.withToolbar(toolbar)
.withAccountHeader(headerResult)
.withSelectedItem(isUserLoggedIn ? TODAY_ITEM : ABOUT_ITEM)
.withDisplayBelowStatusBar(true)
.withShowDrawerOnFirstLaunch(true)
.addDrawerItems(
new ExpandableDrawerItem().withName(R.string.menu_section_1_moi).withSelectable(false).withSubItems(
new SecondaryDrawerItem().withName(R.string.menu_section_1_profil).withIdentifier(PROFILE_ITEM).withIcon(R.drawable.ic_ico_profil).withEnabled(isUserLoggedIn),
new SecondaryDrawerItem().withName(R.string.menu_section_1_ajd).withIdentifier(TODAY_ITEM).withIcon(R.drawable.ic_ico_aujourdhui).withEnabled(isUserLoggedIn),
new SecondaryDrawerItem().withName(R.string.menu_section_1_horaire).withIdentifier(SCHEDULE_ITEM).withIcon(R.drawable.ic_ico_schedule).withEnabled(isUserLoggedIn),
new SecondaryDrawerItem().withName(R.string.menu_section_1_notes).withIdentifier(COURSE_ITEM).withIcon(R.drawable.ic_ico_notes).withEnabled(isUserLoggedIn),
new SecondaryDrawerItem().withName(R.string.menu_section_2_moodle).withIdentifier(MOODLE_ITEM).withIcon(R.drawable.ic_moodle_icon_small).withEnabled(isUserLoggedIn),
new SecondaryDrawerItem().withName(R.string.menu_section_1_monETS).withIdentifier(MONETS_ITEM).withSelectable(false).withIcon(R.drawable.ic_monets).withEnabled(isUserLoggedIn),
new SecondaryDrawerItem().withName(R.string.menu_section_1_bandwith).withIdentifier(BANDWIDTH_ITEM).withIcon(R.drawable.ic_ico_internet),
new SecondaryDrawerItem().withName(R.string.menu_section_3_beta).withIdentifier(BETA_VERSION_ITEM).withIcon(R.drawable.ic_beta_24dp)
),
new ExpandableDrawerItem().withName(R.string.menu_section_2_ets).withSelectable(false).withSubItems(
new SecondaryDrawerItem().withName(R.string.menu_section_2_news).withIdentifier(NEWS_ITEM).withIcon(R.drawable.ic_ico_news),
new SecondaryDrawerItem().withName(R.string.menu_section_2_bottin).withIdentifier(DIRECTORY_ITEM).withIcon(R.drawable.ic_ico_bottin),
new SecondaryDrawerItem().withName(R.string.menu_section_2_biblio).withIdentifier(LIBRARY_ITEM).withSelectable(false).withIcon(R.drawable.ic_ico_library),
new SecondaryDrawerItem().withName(R.string.menu_section_2_securite).withIdentifier(SECURITY_ITEM).withIcon(R.drawable.ic_ico_security)
),
new ExpandableDrawerItem().withName(R.string.menu_section_3_applets).withSelectable(false).withSubItems(
new SecondaryDrawerItem().withName(R.string.menu_section_3_apps).withIdentifier(ACHIEVEMENTS_ITEM).withIcon(R.drawable.ic_star_60x60),
new SecondaryDrawerItem().withName(R.string.menu_section_3_about).withIdentifier(ABOUT_ITEM).withIcon(R.drawable.ic_logo_icon_final),
new SecondaryDrawerItem().withName(R.string.menu_section_3_faq).withIdentifier(FAQ_ITEM).withIcon(R.drawable.ic_ico_faq)
)
);
if (isUserLoggedIn)
drawerBuilder.addStickyDrawerItems(new SecondaryDrawerItem().withName(R.string.action_logout).withIdentifier(LOGOUT).withTextColorRes(R.color.red));
else
drawerBuilder.addStickyDrawerItems(new SecondaryDrawerItem().withName(R.string.action_login).withIdentifier(LOGIN));
drawerBuilder.withOnDrawerItemClickListener(drawerItemClickListener);
activityDrawer = drawerBuilder.build();
activityDrawer.getExpandableExtension().expand(1);
}