|
|
@ -15,13 +15,11 @@ import androidx.annotation.RequiresApi |
|
|
|
import androidx.appcompat.view.SupportMenuInflater |
|
|
|
import androidx.appcompat.view.SupportMenuInflater |
|
|
|
import androidx.appcompat.view.menu.MenuBuilder |
|
|
|
import androidx.appcompat.view.menu.MenuBuilder |
|
|
|
import androidx.appcompat.view.menu.MenuItemImpl |
|
|
|
import androidx.appcompat.view.menu.MenuItemImpl |
|
|
|
import androidx.appcompat.widget.PopupMenu |
|
|
|
import androidx.core.view.isVisible |
|
|
|
import androidx.core.view.size |
|
|
|
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
|
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
|
|
|
|
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.SimpleRecyclerAdapter |
|
|
|
import io.legado.app.base.adapter.SimpleRecyclerAdapter |
|
|
|
|
|
|
|
import io.legado.app.utils.gone |
|
|
|
import io.legado.app.utils.isAbsUrl |
|
|
|
import io.legado.app.utils.isAbsUrl |
|
|
|
import io.legado.app.utils.sendToClip |
|
|
|
import io.legado.app.utils.sendToClip |
|
|
|
import io.legado.app.utils.visible |
|
|
|
import io.legado.app.utils.visible |
|
|
@ -35,6 +33,10 @@ import org.jetbrains.anko.toast |
|
|
|
class TextActionMenu(private val context: Context, private val callBack: CallBack) : |
|
|
|
class TextActionMenu(private val context: Context, private val callBack: CallBack) : |
|
|
|
PopupWindow(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) { |
|
|
|
PopupWindow(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val adapter = Adapter(context) |
|
|
|
|
|
|
|
private val menu = MenuBuilder(context) |
|
|
|
|
|
|
|
private val moreMenu = MenuBuilder(context) |
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
init { |
|
|
|
@SuppressLint("InflateParams") |
|
|
|
@SuppressLint("InflateParams") |
|
|
|
contentView = LayoutInflater.from(context).inflate(R.layout.popup_action_menu, null) |
|
|
|
contentView = LayoutInflater.from(context).inflate(R.layout.popup_action_menu, null) |
|
|
@ -44,33 +46,40 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac |
|
|
|
isFocusable = false |
|
|
|
isFocusable = false |
|
|
|
|
|
|
|
|
|
|
|
initRecyclerView() |
|
|
|
initRecyclerView() |
|
|
|
|
|
|
|
setOnDismissListener { |
|
|
|
|
|
|
|
contentView.apply { |
|
|
|
|
|
|
|
iv_menu_more.setImageResource(R.drawable.ic_more_vert) |
|
|
|
|
|
|
|
recycler_view_top.gone() |
|
|
|
|
|
|
|
recycler_view_bottom.gone() |
|
|
|
|
|
|
|
adapter.setItems(menu.visibleItems) |
|
|
|
|
|
|
|
recycler_view.visible() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initRecyclerView() = with(contentView) { |
|
|
|
private fun initRecyclerView() = with(contentView) { |
|
|
|
val adapter = Adapter(context) |
|
|
|
|
|
|
|
recycler_view.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false) |
|
|
|
|
|
|
|
recycler_view.adapter = adapter |
|
|
|
recycler_view.adapter = adapter |
|
|
|
val menu = MenuBuilder(context) |
|
|
|
|
|
|
|
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) { |
|
|
|
val popupMenu = PopupMenu(context, iv_menu_more) |
|
|
|
onInitializeMenu(moreMenu) |
|
|
|
onInitializeMenu(popupMenu.menu) |
|
|
|
} |
|
|
|
if (popupMenu.menu.size > 0) { |
|
|
|
if (moreMenu.size() > 0) { |
|
|
|
iv_menu_more.visible() |
|
|
|
iv_menu_more.visible() |
|
|
|
popupMenu.setOnMenuItemClickListener { item -> |
|
|
|
} |
|
|
|
item.intent?.let { |
|
|
|
iv_menu_more.onClick { |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
|
|
|
if (recycler_view.isVisible) { |
|
|
|
it.putExtra(Intent.EXTRA_PROCESS_TEXT, callBack.selectedText) |
|
|
|
iv_menu_more.setImageResource(R.drawable.ic_arrow_back) |
|
|
|
context.startActivity(it) |
|
|
|
recycler_view_top.adapter = adapter |
|
|
|
} |
|
|
|
adapter.setItems(moreMenu.visibleItems) |
|
|
|
} |
|
|
|
recycler_view.gone() |
|
|
|
this@TextActionMenu.dismiss() |
|
|
|
recycler_view_top.visible() |
|
|
|
true |
|
|
|
} else { |
|
|
|
} |
|
|
|
iv_menu_more.setImageResource(R.drawable.ic_more_vert) |
|
|
|
} |
|
|
|
recycler_view_top.gone() |
|
|
|
iv_menu_more.onClick { |
|
|
|
recycler_view_bottom.gone() |
|
|
|
popupMenu.show() |
|
|
|
adapter.setItems(menu.visibleItems) |
|
|
|
|
|
|
|
recycler_view.visible() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|