From af2ef36d686e7e4c57e61fb54c51238ddeba91c4 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 8 Mar 2020 15:50:07 -0400 Subject: [PATCH] Bottom action menu in library --- .../tachiyomi/ui/library/LibraryController.kt | 22 ++++++++-- .../ui/recent/updates/UpdatesController.kt | 41 +++++++++---------- .../tachiyomi/widget/BottomActionMenu.kt | 5 +++ app/src/main/res/menu/library_selection.xml | 13 ++---- 4 files changed, 46 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 504f99129..516dad6e5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -32,6 +32,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.library.LibraryUpdateService import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault +import eu.kanade.tachiyomi.ui.base.controller.BottomActionMenuController import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.RootController import eu.kanade.tachiyomi.ui.base.controller.SecondaryDrawerController @@ -41,6 +42,7 @@ import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.inflate +import eu.kanade.tachiyomi.widget.BottomActionMenu import java.io.IOException import kotlinx.android.synthetic.main.library_controller.empty_view import kotlinx.android.synthetic.main.library_controller.library_pager @@ -58,6 +60,7 @@ class LibraryController( RootController, TabbedController, SecondaryDrawerController, + BottomActionMenuController, ActionMode.Callback, ChangeMangaCategoriesDialog.Listener, DeleteLibraryMangasDialog.Listener { @@ -72,6 +75,7 @@ class LibraryController( * Action mode for selections. */ private var actionMode: ActionMode? = null + private var bottomActionMenu: BottomActionMenu? = null /** * Library search query. @@ -179,9 +183,9 @@ class LibraryController( } override fun onDestroyView(view: View) { + destroyActionModeIfNeeded() adapter?.onDestroy() adapter = null - actionMode = null tabsVisibilitySubscription?.unsubscribe() tabsVisibilitySubscription = null super.onDestroyView(view) @@ -320,7 +324,7 @@ class LibraryController( /** * Destroys the action mode. */ - fun destroyActionModeIfNeeded() { + private fun destroyActionModeIfNeeded() { actionMode?.finish() } @@ -414,7 +418,7 @@ class LibraryController( } override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { - mode.menuInflater.inflate(R.menu.library_selection, menu) + mode.menuInflater.inflate(R.menu.generic_selection, menu) return true } @@ -425,7 +429,9 @@ class LibraryController( destroyActionModeIfNeeded() } else { mode.title = count.toString() - menu.findItem(R.id.action_edit_cover)?.isVisible = count == 1 + + bottomActionMenu?.show(mode.menuInflater) + bottomActionMenu?.findItem(R.id.action_edit_cover)?.isVisible = count == 1 } return false } @@ -445,12 +451,20 @@ class LibraryController( } override fun onDestroyActionMode(mode: ActionMode?) { + bottomActionMenu?.hide() // Clear all the manga selections and notify child views. selectedMangas.clear() selectionRelay.call(LibrarySelectionEvent.Cleared()) actionMode = null } + override fun configureBottomActionMenu(bottomActionMenu: BottomActionMenu) { + this.bottomActionMenu = bottomActionMenu + bottomActionMenu.configure( + R.menu.library_selection + ) { onActionItemClicked(actionMode!!, it!!) } + } + fun openManga(manga: Manga) { // Notify the presenter a manga is being opened. presenter.onOpenManga() 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 675f311af..c7fc7347b 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 @@ -107,8 +107,8 @@ class UpdatesController : NucleusController(), } override fun onDestroyView(view: View) { + destroyActionModeIfNeeded() adapter = null - actionMode = null super.onDestroyView(view) } @@ -116,7 +116,7 @@ class UpdatesController : NucleusController(), * Returns selected chapters * @return list of selected chapters */ - fun getSelectedChapters(): List { + private fun getSelectedChapters(): List { val adapter = adapter ?: return emptyList() return adapter.selectedPositions.mapNotNull { adapter.getItem(it) as? UpdatesItem } } @@ -175,7 +175,7 @@ class UpdatesController : NucleusController(), * Download selected items * @param chapters list of selected [UpdatesItem]s */ - fun downloadChapters(chapters: List) { + private fun downloadChapters(chapters: List) { presenter.downloadChapters(chapters) } @@ -216,13 +216,21 @@ class UpdatesController : NucleusController(), * Mark chapter as read * @param chapters list of chapters */ - fun markAsRead(chapters: List) { + private fun markAsRead(chapters: List) { presenter.markChapterRead(chapters, true) if (presenter.preferences.removeAfterMarkedAsRead()) { deleteChapters(chapters) } } + /** + * Mark chapter as unread + * @param chapters list of selected [UpdatesItem] + */ + private fun markAsUnread(chapters: List) { + presenter.markChapterRead(chapters, false) + } + override fun deleteChapters(chaptersToDelete: List) { DeletingChaptersDialog().showDialog(router) presenter.deleteChapters(chaptersToDelete) @@ -235,20 +243,12 @@ class UpdatesController : NucleusController(), actionMode?.finish() } - /** - * Mark chapter as unread - * @param chapters list of selected [UpdatesItem] - */ - fun markAsUnread(chapters: List) { - presenter.markChapterRead(chapters, false) - } - override fun onCoverClick(position: Int) { val chapterClicked = adapter?.getItem(position) as? UpdatesItem ?: return openManga(chapterClicked) } - fun openManga(chapter: UpdatesItem) { + private fun openManga(chapter: UpdatesItem) { router.pushController(MangaController(chapter.manga).withFadeTransaction()) } @@ -272,7 +272,7 @@ class UpdatesController : NucleusController(), /** * Called to dismiss deleting dialog */ - fun dismissDeletingDialog() { + private fun dismissDeletingDialog() { router.popControllerWithTag(DeletingChaptersDialog.TAG) } @@ -284,7 +284,6 @@ class UpdatesController : NucleusController(), override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { mode.menuInflater.inflate(R.menu.generic_selection, menu) adapter?.mode = SelectableAdapter.Mode.MULTI - return true } @@ -331,16 +330,16 @@ class UpdatesController : NucleusController(), actionMode = null } - private fun selectAll() { - val adapter = adapter ?: return - adapter.selectAll() - actionMode?.invalidate() - } - override fun configureBottomActionMenu(bottomActionMenu: BottomActionMenu) { this.bottomActionMenu = bottomActionMenu bottomActionMenu.configure( R.menu.updates_chapter_selection ) { onActionItemClicked(actionMode!!, it!!) } } + + private fun selectAll() { + val adapter = adapter ?: return + adapter.selectAll() + actionMode?.invalidate() + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/BottomActionMenu.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/BottomActionMenu.kt index 8ff64c63a..5d5584181 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/BottomActionMenu.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/BottomActionMenu.kt @@ -6,6 +6,7 @@ import android.view.MenuInflater import android.view.MenuItem import android.view.View import android.widget.FrameLayout +import androidx.annotation.IdRes import androidx.annotation.MenuRes import eu.kanade.tachiyomi.R import kotlinx.android.synthetic.main.common_bottom_action_menu.view.bottom_menu @@ -31,6 +32,10 @@ class BottomActionMenu @JvmOverloads constructor(context: Context, attrs: Attrib bottom_menu.setOnMenuItemClickListener(null) } + fun findItem(@IdRes itemId: Int): MenuItem? { + return bottom_menu.menu.findItem(itemId) + } + fun show(menuInflater: MenuInflater) { // Avoid re-inflating the menu if (bottom_menu.menu.size() == 0) { diff --git a/app/src/main/res/menu/library_selection.xml b/app/src/main/res/menu/library_selection.xml index c3acfec06..25d896ba4 100644 --- a/app/src/main/res/menu/library_selection.xml +++ b/app/src/main/res/menu/library_selection.xml @@ -1,5 +1,4 @@ - @@ -7,24 +6,18 @@ android:id="@+id/action_edit_cover" android:icon="@drawable/ic_create_white_24dp" android:title="@string/action_edit_cover" - app:showAsAction="ifRoom" /> + app:showAsAction="always" /> + app:showAsAction="always" /> - - + app:showAsAction="always" />