Commit 008f9df4 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Moves menu actions and sections ids to ids.xml

parent 5b0a4075
......@@ -17,7 +17,6 @@ import androidx.recyclerview.widget.RecyclerView
import chat.rocket.android.R
import chat.rocket.android.createchannel.presentation.CreateChannelPresenter
import chat.rocket.android.createchannel.presentation.CreateChannelView
import chat.rocket.android.main.ui.MENU_ACTION_CHATS
import chat.rocket.android.main.ui.MainActivity
import chat.rocket.android.members.adapter.MembersAdapter
import chat.rocket.android.members.uimodel.MemberUiModel
......@@ -162,7 +161,7 @@ class CreateChannelFragment : Fragment(), CreateChannelView, ActionMode.Callback
override fun prepareToShowChatList() {
with(activity as MainActivity) {
setCheckedNavDrawerItem(MENU_ACTION_CHATS)
setCheckedNavDrawerItem(R.id.menu_action_chats)
openDrawer()
getDrawerLayout().postDelayed(1000) {
closeDrawer()
......
......@@ -5,9 +5,9 @@ import android.app.Activity
import android.app.AlertDialog
import android.app.ProgressDialog
import android.os.Bundle
import android.view.Gravity
import androidx.annotation.IdRes
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.GravityCompat
import androidx.drawerlayout.widget.DrawerLayout
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
......@@ -174,9 +174,9 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector,
}
headerLayout.image_avatar.setOnClickListener {
view_navigation.menu.findItem(MENU_ACTION_PROFILE).isChecked = true
view_navigation.menu.findItem(R.id.menu_action_profile).isChecked = true
presenter.toUserProfile()
drawer_layout.closeDrawer(Gravity.START)
drawer_layout.closeDrawer(GravityCompat.START)
}
}
......@@ -248,9 +248,9 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector,
fun getDrawerLayout(): DrawerLayout = drawer_layout
fun openDrawer() = drawer_layout.openDrawer(Gravity.START)
fun openDrawer() = drawer_layout.openDrawer(GravityCompat.START)
fun closeDrawer() = drawer_layout.closeDrawer(Gravity.START)
fun closeDrawer() = drawer_layout.closeDrawer(GravityCompat.START)
fun setCheckedNavDrawerItem(@IdRes item: Int) = view_navigation.setCheckedItem(item)
......
......@@ -4,75 +4,64 @@ import android.view.Menu
import android.view.MenuItem
import chat.rocket.android.R
private const val MENU_SECTION_ONE = 1
private const val MENU_SECTION_TWO = 2
private const val MENU_SECTION_THREE = 3
const val MENU_ACTION_CHATS = 1
private const val MENU_ACTION_CREATE_CHANNEL = 2
const val MENU_ACTION_PROFILE = 3
private const val MENU_ACTION_SETTINGS = 4
private const val MENU_ACTION_ADMIN_PANEL = 5
private const val MENU_ACTION_LOGOUT = 6
internal fun MainActivity.setupMenu(menu: Menu) {
menu.add(
MENU_SECTION_ONE,
MENU_ACTION_CHATS,
R.id.menu_section_one,
R.id.menu_action_chats,
Menu.NONE,
R.string.title_chats
).setIcon(R.drawable.ic_chat_bubble_black_24dp)
.isChecked = true
menu.add(
MENU_SECTION_ONE,
MENU_ACTION_CREATE_CHANNEL,
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(
MENU_SECTION_TWO,
MENU_ACTION_PROFILE,
R.id.menu_section_two,
R.id.menu_action_profile,
Menu.NONE,
R.string.title_profile
).setIcon(R.drawable.ic_person_black_24dp)
menu.add(
MENU_SECTION_TWO,
MENU_ACTION_SETTINGS,
R.id.menu_section_two,
R.id.menu_action_settings,
Menu.NONE,
R.string.title_settings
).setIcon(R.drawable.ic_settings_black_24dp)
if (permissions.canSeeTheAdminChannel()) {
menu.add(
MENU_SECTION_TWO,
MENU_ACTION_ADMIN_PANEL,
R.id.menu_section_two,
R.id.menu_action_admin_panel,
Menu.NONE,
R.string.title_admin_panel
).setIcon(R.drawable.ic_settings_black_24dp)
}
menu.add(
MENU_SECTION_THREE,
MENU_ACTION_LOGOUT,
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(MENU_SECTION_ONE, true, true)
menu.setGroupCheckable(MENU_SECTION_TWO, true, true)
menu.setGroupCheckable(MENU_SECTION_THREE, true, true)
menu.setGroupCheckable(R.id.menu_section_one, true, true)
menu.setGroupCheckable(R.id.menu_section_two, true, true)
menu.setGroupCheckable(R.id.menu_section_three, true, true)
}
internal fun MainActivity.onNavDrawerItemSelected(menuItem: MenuItem) {
when (menuItem.itemId) {
MENU_ACTION_CHATS -> presenter.toChatList()
MENU_ACTION_CREATE_CHANNEL -> presenter.toCreateChannel()
MENU_ACTION_PROFILE -> presenter.toUserProfile()
MENU_ACTION_SETTINGS -> presenter.toSettings()
MENU_ACTION_ADMIN_PANEL -> presenter.toAdminPanel()
MENU_ACTION_LOGOUT -> presenter.logout()
R.id.menu_action_chats-> presenter.toChatList()
R.id.menu_action_create_channel -> presenter.toCreateChannel()
R.id.menu_action_profile -> presenter.toUserProfile()
R.id.menu_action_settings -> presenter.toSettings()
R.id.menu_action_admin_panel -> presenter.toAdminPanel()
R.id.menu_action_logout -> presenter.logout()
}
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="menu_section_one" type="id"/>
<item name="menu_section_two" type="id"/>
<item name="menu_section_three" type="id"/>
<item name="menu_action_chats" type="id"/>
<item name="menu_action_create_channel" type="id"/>
<item name="menu_action_profile" type="id"/>
<item name="menu_action_settings" type="id"/>
<item name="menu_action_admin_panel" type="id"/>
<item name="menu_action_logout" type="id"/>
</resources>
\ No newline at end of file
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