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

pull/1678/head
kunfei 3 years ago
parent 6f892d3e5d
commit 741a2720c5
  1. 30
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 5
      app/src/main/java/io/legado/app/utils/MenuExtensions.kt
  3. 46
      app/src/main/res/menu/book_read.xml
  4. 17
      app/src/main/res/menu/book_read_change_source.xml
  5. 23
      app/src/main/res/menu/book_read_refresh.xml

@ -7,6 +7,7 @@ import android.content.res.Configuration
import android.os.Bundle
import android.view.*
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.widget.PopupMenu
import androidx.core.view.get
import androidx.core.view.isVisible
import androidx.core.view.size
@ -67,6 +68,7 @@ class ReadBookActivity : BaseReadBookActivity(),
ReadView.CallBack,
TextActionMenu.CallBack,
ContentTextView.CallBack,
PopupMenu.OnMenuItemClickListener,
ReadMenu.CallBack,
SearchMenu.CallBack,
ReadAloudDialog.CallBack,
@ -118,6 +120,8 @@ class ReadBookActivity : BaseReadBookActivity(),
}
}
private var menu: Menu? = null
private var changeSourceMenu: PopupMenu? = null
private var refreshMenu: PopupMenu? = null
val textActionMenu: TextActionMenu by lazy {
TextActionMenu(this, this)
}
@ -193,6 +197,26 @@ 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) {
if (changeSourceMenu == null) {
changeSourceMenu = PopupMenu(this, it).apply {
inflate(R.menu.book_read_change_source)
this.menu.applyOpenTint(this@ReadBookActivity)
setOnMenuItemClickListener(this@ReadBookActivity)
}
}
changeSourceMenu!!.show()
}
menu.findItem(R.id.menu_refresh)?.setOnLongClickListener(menu) {
if (refreshMenu == null) {
refreshMenu = PopupMenu(this, it).apply {
inflate(R.menu.book_read_refresh)
this.menu.applyOpenTint(this@ReadBookActivity)
setOnMenuItemClickListener(this@ReadBookActivity)
}
}
refreshMenu!!.show()
}
return super.onCompatCreateOptionsMenu(menu)
}
@ -238,6 +262,7 @@ class ReadBookActivity : BaseReadBookActivity(),
*/
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_change_source,
R.id.menu_book_change_source -> {
binding.readMenu.runMenuOut()
ReadBook.book?.let {
@ -254,6 +279,7 @@ class ReadBookActivity : BaseReadBookActivity(),
ChangeChapterSourceDialog(book.name, book.author, chapter.index, chapter.title)
)
}
R.id.menu_refresh,
R.id.menu_refresh_dur -> {
if (ReadBook.bookSource == null) {
upContent()
@ -352,6 +378,10 @@ class ReadBookActivity : BaseReadBookActivity(),
return super.onCompatOptionsItemSelected(item)
}
override fun onMenuItemClick(item: MenuItem): Boolean {
return onCompatOptionsItemSelected(item)
}
/**
* 按键拦截,显示菜单
*/

@ -6,6 +6,7 @@ import android.annotation.SuppressLint
import android.content.Context
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.ImageButton
import androidx.appcompat.view.menu.MenuBuilder
import androidx.appcompat.view.menu.MenuItemImpl
@ -60,9 +61,9 @@ fun Menu.applyOpenTint(context: Context) {
}
}
fun MenuItem.setOnLongClickListener(menu: Menu, function: () -> (Unit)) {
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(); true }
actionView.setOnLongClickListener { function.invoke(actionView); true }
actionView.setOnClickListener { menu.performIdentifierAction(itemId, 0) }
}

@ -9,55 +9,13 @@
android:id="@+id/menu_change_source"
android:icon="@drawable/ic_exchange"
android:title="@string/change_origin"
app:showAsAction="always">
<menu>
<item
android:id="@+id/menu_chapter_change_source"
android:icon="@drawable/ic_bubble_chart"
android:title="@string/chapter_change_source"
app:showAsAction="never" />
<item
android:id="@+id/menu_book_change_source"
android:icon="@drawable/ic_bubble_chart"
android:title="@string/book_change_source"
app:showAsAction="never" />
</menu>
</item>
app:showAsAction="always" />
<item
android:id="@+id/menu_refresh"
android:icon="@drawable/ic_refresh_black_24dp"
android:title="@string/refresh"
app:showAsAction="always">
<menu>
<item
android:id="@+id/menu_refresh_dur"
android:icon="@drawable/ic_bubble_chart"
android:title="@string/menu_refresh_dur"
app:showAsAction="never" />
<item
android:id="@+id/menu_refresh_after"
android:icon="@drawable/ic_bubble_chart"
android:title="@string/menu_refresh_after"
app:showAsAction="never" />
<item
android:id="@+id/menu_refresh_all"
android:icon="@drawable/ic_bubble_chart"
android:title="@string/menu_refresh_all"
app:showAsAction="never" />
</menu>
</item>
app:showAsAction="always" />
<item
android:id="@+id/menu_download"

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_chapter_change_source"
android:icon="@drawable/ic_bubble_chart"
android:title="@string/chapter_change_source"
app:showAsAction="never" />
<item
android:id="@+id/menu_book_change_source"
android:icon="@drawable/ic_bubble_chart"
android:title="@string/book_change_source"
app:showAsAction="never" />
</menu>

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_refresh_dur"
android:icon="@drawable/ic_bubble_chart"
android:title="@string/menu_refresh_dur"
app:showAsAction="never" />
<item
android:id="@+id/menu_refresh_after"
android:icon="@drawable/ic_bubble_chart"
android:title="@string/menu_refresh_after"
app:showAsAction="never" />
<item
android:id="@+id/menu_refresh_all"
android:icon="@drawable/ic_bubble_chart"
android:title="@string/menu_refresh_all"
app:showAsAction="never" />
</menu>
Loading…
Cancel
Save