添加展开文本菜单选项

pull/1164/head
gedoor 3 years ago
parent 4a0c2f4f3b
commit 055a59767a
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 60
      app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt
  4. 3
      app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt
  5. 20
      app/src/main/res/layout/popup_action_menu.xml
  6. 7
      app/src/main/res/xml/pref_config_read.xml

@ -82,6 +82,7 @@ object PreferKey {
const val highBrush = "highBrush"
const val brightness = "brightness"
const val nightBrightness = "nightBrightness"
const val expandTextMenu = "expandTextMenu"
const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent"

@ -104,7 +104,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
}
}
private var menu: Menu? = null
private val textActionMenu: TextActionMenu by lazy {
val textActionMenu: TextActionMenu by lazy {
TextActionMenu(this, this)
}

@ -21,6 +21,7 @@ import androidx.core.view.isVisible
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.constant.PreferKey
import io.legado.app.databinding.ItemTextBinding
import io.legado.app.databinding.PopupActionMenuBinding
import io.legado.app.service.BaseReadAloudService
@ -33,8 +34,9 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
TextToSpeech.OnInitListener {
private val binding = PopupActionMenuBinding.inflate(LayoutInflater.from(context))
private val adapter = Adapter(context)
private val visibleMenuItems: List<MenuItemImpl>
private val moreMenuItems: List<MenuItemImpl>
private val menuItems: List<MenuItemImpl>
private val visibleMenuItems = arrayListOf<MenuItemImpl>()
private val moreMenuItems = arrayListOf<MenuItemImpl>()
private val ttsListener by lazy {
TTSUtteranceListener()
}
@ -53,36 +55,44 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
onInitializeMenu(otherMenu)
}
visibleMenuItems = myMenu.visibleItems.subList(0, 5)
moreMenuItems =
myMenu.visibleItems.subList(5, myMenu.visibleItems.lastIndex) + otherMenu.visibleItems
initRecyclerView()
menuItems = myMenu.visibleItems + otherMenu.visibleItems
visibleMenuItems.addAll(menuItems.subList(0, 5))
moreMenuItems.addAll(menuItems.subList(5, menuItems.lastIndex))
binding.recyclerView.adapter = adapter
binding.recyclerViewMore.adapter = adapter
setOnDismissListener {
binding.ivMenuMore.setImageResource(R.drawable.ic_more_vert)
binding.recyclerViewMore.gone()
adapter.setItems(visibleMenuItems)
binding.recyclerView.visible()
if (!context.getPrefBoolean(PreferKey.expandTextMenu)) {
binding.ivMenuMore.setImageResource(R.drawable.ic_more_vert)
binding.recyclerViewMore.gone()
adapter.setItems(visibleMenuItems)
binding.recyclerView.visible()
}
}
}
private fun initRecyclerView() = with(binding) {
recyclerView.adapter = adapter
recyclerViewMore.adapter = adapter
adapter.setItems(visibleMenuItems)
ivMenuMore.visible()
ivMenuMore.setOnClickListener {
if (recyclerView.isVisible) {
ivMenuMore.setImageResource(R.drawable.ic_arrow_back)
binding.ivMenuMore.setOnClickListener {
if (binding.recyclerView.isVisible) {
binding.ivMenuMore.setImageResource(R.drawable.ic_arrow_back)
adapter.setItems(moreMenuItems)
recyclerView.gone()
recyclerViewMore.visible()
binding.recyclerView.gone()
binding.recyclerViewMore.visible()
} else {
ivMenuMore.setImageResource(R.drawable.ic_more_vert)
recyclerViewMore.gone()
binding.ivMenuMore.setImageResource(R.drawable.ic_more_vert)
binding.recyclerViewMore.gone()
adapter.setItems(visibleMenuItems)
recyclerView.visible()
binding.recyclerView.visible()
}
}
upMenu()
}
fun upMenu() {
val expandTextMenu = context.getPrefBoolean(PreferKey.expandTextMenu)
if (expandTextMenu) {
adapter.setItems(menuItems)
binding.ivMenuMore.gone()
} else {
adapter.setItems(visibleMenuItems)
binding.ivMenuMore.visible()
}
}
inner class Adapter(context: Context) :

@ -119,6 +119,9 @@ class MoreConfigDialog : DialogFragment() {
PreferKey.showBrightnessView -> {
postEvent(PreferKey.showBrightnessView, "")
}
PreferKey.expandTextMenu -> {
(activity as? ReadBookActivity)?.textActionMenu?.upMenu()
}
}
}

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@drawable/shape_card_view"
android:padding="5dp"
android:orientation="vertical">
android:orientation="vertical"
android:padding="5dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">
android:gravity="center_vertical"
android:orientation="horizontal">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
@ -19,17 +19,19 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
app:flexDirection="row"
app:flexWrap="wrap"
app:layoutManager="com.google.android.flexbox.FlexboxLayoutManager" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_menu_more"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/more_menu"
android:src="@drawable/ic_more_vert"
android:tint="@color/primaryText"
android:visibility="gone"
android:contentDescription="@string/more_menu" />
android:visibility="gone" />
</LinearLayout>
@ -38,8 +40,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"
android:orientation="vertical"
android:visibility="gone"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</LinearLayout>

@ -116,4 +116,11 @@
app:iconSpaceReserved="false"
app:isBottomBackground="true" />
<io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="false"
android:key="expandTextMenu"
android:title="展开文本选择菜单"
app:iconSpaceReserved="false"
app:isBottomBackground="true" />
</androidx.preference.PreferenceScreen>
Loading…
Cancel
Save