feat: 优化代码

pull/159/head
kunfei 5 years ago
parent 68becb21fd
commit 9da86a4d37
  1. 8
      app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt
  2. 10
      app/src/main/res/layout/popup_action_menu.xml

@ -49,7 +49,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
setOnDismissListener { setOnDismissListener {
contentView.apply { contentView.apply {
iv_menu_more.setImageResource(R.drawable.ic_more_vert) iv_menu_more.setImageResource(R.drawable.ic_more_vert)
recycler_view_top.gone() recycler_view_more.gone()
adapter.setItems(menu.visibleItems) adapter.setItems(menu.visibleItems)
recycler_view.visible() recycler_view.visible()
} }
@ -58,6 +58,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
private fun initRecyclerView() = with(contentView) { private fun initRecyclerView() = with(contentView) {
recycler_view.adapter = adapter recycler_view.adapter = adapter
recycler_view_more.adapter = adapter
SupportMenuInflater(context).inflate(R.menu.content_select_action, menu) SupportMenuInflater(context).inflate(R.menu.content_select_action, menu)
adapter.setItems(menu.visibleItems) adapter.setItems(menu.visibleItems)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
@ -69,13 +70,12 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
iv_menu_more.onClick { iv_menu_more.onClick {
if (recycler_view.isVisible) { if (recycler_view.isVisible) {
iv_menu_more.setImageResource(R.drawable.ic_arrow_back) iv_menu_more.setImageResource(R.drawable.ic_arrow_back)
recycler_view_top.adapter = adapter
adapter.setItems(moreMenu.visibleItems) adapter.setItems(moreMenu.visibleItems)
recycler_view.gone() recycler_view.gone()
recycler_view_top.visible() recycler_view_more.visible()
} else { } else {
iv_menu_more.setImageResource(R.drawable.ic_more_vert) iv_menu_more.setImageResource(R.drawable.ic_more_vert)
recycler_view_top.gone() recycler_view_more.gone()
adapter.setItems(menu.visibleItems) adapter.setItems(menu.visibleItems)
recycler_view.visible() recycler_view.visible()
} }

@ -29,18 +29,18 @@
android:visibility="gone" android:visibility="gone"
android:contentDescription="@string/more_menu" android:contentDescription="@string/more_menu"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="@+id/recycler_view_top" /> app:layout_constraintRight_toRightOf="parent" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_top" android:id="@+id/recycler_view_more"
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:visibility="gone"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@+id/iv_menu_more" app:layout_constraintTop_toBottomOf="@+id/iv_menu_more"
app:layout_constraintRight_toRightOf="parent" /> app:layout_constraintRight_toRightOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

Loading…
Cancel
Save