From e2665383d20bc084edcdd2052c43058f32eaf743 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 15 Feb 2020 10:00:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/main/explore/ExploreAdapter.kt | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) 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 599268ed5..afb04a298 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 @@ -2,6 +2,7 @@ package io.legado.app.ui.main.explore import android.content.Context import android.view.LayoutInflater +import android.view.View import android.widget.PopupMenu import io.legado.app.App import io.legado.app.R @@ -39,24 +40,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca callBack.scrollTo(holder.layoutPosition) } ll_title.onLongClick { - val popupMenu = PopupMenu(context, ll_title) - popupMenu.inflate(R.menu.explore_item) - popupMenu.setOnMenuItemClickListener { - when (it.itemId) { - R.id.menu_edit -> callBack.editSource(item.bookSourceUrl) - R.id.menu_top -> callBack.toTop(item) - R.id.menu_refresh -> { - ACache.get(context, "explore").remove(item.bookSourceUrl) - notifyItemChanged(holder.layoutPosition) - } - R.id.menu_del -> Coroutine.async(scope) { - App.db.bookSourceDao().delete(item) - } - } - true - } - popupMenu.show() - true + showMenu(ll_title, getItem(holder.layoutPosition), holder.layoutPosition) } } if (exIndex == holder.layoutPosition) { @@ -96,6 +80,28 @@ 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 + val popupMenu = PopupMenu(context, view) + popupMenu.inflate(R.menu.explore_item) + popupMenu.setOnMenuItemClickListener { + when (it.itemId) { + R.id.menu_edit -> callBack.editSource(source.bookSourceUrl) + R.id.menu_top -> callBack.toTop(source) + R.id.menu_refresh -> { + ACache.get(context, "explore").remove(source.bookSourceUrl) + notifyItemChanged(position) + } + R.id.menu_del -> Coroutine.async(scope) { + App.db.bookSourceDao().delete(source) + } + } + true + } + popupMenu.show() + return true + } + interface CallBack { fun scrollTo(pos: Int) fun openExplore(sourceUrl: String, title: String, exploreUrl: String)