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();
}
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);
}
Aggregations