Commit e1903067 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Using with to avoid repeating menu lots of time.

parent 728f4011
...@@ -5,54 +5,56 @@ import android.view.MenuItem ...@@ -5,54 +5,56 @@ import android.view.MenuItem
import chat.rocket.android.R import chat.rocket.android.R
internal fun MainActivity.setupMenu(menu: Menu) { internal fun MainActivity.setupMenu(menu: Menu) {
menu.add( with(menu) {
R.id.menu_section_one, add(
R.id.menu_action_chats, R.id.menu_section_one,
Menu.NONE, R.id.menu_action_chats,
R.string.title_chats Menu.NONE,
).setIcon(R.drawable.ic_chat_bubble_black_24dp) R.string.title_chats
.isChecked = true ).setIcon(R.drawable.ic_chat_bubble_black_24dp)
.isChecked = true
menu.add(
R.id.menu_section_one,
R.id.menu_action_create_channel,
Menu.NONE,
R.string.action_create_channel
).setIcon(R.drawable.ic_create_black_24dp)
menu.add( add(
R.id.menu_section_two, R.id.menu_section_one,
R.id.menu_action_profile, R.id.menu_action_create_channel,
Menu.NONE, Menu.NONE,
R.string.title_profile R.string.action_create_channel
).setIcon(R.drawable.ic_person_black_24dp) ).setIcon(R.drawable.ic_create_black_24dp)
menu.add( add(
R.id.menu_section_two, R.id.menu_section_two,
R.id.menu_action_settings, R.id.menu_action_profile,
Menu.NONE, Menu.NONE,
R.string.title_settings R.string.title_profile
).setIcon(R.drawable.ic_settings_black_24dp) ).setIcon(R.drawable.ic_person_black_24dp)
if (permissions.canSeeTheAdminPanel()) { add(
menu.add(
R.id.menu_section_two, R.id.menu_section_two,
R.id.menu_action_admin_panel, R.id.menu_action_settings,
Menu.NONE, Menu.NONE,
R.string.title_admin_panel R.string.title_settings
).setIcon(R.drawable.ic_settings_black_24dp) ).setIcon(R.drawable.ic_settings_black_24dp)
}
menu.add( if (permissions.canSeeTheAdminPanel()) {
R.id.menu_section_three, add(
R.id.menu_action_logout, R.id.menu_section_two,
Menu.NONE, R.id.menu_action_admin_panel,
R.string.action_logout Menu.NONE,
).setIcon(R.drawable.ic_logout_black_24dp) R.string.title_admin_panel
).setIcon(R.drawable.ic_settings_black_24dp)
}
add(
R.id.menu_section_three,
R.id.menu_action_logout,
Menu.NONE,
R.string.action_logout
).setIcon(R.drawable.ic_logout_black_24dp)
menu.setGroupCheckable(R.id.menu_section_one, true, true) setGroupCheckable(R.id.menu_section_one, true, true)
menu.setGroupCheckable(R.id.menu_section_two, true, true) setGroupCheckable(R.id.menu_section_two, true, true)
menu.setGroupCheckable(R.id.menu_section_three, true, true) setGroupCheckable(R.id.menu_section_three, true, true)
}
} }
internal fun MainActivity.onNavDrawerItemSelected(menuItem: MenuItem) { internal fun MainActivity.onNavDrawerItemSelected(menuItem: MenuItem) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment