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

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. 13
      app/src/main/java/io/legado/app/utils/MenuExtensions.kt

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

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