From 9180a4c40d35e75744d31ed5c9749c5413881da1 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 8 Jul 2021 11:05:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/read/TextActionMenu.kt | 42 ++++--------------- app/src/main/res/layout/popup_action_menu.xml | 7 ++-- 2 files changed, 12 insertions(+), 37 deletions(-) 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 cefd43b16..906fc8ebc 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 @@ -18,8 +18,6 @@ import androidx.appcompat.view.SupportMenuInflater import androidx.appcompat.view.menu.MenuBuilder import androidx.appcompat.view.menu.MenuItemImpl import io.legado.app.R -import io.legado.app.base.adapter.ItemViewHolder -import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.databinding.ItemTextBinding import io.legado.app.databinding.PopupActionMenuBinding import io.legado.app.service.BaseReadAloudService @@ -27,6 +25,7 @@ import io.legado.app.utils.isAbsUrl import io.legado.app.utils.sendToClip import io.legado.app.utils.share import io.legado.app.utils.toastOnUi +import splitties.views.onClick import java.util.* @SuppressLint("RestrictedApi") @@ -35,7 +34,6 @@ 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 menu = MenuBuilder(context) private val moreMenu = MenuBuilder(context) private val ttsListener by lazy { @@ -50,45 +48,23 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac isOutsideTouchable = false isFocusable = false - initRecyclerView() - } - - private fun initRecyclerView() = binding.run { - recyclerView.adapter = adapter SupportMenuInflater(context).inflate(R.menu.content_select_action, menu) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { onInitializeMenu(moreMenu) } - adapter.setItems(menu.visibleItems + moreMenu.visibleItems) - } - - inner class Adapter(context: Context) : - RecyclerAdapter(context) { - - override fun getViewBinding(parent: ViewGroup): ItemTextBinding { - return ItemTextBinding.inflate(inflater, parent, false) - } - - override fun convert( - holder: ItemViewHolder, - binding: ItemTextBinding, - item: MenuItemImpl, - payloads: MutableList - ) { - binding.run { - textView.text = item.title - } - } - - override fun registerListener(holder: ItemViewHolder, binding: ItemTextBinding) { - holder.itemView.setOnClickListener { - getItem(holder.layoutPosition)?.let { + val menuItems = menu.visibleItems + moreMenu.visibleItems + menuItems.forEach { + val textView = ItemTextBinding.inflate(LayoutInflater.from(context)).root.apply { + tag = it + text = it.title + onClick { if (!callBack.onMenuItemSelected(it.itemId)) { onMenuItemSelected(it) } + callBack.onMenuActionFinally() } - callBack.onMenuActionFinally() } + binding.root.addView(textView) } } diff --git a/app/src/main/res/layout/popup_action_menu.xml b/app/src/main/res/layout/popup_action_menu.xml index 238593f51..74b43c301 100644 --- a/app/src/main/res/layout/popup_action_menu.xml +++ b/app/src/main/res/layout/popup_action_menu.xml @@ -1,10 +1,9 @@ - \ No newline at end of file + app:flexDirection="row" + app:flexWrap="wrap" /> \ No newline at end of file