Commit 50fa7847 authored by Leonardo Aramaki's avatar Leonardo Aramaki

More refactoring

parent 7cd40441
......@@ -14,8 +14,11 @@ class BottomSheetMenu(adapter: MenuAdapter) : SheetMenu(adapter = adapter) {
layoutManager = LinearLayoutManager(recycler.context, LinearLayoutManager.VERTICAL, false)
}
val callback = adapter?.callback
adapter?.callback = MenuItem.OnMenuItemClickListener {
// Superclass SheetMenu adapter property is nullable MenuAdapter? but this class enforces
// passing one at the constructor, so we assume it's always non-null.
val adapter = adapter!!
val callback = adapter.callback
adapter.callback = MenuItem.OnMenuItemClickListener {
callback?.onMenuItemClick(it)
dialog.cancel()
true
......
package chat.rocket.android.chatroom.ui.bottomsheet.adapter
import android.graphics.Color
import android.view.MenuItem
import android.view.View
import chat.rocket.android.R
import chat.rocket.android.util.setVisible
/**
* An adapter for bottomsheet menu that lists all the actions that could be taken over a chat message.
......@@ -15,13 +15,9 @@ class ActionListAdapter(menuItems: List<MenuItem> = emptyList(), callback: MenuI
val item = menuItems[position]
if (showIcons) {
if (item.icon == null) {
holder.imageIcon.visibility = View.GONE
holder.imageIcon.setVisible(item.icon == null)
} else {
holder.imageIcon.visibility = View.VISIBLE
}
} else {
holder.imageIcon.visibility = View.GONE
holder.imageIcon.setVisible(false)
}
holder.imageIcon.setImageDrawable(item.icon)
......@@ -29,7 +25,8 @@ class ActionListAdapter(menuItems: List<MenuItem> = emptyList(), callback: MenuI
holder.itemView.setOnClickListener {
callback?.onMenuItemClick(item)
}
val color = if (item.itemId == R.id.action_menu_msg_delete) Color.RED else textColors.get(item.itemId)
val deleteTextColor = holder.itemView.context.resources.getColor(R.color.red)
val color = if (item.itemId == R.id.action_menu_msg_delete) deleteTextColor else textColors.get(item.itemId)
holder.textTitle.setTextColor(color)
}
}
\ No newline at end of file
......@@ -30,8 +30,7 @@ open class ListBottomSheetAdapter(menuItems: List<MenuItem> = emptyList(), callb
* @param itemId The id of the menu item to disable and hide.
*/
fun hideMenuItem(@IdRes itemId: Int) {
val item = menuItems.firstOrNull { it.itemId == itemId }
item?.apply {
menuItems.firstOrNull { it.itemId == itemId }?.apply {
setVisible(false)
setEnabled(false)
}
......@@ -43,8 +42,7 @@ open class ListBottomSheetAdapter(menuItems: List<MenuItem> = emptyList(), callb
* @param itemId The id of the menu item to enable and show.
*/
fun showMenuItem(@IdRes itemId: Int) {
val item = menuItems.firstOrNull { it.itemId == itemId }
item?.apply {
menuItems.firstOrNull { it.itemId == itemId }?.apply {
setVisible(true)
setEnabled(true)
}
......
......@@ -17,6 +17,7 @@
<color name="white">#FFFFFFFF</color>
<color name="black">#FF000000</color>
<color name="red">#FFFF0000</color>
<color name="darkGray">#a0a0a0</color>
<color name="actionMenuColor">#727272</color>
......
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