From a9e5c152d9f79fdb0fb899a8cdfec45d3d940a65 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 14 Feb 2020 22:51:33 +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 --- .../book/source/manage/BookSourceAdapter.kt | 54 ++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-) 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 d7c86fbad..6e66704b8 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 @@ -3,6 +3,7 @@ package io.legado.app.ui.book.source.manage import android.content.Context import android.graphics.Color import android.os.Bundle +import android.view.View import android.widget.ImageView import android.widget.PopupMenu import androidx.core.os.bundleOf @@ -82,31 +83,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : } iv_edit.onClick { callBack.edit(item) } iv_menu_more.onClick { - val popupMenu = PopupMenu(context, it) - popupMenu.inflate(R.menu.book_source_item) - val qyMenu = popupMenu.menu.findItem(R.id.menu_enable_explore) - if (item.exploreUrl.isNullOrEmpty()) { - qyMenu.isVisible = false - } else { - if (item.enabledExplore) { - qyMenu.setTitle(R.string.disable_explore) - } else { - qyMenu.setTitle(R.string.enable_explore) - } - } - popupMenu.setOnMenuItemClickListener { menuItem -> - when (menuItem.itemId) { - R.id.menu_top -> callBack.toTop(item) - R.id.menu_del -> callBack.del(item) - R.id.menu_enable_explore -> { - item.enabledExplore = !item.enabledExplore - callBack.update(item) - upShowExplore(iv_explore, item) - } - } - true - } - popupMenu.show() + showMenu(iv_menu_more, getItem(holder.layoutPosition)) } upShowExplore(iv_explore, item) } else { @@ -127,6 +104,33 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : } } + private fun showMenu(view: View, source: BookSource?) { + if (source == null) return + val popupMenu = PopupMenu(context, view) + popupMenu.inflate(R.menu.book_source_item) + val qyMenu = popupMenu.menu.findItem(R.id.menu_enable_explore) + if (source.exploreUrl.isNullOrEmpty()) { + qyMenu.isVisible = false + } else { + if (source.enabledExplore) { + qyMenu.setTitle(R.string.disable_explore) + } else { + qyMenu.setTitle(R.string.enable_explore) + } + } + popupMenu.setOnMenuItemClickListener { menuItem -> + when (menuItem.itemId) { + R.id.menu_top -> callBack.toTop(source) + R.id.menu_del -> callBack.del(source) + R.id.menu_enable_explore -> { + callBack.update(source.copy(enabledExplore = !source.enabledExplore)) + } + } + true + } + popupMenu.show() + } + private fun upShowExplore(iv: ImageView, source: BookSource) { when { source.exploreUrl.isNullOrEmpty() -> {