diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt index 343b8a7d5..2d0fefc39 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt @@ -95,7 +95,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : } } iv_menu_more.onClick { - showMenu(iv_menu_more, getItem(holder.layoutPosition)) + showMenu(iv_menu_more, holder.layoutPosition) } upShowExplore(iv_explore, item) } else { @@ -116,8 +116,8 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : } } - private fun showMenu(view: View, source: BookSource?) { - if (source == null) return + private fun showMenu(view: View, position: Int) { + val source = getItem(position) ?: return val popupMenu = PopupMenu(context, view) popupMenu.inflate(R.menu.book_source_item) val qyMenu = popupMenu.menu.findItem(R.id.menu_enable_explore) diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index afb04a298..49dfcc737 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -40,7 +40,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca callBack.scrollTo(holder.layoutPosition) } ll_title.onLongClick { - showMenu(ll_title, getItem(holder.layoutPosition), holder.layoutPosition) + showMenu(ll_title, holder.layoutPosition) } } if (exIndex == holder.layoutPosition) { @@ -80,8 +80,8 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca } } - private fun showMenu(view: View, source: BookSource?, position: Int): Boolean { - if (source == null) return true + private fun showMenu(view: View, position: Int): Boolean { + val source = getItem(position) ?: return true val popupMenu = PopupMenu(context, view) popupMenu.inflate(R.menu.explore_item) popupMenu.setOnMenuItemClickListener { diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt index 5368569d3..ee95ffd5a 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt @@ -2,6 +2,7 @@ package io.legado.app.ui.replacerule import android.content.Context import android.os.Bundle +import android.view.View import android.widget.PopupMenu import androidx.core.os.bundleOf import androidx.recyclerview.widget.RecyclerView @@ -81,16 +82,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : callBack.upCountView() } iv_menu_more.onClick { - val popupMenu = PopupMenu(context, it) - popupMenu.inflate(R.menu.replace_rule_item) - popupMenu.setOnMenuItemClickListener { menuItem -> - when (menuItem.itemId) { - R.id.menu_top -> callBack.toTop(item) - R.id.menu_del -> callBack.delete(item) - } - true - } - popupMenu.show() + showMenu(iv_menu_more, holder.layoutPosition) } } else { bundle.keySet().map { @@ -110,6 +102,20 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : } } + private fun showMenu(view: View, position: Int) { + val item = getItem(position) ?: return + val popupMenu = PopupMenu(context, view) + popupMenu.inflate(R.menu.replace_rule_item) + popupMenu.setOnMenuItemClickListener { menuItem -> + when (menuItem.itemId) { + R.id.menu_top -> callBack.toTop(item) + R.id.menu_del -> callBack.delete(item) + } + true + } + popupMenu.show() + } + override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { val srcItem = getItem(srcPosition) val targetItem = getItem(targetPosition) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt index 11beabe5c..a4e2d5671 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt @@ -88,7 +88,7 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : } } iv_menu_more.onClick { - showMenu(iv_menu_more, getItem(holder.layoutPosition)) + showMenu(iv_menu_more, holder.layoutPosition) } } else { when (payloads[0]) { @@ -99,8 +99,8 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : } } - private fun showMenu(view: View, source: RssSource?) { - if (source == null) return + private fun showMenu(view: View, position: Int) { + val source = getItem(position) ?: return val popupMenu = PopupMenu(context, view) popupMenu.inflate(R.menu.rss_source_item) popupMenu.setOnMenuItemClickListener { menuItem ->