单章换源和更多刷新放到长按里面

pull/1678/head 3.22.030322
kunfei 3 years ago
parent a5a4549167
commit 6638018222
  1. 4
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 15
      app/src/main/java/io/legado/app/utils/MenuExtensions.kt

@ -197,7 +197,7 @@ class ReadBookActivity : BaseReadBookActivity(),
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.book_read, menu)
menu.findItem(R.id.menu_change_source)?.setOnLongClickListener(menu) {
menu.iconItemOnLongClick(R.id.menu_change_source) {
val changeSourceMenu = changeSourceMenu ?: PopupMenu(this, it).apply {
inflate(R.menu.book_read_change_source)
this.menu.applyOpenTint(this@ReadBookActivity)
@ -206,7 +206,7 @@ class ReadBookActivity : BaseReadBookActivity(),
}
changeSourceMenu.show()
}
menu.findItem(R.id.menu_refresh)?.setOnLongClickListener(menu) {
menu.iconItemOnLongClick(R.id.menu_refresh) {
val refreshMenu = refreshMenu ?: PopupMenu(this, it).apply {
inflate(R.menu.book_read_refresh)
this.menu.applyOpenTint(this@ReadBookActivity)

@ -61,9 +61,12 @@ fun Menu.applyOpenTint(context: Context) {
}
}
fun MenuItem.setOnLongClickListener(menu: Menu, function: (view: View) -> (Unit)) {
setActionView(R.layout.view_action_button)
actionView.findViewById<ImageButton>(R.id.item).setImageDrawable(icon)
actionView.setOnLongClickListener { function.invoke(actionView); true }
actionView.setOnClickListener { menu.performIdentifierAction(itemId, 0) }
}
fun Menu.iconItemOnLongClick(id: Int, function: (view: View) -> Unit) {
findItem(id)?.let { item ->
item.setActionView(R.layout.view_action_button)
item.actionView.contentDescription = item.title
item.actionView.findViewById<ImageButton>(R.id.item).setImageDrawable(item.icon)
item.actionView.setOnLongClickListener { function.invoke(item.actionView); true }
item.actionView.setOnClickListener { performIdentifierAction(id, 0) }
}
}

Loading…
Cancel
Save