From c275adbb91760911a6b134584a6bb4ccfe0319c2 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 7 Mar 2020 23:00:29 -0500 Subject: [PATCH] Remove chapter item popup menu --- .../ui/manga/chapter/ChapterHolder.kt | 52 +------------------ .../ui/manga/chapter/ChaptersAdapter.kt | 7 --- .../ui/manga/chapter/ChaptersController.kt | 29 ++++------- .../res/drawable/ic_more_vert_black_24dp.xml | 9 ---- app/src/main/res/layout/chapters_item.xml | 16 +----- app/src/main/res/menu/chapter_selection.xml | 11 +++- app/src/main/res/menu/chapter_single.xml | 37 ------------- app/src/main/res/values/attrs.xml | 1 - app/src/main/res/values/strings.xml | 1 - app/src/main/res/values/themes.xml | 2 - 10 files changed, 21 insertions(+), 144 deletions(-) delete mode 100644 app/src/main/res/drawable/ic_more_vert_black_24dp.xml delete mode 100644 app/src/main/res/menu/chapter_single.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt index 2175f228d..ff2c01768 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt @@ -1,29 +1,20 @@ package eu.kanade.tachiyomi.ui.manga.chapter import android.view.View -import android.widget.PopupMenu import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import java.util.Date import kotlinx.android.synthetic.main.chapters_item.chapter_description -import kotlinx.android.synthetic.main.chapters_item.chapter_menu import kotlinx.android.synthetic.main.chapters_item.chapter_title import kotlinx.android.synthetic.main.chapters_item.download_text class ChapterHolder( - private val view: View, + view: View, private val adapter: ChaptersAdapter ) : BaseFlexibleViewHolder(view, adapter) { - 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) } } - } - fun bind(item: ChapterItem, manga: Manga) { val chapter = item.chapter @@ -73,45 +64,4 @@ class ChapterHolder( else -> text = "" } } - - private fun showPopupMenu(view: View) { - val item = adapter.getItem(adapterPosition) ?: return - - // 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_single, popup.menu) - - val chapter = item.chapter - - // Hide download and show delete if the chapter is downloaded - if (item.isDownloaded) { - popup.menu.findItem(R.id.action_download).isVisible = false - popup.menu.findItem(R.id.action_delete).isVisible = true - } - - // Hide bookmark if bookmark - popup.menu.findItem(R.id.action_bookmark).isVisible = !chapter.bookmark - popup.menu.findItem(R.id.action_remove_bookmark).isVisible = chapter.bookmark - - // Hide mark as unread when the chapter is unread - if (!chapter.read && 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 (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 -> - adapter.menuItemListener.onMenuItemClick(adapterPosition, menuItem) - true - } - - // Finally show the PopupMenu - popup.show() - } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersAdapter.kt index c6ecf7efc..6866be675 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersAdapter.kt @@ -1,7 +1,6 @@ package eu.kanade.tachiyomi.ui.manga.chapter import android.content.Context -import android.view.MenuItem import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper @@ -21,8 +20,6 @@ class ChaptersAdapter( var items: List = emptyList() - val menuItemListener: OnMenuItemClickListener = controller - val readColor = context.getResourceColor(android.R.attr.textColorHint) val unreadColor = context.getResourceColor(android.R.attr.textColorPrimary) @@ -42,8 +39,4 @@ class ChaptersAdapter( fun indexOf(item: ChapterItem): Int { return items.indexOf(item) } - - interface OnMenuItemClickListener { - fun onMenuItemClick(position: Int, item: MenuItem) - } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt index 70e03d080..588ff0563 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt @@ -42,7 +42,6 @@ class ChaptersController : NucleusController(), ActionMode.Callback, FlexibleAdapter.OnItemClickListener, FlexibleAdapter.OnItemLongClickListener, - ChaptersAdapter.OnMenuItemClickListener, DownloadCustomChaptersDialog.Listener, DeleteChaptersDialog.Listener { @@ -364,6 +363,15 @@ class ChaptersController : 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_bookmark).isVisible = chapters.any { !it.chapter.bookmark } + menu.findItem(R.id.action_remove_bookmark).isVisible = chapters.any { it.chapter.bookmark } + 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 } + menu.findItem(R.id.action_mark_previous_as_read).isVisible = count == 1 } return false } @@ -377,6 +385,7 @@ class ChaptersController : NucleusController(), R.id.action_mark_as_read -> markAsRead(getSelectedChapters()) R.id.action_mark_as_unread -> markAsUnread(getSelectedChapters()) R.id.action_select_all -> selectAll() + R.id.action_mark_previous_as_read -> markPreviousAsRead(getSelectedChapters()[0]) else -> return false } return true @@ -394,21 +403,6 @@ class ChaptersController : NucleusController(), super.onDetach(view) } - override fun onMenuItemClick(position: Int, item: MenuItem) { - val chapter = adapter?.getItem(position) ?: return - val chapters = listOf(chapter) - - when (item.itemId) { - R.id.action_download -> downloadChapters(chapters) - R.id.action_delete -> deleteChapters(chapters) - R.id.action_bookmark -> bookmarkChapters(chapters, true) - R.id.action_remove_bookmark -> bookmarkChapters(chapters, false) - R.id.action_mark_as_read -> markAsRead(chapters) - R.id.action_mark_as_unread -> markAsUnread(chapters) - R.id.action_mark_previous_as_read -> markPreviousAsRead(chapter) - } - } - // SELECTION MODE ACTIONS private fun selectAll() { @@ -431,7 +425,6 @@ class ChaptersController : NucleusController(), private fun downloadChapters(chapters: List) { val view = view - destroyActionModeIfNeeded() presenter.downloadChapters(chapters) if (view != null && !presenter.manga.favorite) { recycler?.snack(view.context.getString(R.string.snack_add_to_library), Snackbar.LENGTH_INDEFINITE) { @@ -460,12 +453,10 @@ class ChaptersController : NucleusController(), } private fun bookmarkChapters(chapters: List, bookmarked: Boolean) { - destroyActionModeIfNeeded() presenter.bookmarkChapters(chapters, bookmarked) } fun deleteChapters(chapters: List) { - destroyActionModeIfNeeded() if (chapters.isEmpty()) return DeletingChaptersDialog().showDialog(router) diff --git a/app/src/main/res/drawable/ic_more_vert_black_24dp.xml b/app/src/main/res/drawable/ic_more_vert_black_24dp.xml deleted file mode 100644 index 0ef23a567..000000000 --- a/app/src/main/res/drawable/ic_more_vert_black_24dp.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/layout/chapters_item.xml b/app/src/main/res/layout/chapters_item.xml index 294f51358..3b1620232 100644 --- a/app/src/main/res/layout/chapters_item.xml +++ b/app/src/main/res/layout/chapters_item.xml @@ -15,7 +15,7 @@ android:layout_marginTop="12dp" android:ellipsize="end" android:maxLines="1" - app:layout_constraintEnd_toStartOf="@+id/chapter_menu" + app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" tools:text="Title" /> @@ -34,20 +34,6 @@ app:layout_constraintStart_toStartOf="parent" tools:text="22/02/2016 • Scanlator • Page: 45" /> - - + app:showAsAction="ifRoom" /> + app:showAsAction="ifRoom" /> + + diff --git a/app/src/main/res/menu/chapter_single.xml b/app/src/main/res/menu/chapter_single.xml deleted file mode 100644 index 0f1f14e1d..000000000 --- a/app/src/main/res/menu/chapter_single.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 978a24851..3eecbfdbb 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -25,7 +25,6 @@ - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e4395bb17..e0a927a65 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -29,7 +29,6 @@ Settings - Menu Filter Downloaded Bookmarked diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 529aa4a96..0ad8b28da 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -39,7 +39,6 @@ @drawable/library_item_selector_light @color/textColorPrimaryLight @color/dialogLight - @color/iconColorLight @android:color/white @color/textColorHintDark @@ -88,7 +87,6 @@ @drawable/library_item_selector_dark @color/textColorPrimaryDark @color/dialogDark - @color/iconColorDark @android:color/white @color/textColorHintDark