Instantly share code, notes, and snippets.
Last active
August 22, 2016 14:58
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save janishar/d212b6a72161ef001c8d4d6945de68d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Layout(R.layout.drawer_item) | |
public class DrawerMenuItem { | |
public static final int DRAWER_MENU_ITEM_PROFILE = 1; | |
public static final int DRAWER_MENU_ITEM_REQUESTS = 2; | |
public static final int DRAWER_MENU_ITEM_GROUPS = 3; | |
public static final int DRAWER_MENU_ITEM_MESSAGE = 4; | |
public static final int DRAWER_MENU_ITEM_NOTIFICATIONS = 5; | |
public static final int DRAWER_MENU_ITEM_SETTINGS = 6; | |
public static final int DRAWER_MENU_ITEM_TERMS = 7; | |
public static final int DRAWER_MENU_ITEM_LOGOUT = 8; | |
private int mMenuPosition; | |
private Context mContext; | |
private DrawerCallBack mCallBack; | |
@View(R.id.itemNameTxt) | |
private TextView itemNameTxt; | |
@View(R.id.itemIcon) | |
private ImageView itemIcon; | |
public DrawerMenuItem(Context context, int menuPosition) { | |
mContext = context; | |
mMenuPosition = menuPosition; | |
} | |
@Resolve | |
private void onResolved() { | |
switch (mMenuPosition){ | |
case DRAWER_MENU_ITEM_PROFILE: | |
itemNameTxt.setText("Profile"); | |
itemIcon.setImageDrawable(mContext.getResources().getDrawable(R.drawable.ic_account_circle_black_18dp)); | |
break; | |
case DRAWER_MENU_ITEM_REQUESTS: | |
itemNameTxt.setText("Requests"); | |
itemIcon.setImageDrawable(mContext.getResources().getDrawable(R.drawable.ic_compare_arrows_black_18dp)); | |
break; | |
case DRAWER_MENU_ITEM_GROUPS: | |
itemNameTxt.setText("Groups"); | |
itemIcon.setImageDrawable(mContext.getResources().getDrawable(R.drawable.ic_group_work_black_18dp)); | |
break; | |
case DRAWER_MENU_ITEM_MESSAGE: | |
itemNameTxt.setText("Messages"); | |
itemIcon.setImageDrawable(mContext.getResources().getDrawable(R.drawable.ic_email_black_18dp)); | |
break; | |
case DRAWER_MENU_ITEM_NOTIFICATIONS: | |
itemNameTxt.setText("Notifications"); | |
itemIcon.setImageDrawable(mContext.getResources().getDrawable(R.drawable.ic_notifications_black_18dp)); | |
break; | |
case DRAWER_MENU_ITEM_SETTINGS: | |
itemNameTxt.setText("Settings"); | |
itemIcon.setImageDrawable(mContext.getResources().getDrawable(R.drawable.ic_settings_black_18dp)); | |
break; | |
case DRAWER_MENU_ITEM_TERMS: | |
itemIcon.setImageDrawable(mContext.getResources().getDrawable(R.drawable.ic_book_black_18dp)); | |
itemNameTxt.setText("Terms"); | |
break; | |
case DRAWER_MENU_ITEM_LOGOUT: | |
itemIcon.setImageDrawable(mContext.getResources().getDrawable(R.drawable.ic_exit_to_app_black_18dp)); | |
itemNameTxt.setText("Logout"); | |
break; | |
} | |
} | |
@Click(R.id.mainView) | |
private void onMenuItemClick(){ | |
switch (mMenuPosition){ | |
case DRAWER_MENU_ITEM_PROFILE: | |
Toast.makeText(mContext, "Profile", Toast.LENGTH_SHORT).show(); | |
if(mCallBack != null)mCallBack.onProfileMenuSelected(); | |
break; | |
case DRAWER_MENU_ITEM_REQUESTS: | |
Toast.makeText(mContext, "Requests", Toast.LENGTH_SHORT).show(); | |
if(mCallBack != null)mCallBack.onRequestMenuSelected(); | |
break; | |
case DRAWER_MENU_ITEM_GROUPS: | |
Toast.makeText(mContext, "Groups", Toast.LENGTH_SHORT).show(); | |
if(mCallBack != null)mCallBack.onGroupsMenuSelected(); | |
break; | |
case DRAWER_MENU_ITEM_MESSAGE: | |
Toast.makeText(mContext, "Messages", Toast.LENGTH_SHORT).show(); | |
if(mCallBack != null)mCallBack.onMessagesMenuSelected(); | |
break; | |
case DRAWER_MENU_ITEM_NOTIFICATIONS: | |
Toast.makeText(mContext, "Notifications", Toast.LENGTH_SHORT).show(); | |
if(mCallBack != null)mCallBack.onNotificationsMenuSelected(); | |
break; | |
case DRAWER_MENU_ITEM_SETTINGS: | |
Toast.makeText(mContext, "Settings", Toast.LENGTH_SHORT).show(); | |
if(mCallBack != null)mCallBack.onSettingsMenuSelected(); | |
break; | |
case DRAWER_MENU_ITEM_TERMS: | |
Toast.makeText(mContext, "Terms", Toast.LENGTH_SHORT).show(); | |
if(mCallBack != null)mCallBack.onTermsMenuSelected(); | |
break; | |
case DRAWER_MENU_ITEM_LOGOUT: | |
Toast.makeText(mContext, "Logout", Toast.LENGTH_SHORT).show(); | |
if(mCallBack != null)mCallBack.onLogoutMenuSelected(); | |
break; | |
} | |
} | |
public void setDrawerCallBack(DrawerCallBack callBack) { | |
mCallBack = callBack; | |
} | |
public interface DrawerCallBack{ | |
void onProfileMenuSelected(); | |
void onRequestMenuSelected(); | |
void onGroupsMenuSelected(); | |
void onMessagesMenuSelected(); | |
void onNotificationsMenuSelected(); | |
void onSettingsMenuSelected(); | |
void onTermsMenuSelected(); | |
void onLogoutMenuSelected(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment