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 ed823839a..f0d2bb3f0 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 @@ -11,7 +11,6 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.BookSource import io.legado.app.help.ItemTouchCallback.OnItemTouchCallbackListener import io.legado.app.lib.theme.backgroundColor -import io.legado.app.utils.invisible import io.legado.app.utils.visible import kotlinx.android.synthetic.main.item_book_source.view.* import org.jetbrains.anko.sdk27.listeners.onClick @@ -82,20 +81,31 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : 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) + iv_explore.visible(item.showExplore()) + } } true } popupMenu.show() } - if (item.showExplore()) { - iv_explore.visible() - } else { - iv_explore.invisible() - } + iv_explore.visible(item.showExplore()) } else { payload.keySet().map { when (it) { @@ -107,16 +117,11 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : String.format("%s (%s)", item.bookSourceName, item.bookSourceGroup) } "enabled" -> swt_enabled.isChecked = payload.getBoolean(it) - "showExplore" -> if (payload.getBoolean(it)) { - iv_explore.visible() - } else { - iv_explore.invisible() - } + "showExplore" -> iv_explore.visible(payload.getBoolean(it)) } } } } - } override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/DiffCallBack.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/DiffCallBack.kt index cdb56bc48..9ed40b625 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/DiffCallBack.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/DiffCallBack.kt @@ -32,6 +32,9 @@ class DiffCallBack( return false if (oldItem.enabled != newItem.enabled) return false + if (oldItem.showExplore() != newItem.showExplore()) { + return false + } return true } diff --git a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt index 403f0d40c..5d191609f 100644 --- a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt @@ -49,6 +49,14 @@ fun View.visible() { visibility = VISIBLE } +fun View.visible(visible: Boolean) { + visibility = if (visible) { + VISIBLE + } else { + INVISIBLE + } +} + fun View.screenshot(): Bitmap? { return runCatching { val screenshot = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) diff --git a/app/src/main/res/menu/book_source_item.xml b/app/src/main/res/menu/book_source_item.xml index 17483eeec..a3cdcd258 100644 --- a/app/src/main/res/menu/book_source_item.xml +++ b/app/src/main/res/menu/book_source_item.xml @@ -9,4 +9,8 @@ android:id="@+id/menu_del" android:title="@string/delete" /> + + \ No newline at end of file