Search in sources :

Example 1 with ProfilManager

use of ca.etsmtl.applets.etsmobile.util.ProfilManager in project ETSMobile-Android2 by ApplETS.

the class ApplicationManager method deconnexion.

public static void deconnexion(final Activity activity) {
    final Editor editor = PreferenceManager.getDefaultSharedPreferences(activity).edit();
    editor.clear();
    editor.commit();
    // Enlever le profil de la DB SQLite
    new ProfilManager(activity).removeProfil();
    new NoteManager(activity).remove();
    AccountManager accountManager = AccountManager.get(activity);
    Account[] accounts = accountManager.getAccountsByType(Constants.ACCOUNT_TYPE);
    for (int index = 0; index < accounts.length; index++) {
        accountManager.removeAccount(accounts[index], null, null);
    }
    ApplicationManager.userCredentials = null;
    Intent intent = new Intent(activity, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    activity.startActivity(intent);
    new Thread(new Runnable() {

        @Override
        public void run() {
            activity.finish();
        }
    }).start();
}
Also used : Account(android.accounts.Account) NoteManager(ca.etsmtl.applets.etsmobile.util.NoteManager) AccountManager(android.accounts.AccountManager) Intent(android.content.Intent) Editor(android.content.SharedPreferences.Editor) ProfilManager(ca.etsmtl.applets.etsmobile.util.ProfilManager)

Example 2 with ProfilManager

use of ca.etsmtl.applets.etsmobile.util.ProfilManager in project ETSMobile-Android2 by ApplETS.

the class ProfilFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup v = (ViewGroup) inflater.inflate(R.layout.fragment_profil, container, false);
    super.onCreateView(inflater, v, savedInstanceState);
    ((MainActivity) getActivity()).setTitle(getFragmentTitle());
    loadingView.showLoadingView();
    dataManager.getDataFromSignet(SignetMethods.INFO_ETUDIANT, ApplicationManager.userCredentials, this, "");
    dataManager.getDataFromSignet(SignetMethods.LIST_PROGRAM, ApplicationManager.userCredentials, this, "");
    listViewProfile = (ListView) v.findViewById(R.id.listview_profile);
    listViewProfile.setAdapter(profileAdapter);
    profilManager = new ProfilManager(getActivity());
    AnalyticsHelper.getInstance(getActivity()).sendScreenEvent(getClass().getSimpleName());
    return v;
}
Also used : ViewGroup(android.view.ViewGroup) MainActivity(ca.etsmtl.applets.etsmobile.ui.activity.MainActivity) ProfilManager(ca.etsmtl.applets.etsmobile.util.ProfilManager)

Example 3 with ProfilManager

use of ca.etsmtl.applets.etsmobile.util.ProfilManager in project ETSMobile-Android2 by ApplETS.

the class MainActivity method initDrawer.

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());
            return false;
        }
    }).build();
    DrawerBuilder drawerBuilder = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withAccountHeader(headerResult).withSelectedItem(isUserLoggedIn ? TODAY_FRAGMENT : ABOUT_FRAGMENT).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_ajd).withIdentifier(TODAY_FRAGMENT).withIcon(R.drawable.ic_ico_aujourdhui).withEnabled(isUserLoggedIn), new SecondaryDrawerItem().withName(R.string.menu_section_1_horaire).withIdentifier(SCHEDULE_FRAGMENT).withIcon(R.drawable.ic_ico_schedule).withEnabled(isUserLoggedIn), new SecondaryDrawerItem().withName(R.string.menu_section_1_notes).withIdentifier(COURSE_FRAGMENT).withIcon(R.drawable.ic_ico_notes).withEnabled(isUserLoggedIn), new SecondaryDrawerItem().withName(R.string.menu_section_2_moodle).withIdentifier(MOODLE_FRAGMENT).withIcon(R.drawable.ic_moodle_icon_small).withEnabled(isUserLoggedIn), new SecondaryDrawerItem().withName(R.string.menu_section_1_monETS).withIdentifier(MONETS_FRAGMENT).withIcon(R.drawable.ic_monets).withEnabled(isUserLoggedIn), new SecondaryDrawerItem().withName(R.string.menu_section_1_bandwith).withIdentifier(BANDWIDTH_FRAGMENT).withIcon(R.drawable.ic_ico_internet)).withIsExpanded(true), new ExpandableDrawerItem().withName(R.string.menu_section_2_ets).withSelectable(false).withSubItems(new SecondaryDrawerItem().withName(R.string.menu_section_2_news).withIdentifier(NEWS_FRAGMENT).withIcon(R.drawable.ic_ico_news), new SecondaryDrawerItem().withName(R.string.menu_section_2_events).withIdentifier(EVENTS_FRAGMENT).withIcon(R.drawable.ic_event_available), new SecondaryDrawerItem().withName(R.string.menu_section_2_bottin).withIdentifier(DIRECTORY_FRAGMENT).withIcon(R.drawable.ic_ico_bottin), new SecondaryDrawerItem().withName(R.string.menu_section_2_biblio).withIdentifier(LIBRARY_FRAGMENT).withIcon(R.drawable.ic_ico_library), new SecondaryDrawerItem().withName(R.string.menu_section_2_securite).withIdentifier(SECURITY_FRAGMENT).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_FRAGMENT).withIcon(R.drawable.ic_star_60x60), new SecondaryDrawerItem().withName(R.string.menu_section_3_about).withIdentifier(ABOUT_FRAGMENT).withIcon(R.drawable.ic_logo_icon_final), new SecondaryDrawerItem().withName(R.string.menu_section_3_comms).withIdentifier(COMMENTS_FRAGMENT).withIcon(R.drawable.ic_ico_comment), new SecondaryDrawerItem().withName(R.string.menu_section_3_sponsors).withIdentifier(SPONSOR_FRAGMENT).withIcon(R.drawable.ic_ico_partners), new SecondaryDrawerItem().withName(R.string.menu_section_3_faq).withIdentifier(FAQ_FRAGMENT).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);
    drawerBuilder.build();
}
Also used : Etudiant(ca.etsmtl.applets.etsmobile.model.Etudiant) ProfilFragment(ca.etsmtl.applets.etsmobile.ui.fragment.ProfilFragment) ProfileDrawerItem(com.mikepenz.materialdrawer.model.ProfileDrawerItem) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) View(android.view.View) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) AccountHeader(com.mikepenz.materialdrawer.AccountHeader) ExpandableDrawerItem(com.mikepenz.materialdrawer.model.ExpandableDrawerItem) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) ProfilManager(ca.etsmtl.applets.etsmobile.util.ProfilManager)

Aggregations

ProfilManager (ca.etsmtl.applets.etsmobile.util.ProfilManager)3 Account (android.accounts.Account)1 AccountManager (android.accounts.AccountManager)1 Intent (android.content.Intent)1 Editor (android.content.SharedPreferences.Editor)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 Etudiant (ca.etsmtl.applets.etsmobile.model.Etudiant)1 MainActivity (ca.etsmtl.applets.etsmobile.ui.activity.MainActivity)1 ProfilFragment (ca.etsmtl.applets.etsmobile.ui.fragment.ProfilFragment)1 NoteManager (ca.etsmtl.applets.etsmobile.util.NoteManager)1 AccountHeader (com.mikepenz.materialdrawer.AccountHeader)1 AccountHeaderBuilder (com.mikepenz.materialdrawer.AccountHeaderBuilder)1 DrawerBuilder (com.mikepenz.materialdrawer.DrawerBuilder)1 ExpandableDrawerItem (com.mikepenz.materialdrawer.model.ExpandableDrawerItem)1 ProfileDrawerItem (com.mikepenz.materialdrawer.model.ProfileDrawerItem)1 SecondaryDrawerItem (com.mikepenz.materialdrawer.model.SecondaryDrawerItem)1 IProfile (com.mikepenz.materialdrawer.model.interfaces.IProfile)1