diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index cc1a23bb6..4b861fa54 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -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" diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index e34a4e624..be8bcfd02 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -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) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt index b4296247b..811f813f3 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt @@ -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 - private val moreMenuItems: List + private val menuItems: List + private val visibleMenuItems = arrayListOf() + private val moreMenuItems = arrayListOf() 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) : diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt index 3fe8ed971..15f601c27 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt @@ -119,6 +119,9 @@ class MoreConfigDialog : DialogFragment() { PreferKey.showBrightnessView -> { postEvent(PreferKey.showBrightnessView, "") } + PreferKey.expandTextMenu -> { + (activity as? ReadBookActivity)?.textActionMenu?.upMenu() + } } } diff --git a/app/src/main/res/layout/popup_action_menu.xml b/app/src/main/res/layout/popup_action_menu.xml index ab9a681b8..b44b71355 100644 --- a/app/src/main/res/layout/popup_action_menu.xml +++ b/app/src/main/res/layout/popup_action_menu.xml @@ -1,17 +1,17 @@ + android:orientation="vertical" + android:padding="5dp"> + android:gravity="center_vertical" + android:orientation="horizontal"> + app:flexDirection="row" + app:flexWrap="wrap" + app:layoutManager="com.google.android.flexbox.FlexboxLayoutManager" /> + android:visibility="gone" /> @@ -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" /> diff --git a/app/src/main/res/xml/pref_config_read.xml b/app/src/main/res/xml/pref_config_read.xml index 6f4b6e440..f66057975 100644 --- a/app/src/main/res/xml/pref_config_read.xml +++ b/app/src/main/res/xml/pref_config_read.xml @@ -116,4 +116,11 @@ app:iconSpaceReserved="false" app:isBottomBackground="true" /> + + \ No newline at end of file