|
|
@ -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 { |
|
|
|
|
|
|
|
if (!context.getPrefBoolean(PreferKey.expandTextMenu)) { |
|
|
|
binding.ivMenuMore.setImageResource(R.drawable.ic_more_vert) |
|
|
|
binding.ivMenuMore.setImageResource(R.drawable.ic_more_vert) |
|
|
|
binding.recyclerViewMore.gone() |
|
|
|
binding.recyclerViewMore.gone() |
|
|
|
adapter.setItems(visibleMenuItems) |
|
|
|
adapter.setItems(visibleMenuItems) |
|
|
|
binding.recyclerView.visible() |
|
|
|
binding.recyclerView.visible() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
binding.ivMenuMore.setOnClickListener { |
|
|
|
private fun initRecyclerView() = with(binding) { |
|
|
|
if (binding.recyclerView.isVisible) { |
|
|
|
recyclerView.adapter = adapter |
|
|
|
binding.ivMenuMore.setImageResource(R.drawable.ic_arrow_back) |
|
|
|
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) : |
|
|
|