添加展开文本菜单选项

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 highBrush = "highBrush"
const val brightness = "brightness" const val brightness = "brightness"
const val nightBrightness = "nightBrightness" const val nightBrightness = "nightBrightness"
const val expandTextMenu = "expandTextMenu"
const val cPrimary = "colorPrimary" const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent" const val cAccent = "colorAccent"

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

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

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

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

@ -116,4 +116,11 @@
app:iconSpaceReserved="false" app:iconSpaceReserved="false"
app:isBottomBackground="true" /> 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> </androidx.preference.PreferenceScreen>
Loading…
Cancel
Save