From af05c34da354d8849f68666f3601c0be2e5d4089 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 8 Mar 2020 12:16:17 -0400 Subject: [PATCH] Bottom action menu for updates --- .../ui/recent/updates/UpdatesController.kt | 48 +++++++++---------- .../main/res/layout/updates_controller.xml | 19 ++++++++ app/src/main/res/menu/generic_selection.xml | 11 +++++ .../res/menu/updates_chapter_selection.xml | 12 ++--- 4 files changed, 58 insertions(+), 32 deletions(-) create mode 100644 app/src/main/res/menu/generic_selection.xml 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 9f92fa9aaa..50f308f631 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 @@ -27,6 +27,8 @@ import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.util.system.notificationManager import eu.kanade.tachiyomi.util.system.toast +import kotlinx.android.synthetic.main.updates_controller.bottom_menu +import kotlinx.android.synthetic.main.updates_controller.bottom_menu_bar import kotlinx.android.synthetic.main.updates_controller.empty_view import kotlinx.android.synthetic.main.updates_controller.recycler import kotlinx.android.synthetic.main.updates_controller.swipe_refresh @@ -100,11 +102,14 @@ class UpdatesController : NucleusController(), // It can be a very long operation, so we disable swipe refresh and show a toast. swipe_refresh.isRefreshing = false } + + bottom_menu.setOnMenuItemClickListener { onActionItemClicked(actionMode!!, it) } } override fun onDestroyView(view: View) { adapter = null actionMode = null + bottom_menu.setOnMenuItemClickListener(null) super.onDestroyView(view) } @@ -171,7 +176,6 @@ class UpdatesController : NucleusController(), * @param chapters list of selected [UpdatesItem]s */ fun downloadChapters(chapters: List) { - destroyActionModeIfNeeded() presenter.downloadChapters(chapters) } @@ -220,7 +224,6 @@ class UpdatesController : NucleusController(), } override fun deleteChapters(chaptersToDelete: List) { - destroyActionModeIfNeeded() DeletingChaptersDialog().showDialog(router) presenter.deleteChapters(chaptersToDelete) } @@ -228,7 +231,7 @@ class UpdatesController : NucleusController(), /** * Destory [ActionMode] if it's shown */ - fun destroyActionModeIfNeeded() { + private fun destroyActionModeIfNeeded() { actionMode?.finish() } @@ -240,23 +243,6 @@ class UpdatesController : NucleusController(), presenter.markChapterRead(chapters, false) } - /** - * Start downloading chapter - * @param chapter selected chapter with manga - */ - fun downloadChapter(chapter: UpdatesItem) { - presenter.downloadChapters(listOf(chapter)) - } - - /** - * Start deleting chapter - * @param chapter selected chapter with manga - */ - fun deleteChapter(chapter: UpdatesItem) { - DeletingChaptersDialog().showDialog(router) - presenter.deleteChapters(listOf(chapter)) - } - override fun onCoverClick(position: Int) { val chapterClicked = adapter?.getItem(position) as? UpdatesItem ?: return openManga(chapterClicked) @@ -296,8 +282,14 @@ class UpdatesController : NucleusController(), * @param menu menu object of ActionMode */ override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { - mode.menuInflater.inflate(R.menu.updates_chapter_selection, menu) + mode.menuInflater.inflate(R.menu.generic_selection, menu) adapter?.mode = SelectableAdapter.Mode.MULTI + + // Avoid reinflating the menu multiple times + if (bottom_menu.menu.size() == 0) { + mode.menuInflater.inflate(R.menu.updates_chapter_selection, bottom_menu.menu) + } + return true } @@ -309,11 +301,7 @@ class UpdatesController : NucleusController(), } 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 } + bottom_menu_bar.visibility = View.VISIBLE } return false @@ -326,6 +314,7 @@ class UpdatesController : NucleusController(), */ override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { when (item.itemId) { + R.id.action_select_all -> selectAll() R.id.action_download -> downloadChapters(getSelectedChapters()) R.id.action_delete -> ConfirmDeleteChaptersDialog(this, getSelectedChapters()) .showDialog(router) @@ -341,8 +330,15 @@ class UpdatesController : NucleusController(), * @param mode the ActionMode object */ override fun onDestroyActionMode(mode: ActionMode?) { + bottom_menu_bar.visibility = View.GONE adapter?.mode = SelectableAdapter.Mode.IDLE adapter?.clearSelection() actionMode = null } + + private fun selectAll() { + val adapter = adapter ?: return + adapter.selectAll() + actionMode?.invalidate() + } } diff --git a/app/src/main/res/layout/updates_controller.xml b/app/src/main/res/layout/updates_controller.xml index e9cb1dc2a2..49acd01fc2 100644 --- a/app/src/main/res/layout/updates_controller.xml +++ b/app/src/main/res/layout/updates_controller.xml @@ -1,6 +1,7 @@ @@ -23,6 +24,24 @@ android:layout_gravity="center" android:visibility="gone" /> + + + + + + diff --git a/app/src/main/res/menu/generic_selection.xml b/app/src/main/res/menu/generic_selection.xml new file mode 100644 index 0000000000..a00db717ac --- /dev/null +++ b/app/src/main/res/menu/generic_selection.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/app/src/main/res/menu/updates_chapter_selection.xml b/app/src/main/res/menu/updates_chapter_selection.xml index baf1399bee..742bc39f11 100644 --- a/app/src/main/res/menu/updates_chapter_selection.xml +++ b/app/src/main/res/menu/updates_chapter_selection.xml @@ -6,24 +6,24 @@ android:id="@+id/action_download" android:icon="@drawable/ic_file_download_white_24dp" android:title="@string/action_download" - app:showAsAction="ifRoom" /> + app:showAsAction="always" /> + app:showAsAction="always" /> + app:showAsAction="always" /> + app:showAsAction="always" />