From 4061232fe34080200e6e9c7d57ec3670ab3f85ff Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 7 Mar 2020 22:46:13 -0500 Subject: [PATCH] Remove chapter updates popup menu --- .../ui/recent/updates/UpdatesController.kt | 13 +++-- .../ui/recent/updates/UpdatesHolder.kt | 52 ------------------- app/src/main/res/layout/updates_item.xml | 21 ++------ app/src/main/res/menu/chapter_recent.xml | 28 ---------- ...tion.xml => updates_chapter_selection.xml} | 1 - 5 files changed, 13 insertions(+), 102 deletions(-) delete mode 100644 app/src/main/res/menu/chapter_recent.xml rename app/src/main/res/menu/{chapter_recent_selection.xml => updates_chapter_selection.xml} (99%) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt index 4c8ebca1f..9f92fa9aa 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt @@ -296,7 +296,7 @@ class UpdatesController : NucleusController(), * @param menu menu object of ActionMode */ override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { - mode.menuInflater.inflate(R.menu.chapter_recent_selection, menu) + mode.menuInflater.inflate(R.menu.updates_chapter_selection, menu) adapter?.mode = SelectableAdapter.Mode.MULTI return true } @@ -308,7 +308,14 @@ class UpdatesController : NucleusController(), destroyActionModeIfNeeded() } else { mode.title = count.toString() + + val chapters = getSelectedChapters() + menu.findItem(R.id.action_download).isVisible = chapters.any { !it.isDownloaded } + menu.findItem(R.id.action_delete).isVisible = chapters.any { it.isDownloaded } + menu.findItem(R.id.action_mark_as_read).isVisible = chapters.any { !it.chapter.read } + menu.findItem(R.id.action_mark_as_unread).isVisible = chapters.any { it.chapter.read } } + return false } @@ -319,11 +326,11 @@ class UpdatesController : NucleusController(), */ override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { when (item.itemId) { - R.id.action_mark_as_read -> markAsRead(getSelectedChapters()) - R.id.action_mark_as_unread -> markAsUnread(getSelectedChapters()) R.id.action_download -> downloadChapters(getSelectedChapters()) R.id.action_delete -> ConfirmDeleteChaptersDialog(this, getSelectedChapters()) .showDialog(router) + R.id.action_mark_as_read -> markAsRead(getSelectedChapters()) + R.id.action_mark_as_unread -> markAsUnread(getSelectedChapters()) else -> return false } return true diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesHolder.kt index fcb5e04ec..9108eba17 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesHolder.kt @@ -1,14 +1,12 @@ package eu.kanade.tachiyomi.ui.recent.updates import android.view.View -import android.widget.PopupMenu import com.bumptech.glide.load.engine.DiskCacheStrategy import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.util.system.getResourceColor -import kotlinx.android.synthetic.main.updates_item.chapter_menu import kotlinx.android.synthetic.main.updates_item.chapter_title import kotlinx.android.synthetic.main.updates_item.download_text import kotlinx.android.synthetic.main.updates_item.manga_cover @@ -43,10 +41,6 @@ class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter) private var item: UpdatesItem? = null init { - // We need to post a Runnable to show the popup to make sure that the PopupMenu is - // correctly positioned. The reason being that the view may change position before the - // PopupMenu is shown. - chapter_menu.setOnClickListener { it.post { showPopupMenu(it) } } manga_cover.setOnClickListener { adapter.coverClickListener.onCoverClick(adapterPosition) } @@ -103,50 +97,4 @@ class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter) else -> text = "" } } - - /** - * Show pop up menu - * - * @param view view containing popup menu. - */ - private fun showPopupMenu(view: View) = item?.let { item -> - // Create a PopupMenu, giving it the clicked view for an anchor - val popup = PopupMenu(view.context, view) - - // Inflate our menu resource into the PopupMenu's Menu - popup.menuInflater.inflate(R.menu.chapter_recent, popup.menu) - - // Hide download and show delete if the chapter is downloaded and - if (item.isDownloaded) { - popup.menu.findItem(R.id.action_download).isVisible = false - popup.menu.findItem(R.id.action_delete).isVisible = true - } - - // Hide mark as unread when the chapter is unread - if (!item.chapter.read /*&& mangaChapter.chapter.last_page_read == 0*/) { - popup.menu.findItem(R.id.action_mark_as_unread).isVisible = false - } - - // Hide mark as read when the chapter is read - if (item.chapter.read) { - popup.menu.findItem(R.id.action_mark_as_read).isVisible = false - } - - // Set a listener so we are notified if a menu item is clicked - popup.setOnMenuItemClickListener { menuItem -> - with(adapter.controller) { - when (menuItem.itemId) { - R.id.action_download -> downloadChapter(item) - R.id.action_delete -> deleteChapter(item) - R.id.action_mark_as_read -> markAsRead(listOf(item)) - R.id.action_mark_as_unread -> markAsUnread(listOf(item)) - } - } - - true - } - - // Finally show the PopupMenu - popup.show() - } } diff --git a/app/src/main/res/layout/updates_item.xml b/app/src/main/res/layout/updates_item.xml index 2028c7919..bcfee460f 100644 --- a/app/src/main/res/layout/updates_item.xml +++ b/app/src/main/res/layout/updates_item.xml @@ -4,6 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="@dimen/material_component_lists_two_line_height" + android:paddingEnd="16dp" android:background="?attr/selectable_list_drawable"> - - diff --git a/app/src/main/res/menu/chapter_recent.xml b/app/src/main/res/menu/chapter_recent.xml deleted file mode 100644 index 7d88bc173..000000000 --- a/app/src/main/res/menu/chapter_recent.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - diff --git a/app/src/main/res/menu/chapter_recent_selection.xml b/app/src/main/res/menu/updates_chapter_selection.xml similarity index 99% rename from app/src/main/res/menu/chapter_recent_selection.xml rename to app/src/main/res/menu/updates_chapter_selection.xml index 6c4b09f16..baf1399be 100644 --- a/app/src/main/res/menu/chapter_recent_selection.xml +++ b/app/src/main/res/menu/updates_chapter_selection.xml @@ -1,5 +1,4 @@ -