Search in sources :

Example 36 with IDrawerItem

use of com.mikepenz.materialdrawer.model.interfaces.IDrawerItem in project Tusky by tuskyapp.

the class MainActivity method setupDrawer.

private void setupDrawer() {
    headerResult = new AccountHeaderBuilder().withActivity(this).withDividerBelowHeader(false).withHeaderBackgroundScaleType(ImageView.ScaleType.CENTER_CROP).withCurrentProfileHiddenInList(true).withOnAccountHeaderListener((view, profile, current) -> handleProfileClick(profile, current)).addProfiles(new ProfileSettingDrawerItem().withIdentifier(DRAWER_ITEM_ADD_ACCOUNT).withName(R.string.add_account_name).withDescription(R.string.add_account_description).withIcon(GoogleMaterial.Icon.gmd_add)).build();
    headerResult.getView().findViewById(R.id.material_drawer_account_header_current).setContentDescription(getString(R.string.action_view_profile));
    ImageView background = headerResult.getHeaderBackgroundView();
    background.setColorFilter(ContextCompat.getColor(this, R.color.header_background_filter));
    background.setBackgroundColor(ContextCompat.getColor(this, R.color.window_background_dark));
    DrawerImageLoader.init(new AbstractDrawerImageLoader() {

        @Override
        public void set(ImageView imageView, Uri uri, Drawable placeholder, String tag) {
            Picasso.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView);
        }

        @Override
        public void cancel(ImageView imageView) {
            Picasso.with(imageView.getContext()).cancelRequest(imageView);
        }
    });
    VectorDrawableCompat muteDrawable = VectorDrawableCompat.create(getResources(), R.drawable.ic_mute_24dp, getTheme());
    ThemeUtils.setDrawableTint(this, muteDrawable, R.attr.toolbar_icon_tint);
    List<IDrawerItem> listItem = new ArrayList<>();
    listItem.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_EDIT_PROFILE).withName(getString(R.string.action_edit_profile)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_person));
    listItem.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_FAVOURITES).withName(getString(R.string.action_view_favourites)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_star));
    listItem.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_LISTS).withName(R.string.action_lists).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_list));
    listItem.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_MUTED_USERS).withName(getString(R.string.action_view_mutes)).withSelectable(false).withIcon(muteDrawable));
    listItem.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_BLOCKED_USERS).withName(getString(R.string.action_view_blocks)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_block));
    listItem.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_SEARCH).withName(getString(R.string.action_search)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_search));
    listItem.add(new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_SAVED_TOOT).withName(getString(R.string.action_access_saved_toot)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_save));
    listItem.add(new DividerDrawerItem());
    listItem.add(new SecondaryDrawerItem().withIdentifier(DRAWER_ITEM_PREFERENCES).withName(getString(R.string.action_view_preferences)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_settings));
    listItem.add(new SecondaryDrawerItem().withIdentifier(DRAWER_ITEM_ABOUT).withName(getString(R.string.about_title_activity)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_info));
    listItem.add(new SecondaryDrawerItem().withIdentifier(DRAWER_ITEM_LOG_OUT).withName(getString(R.string.action_logout)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_exit_to_app));
    IDrawerItem[] array = new IDrawerItem[listItem.size()];
    // fill the array
    listItem.toArray(array);
    drawer = new DrawerBuilder().withActivity(this).withAccountHeader(headerResult).withHasStableIds(true).withSelectedItem(-1).addDrawerItems(array).withOnDrawerItemClickListener((view, position, drawerItem) -> {
        if (drawerItem != null) {
            long drawerItemIdentifier = drawerItem.getIdentifier();
            if (drawerItemIdentifier == DRAWER_ITEM_EDIT_PROFILE) {
                Intent intent = new Intent(MainActivity.this, EditProfileActivity.class);
                startActivity(intent);
            } else if (drawerItemIdentifier == DRAWER_ITEM_FAVOURITES) {
                Intent intent = new Intent(MainActivity.this, FavouritesActivity.class);
                startActivity(intent);
            } else if (drawerItemIdentifier == DRAWER_ITEM_MUTED_USERS) {
                Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
                intent.putExtra("type", AccountListActivity.Type.MUTES);
                startActivity(intent);
            } else if (drawerItemIdentifier == DRAWER_ITEM_BLOCKED_USERS) {
                Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
                intent.putExtra("type", AccountListActivity.Type.BLOCKS);
                startActivity(intent);
            } else if (drawerItemIdentifier == DRAWER_ITEM_SEARCH) {
                Intent intent = new Intent(MainActivity.this, SearchActivity.class);
                startActivity(intent);
            } else if (drawerItemIdentifier == DRAWER_ITEM_PREFERENCES) {
                Intent intent = new Intent(MainActivity.this, PreferencesActivity.class);
                startActivity(intent);
            } else if (drawerItemIdentifier == DRAWER_ITEM_ABOUT) {
                Intent intent = new Intent(MainActivity.this, AboutActivity.class);
                startActivity(intent);
            } else if (drawerItemIdentifier == DRAWER_ITEM_LOG_OUT) {
                logout();
            } else if (drawerItemIdentifier == DRAWER_ITEM_FOLLOW_REQUESTS) {
                Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
                intent.putExtra("type", AccountListActivity.Type.FOLLOW_REQUESTS);
                startActivity(intent);
            } else if (drawerItemIdentifier == DRAWER_ITEM_SAVED_TOOT) {
                Intent intent = new Intent(MainActivity.this, SavedTootActivity.class);
                startActivity(intent);
            } else if (drawerItemIdentifier == DRAWER_ITEM_LISTS) {
                startActivity(ListsActivity.newIntent(this));
            }
        }
        return false;
    }).build();
    if (BuildConfig.DEBUG) {
        IDrawerItem debugItem = new SecondaryDrawerItem().withIdentifier(1337).withName("debug").withDisabledTextColor(Color.GREEN).withSelectable(false).withEnabled(false);
        drawer.addItem(debugItem);
    }
    updateProfiles();
}
Also used : ImageButton(android.widget.ImageButton) Bundle(android.os.Bundle) Uri(android.net.Uri) ImageView(android.widget.ImageView) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) Drawable(android.graphics.drawable.Drawable) DrawerImageLoader(com.mikepenz.materialdrawer.util.DrawerImageLoader) Picasso(com.squareup.picasso.Picasso) ActionButtonActivity(com.keylesspalace.tusky.interfaces.ActionButtonActivity) Account(com.keylesspalace.tusky.entity.Account) ProfileSettingDrawerItem(com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem) DispatchingAndroidInjector(dagger.android.DispatchingAndroidInjector) NotificationHelper(com.keylesspalace.tusky.util.NotificationHelper) Log(android.util.Log) FloatingActionButton(android.support.design.widget.FloatingActionButton) AndroidInjector(dagger.android.AndroidInjector) AccountHeader(com.mikepenz.materialdrawer.AccountHeader) Fragment(android.support.v4.app.Fragment) ContextCompat(android.support.v4.content.ContextCompat) PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) GoogleMaterial(com.mikepenz.google_material_typeface_library.GoogleMaterial) List(java.util.List) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) Nullable(android.support.annotation.Nullable) HasSupportFragmentInjector(dagger.android.support.HasSupportFragmentInjector) Call(retrofit2.Call) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) KeyEvent(android.view.KeyEvent) VectorDrawableCompat(android.support.graphics.drawable.VectorDrawableCompat) ViewPager(android.support.v4.view.ViewPager) Intent(android.content.Intent) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) NonNull(android.support.annotation.NonNull) IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) Response(retrofit2.Response) ArrayList(java.util.ArrayList) TabLayout(android.support.design.widget.TabLayout) Inject(javax.inject.Inject) Drawer(com.mikepenz.materialdrawer.Drawer) ThemeUtils(com.keylesspalace.tusky.util.ThemeUtils) ProfileDrawerItem(com.mikepenz.materialdrawer.model.ProfileDrawerItem) TimelinePagerAdapter(com.keylesspalace.tusky.pager.TimelinePagerAdapter) TimelineReceiver(com.keylesspalace.tusky.receiver.TimelineReceiver) Color(android.graphics.Color) AbstractDrawerImageLoader(com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) Callback(retrofit2.Callback) Configuration(android.content.res.Configuration) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) MastodonApi(com.keylesspalace.tusky.network.MastodonApi) AccountManager(com.keylesspalace.tusky.db.AccountManager) DividerDrawerItem(com.mikepenz.materialdrawer.model.DividerDrawerItem) AbstractDrawerImageLoader(com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader) IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) DividerDrawerItem(com.mikepenz.materialdrawer.model.DividerDrawerItem) ProfileSettingDrawerItem(com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem) Drawable(android.graphics.drawable.Drawable) ArrayList(java.util.ArrayList) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) Intent(android.content.Intent) Uri(android.net.Uri) VectorDrawableCompat(android.support.graphics.drawable.VectorDrawableCompat) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) ImageView(android.widget.ImageView) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder)

Example 37 with IDrawerItem

use of com.mikepenz.materialdrawer.model.interfaces.IDrawerItem in project Roblu by wdavies973.

the class EventDrawerManager method loadEventsToDrawer.

/**
 * Loads events from the file system into the event drawer.
 * Note: loadEvents() must be called after the drawer UI is setup, it will insert
 * REvents into the pre-created UI drawer
 */
public void loadEventsToDrawer() {
    /*
         * Load events
         */
    // Delete the preview event, if necessary
    new IO(activity).deleteEvent(-1);
    REvent[] loaded = new IO(activity).loadEvents();
    if (loaded == null) {
        if (((AppCompatActivity) activity).getSupportActionBar() != null)
            ((AppCompatActivity) activity).getSupportActionBar().setSubtitle("No events");
        return;
    }
    // Set loaded events to the managed array-list
    events = new ArrayList<>(Arrays.asList(loaded));
    // Sort descending by event ID, most recently created event will appear first
    Collections.sort(events);
    Collections.reverse(events);
    // Load icons
    Drawable folder, scout, options, pit;
    folder = ContextCompat.getDrawable(activity, R.drawable.event);
    scout = ContextCompat.getDrawable(activity, R.drawable.match);
    options = ContextCompat.getDrawable(activity, R.drawable.settings_circle);
    pit = ContextCompat.getDrawable(activity, R.drawable.pit);
    // Set UI preferences to drawable icon
    folder.mutate();
    folder.setColorFilter(rui.getText(), PorterDuff.Mode.SRC_IN);
    scout.mutate();
    scout.setColorFilter(rui.getText(), PorterDuff.Mode.SRC_IN);
    options.mutate();
    options.setColorFilter(rui.getText(), PorterDuff.Mode.SRC_IN);
    pit.mutate();
    pit.setColorFilter(rui.getText(), PorterDuff.Mode.SRC_IN);
    // Specify the list of items that have to be added to the drawer
    ArrayList<IDrawerItem> items = new ArrayList<>();
    if (events != null)
        for (REvent e : events) {
            items.add(new ExpandableDrawerItem().withTextColor(rui.getText()).withName(e.getName()).withTag(e.getID()).withArrowColor(rui.getText()).withIcon(folder).withIdentifier(Constants.HEADER).withSelectable(false).withSubItems(new SecondaryDrawerItem().withTextColor(rui.getText()).withName("Scout").withLevel(2).withIcon(scout).withIdentifier(Constants.SCOUT).withTag(e.getID()), new SecondaryDrawerItem().withTextColor(rui.getText()).withName("My matches").withLevel(2).withIcon(pit).withIdentifier(Constants.MY_MATCHES).withTag(e.getID()), new SecondaryDrawerItem().withTextColor(rui.getText()).withName("Picks").withLevel(2).withIcon(scout).withIdentifier(Constants.PICKS).withTag(e.getID()), new SecondaryDrawerItem().withTextColor(rui.getText()).withName("Settings").withLevel(2).withIcon(options).withIdentifier(Constants.EVENT_SETTINGS).withTag(e.getID())));
        }
    // Clear old events from the drawer
    for (int i = 0; i < eventDrawer.getDrawerItems().size(); i++) {
        long identifier = eventDrawer.getDrawerItems().get(i).getIdentifier();
        if (identifier == Constants.HEADER || identifier == Constants.SCOUT || identifier == Constants.EVENT_SETTINGS || identifier == Constants.MY_MATCHES || identifier == Constants.PICKS) {
            eventDrawer.removeItemByPosition(i);
            i = 0;
        }
    }
    // Set defined list of items to drawer UI
    for (int i = 0; i < items.size(); i++) eventDrawer.addItemAtPosition(items.get(i), i + 3);
}
Also used : IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) IO(com.cpjd.roblu.io.IO) AppCompatActivity(android.support.v7.app.AppCompatActivity) Drawable(android.graphics.drawable.Drawable) ArrayList(java.util.ArrayList) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) REvent(com.cpjd.roblu.models.REvent) ExpandableDrawerItem(com.mikepenz.materialdrawer.model.ExpandableDrawerItem)

Aggregations

IDrawerItem (com.mikepenz.materialdrawer.model.interfaces.IDrawerItem)37 View (android.view.View)25 DrawerBuilder (com.mikepenz.materialdrawer.DrawerBuilder)21 PrimaryDrawerItem (com.mikepenz.materialdrawer.model.PrimaryDrawerItem)19 Drawer (com.mikepenz.materialdrawer.Drawer)17 SecondaryDrawerItem (com.mikepenz.materialdrawer.model.SecondaryDrawerItem)15 Toolbar (android.support.v7.widget.Toolbar)14 IProfile (com.mikepenz.materialdrawer.model.interfaces.IProfile)12 AccountHeaderBuilder (com.mikepenz.materialdrawer.AccountHeaderBuilder)11 Nameable (com.mikepenz.materialdrawer.model.interfaces.Nameable)11 DividerDrawerItem (com.mikepenz.materialdrawer.model.DividerDrawerItem)10 Intent (android.content.Intent)9 ProfileDrawerItem (com.mikepenz.materialdrawer.model.ProfileDrawerItem)8 BadgeStyle (com.mikepenz.materialdrawer.holder.BadgeStyle)6 ProfileSettingDrawerItem (com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem)6 SectionDrawerItem (com.mikepenz.materialdrawer.model.SectionDrawerItem)6 LibsBuilder (com.mikepenz.aboutlibraries.LibsBuilder)5 IconicsDrawable (com.mikepenz.iconics.IconicsDrawable)5 ArrayList (java.util.ArrayList)5 RecyclerView (android.support.v7.widget.RecyclerView)4