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