From c63d8e7a302455a8f825caad6eef8c78c8b3ac19 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 8 Mar 2020 17:37:42 -0400 Subject: [PATCH] Bottom action menu in chapters list --- .../ui/manga/chapter/ChaptersController.kt | 33 ++++++++++--------- .../main/res/layout/chapters_controller.xml | 6 ++++ app/src/main/res/menu/chapter_selection.xml | 23 +++++-------- 3 files changed, 32 insertions(+), 30 deletions(-) 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 4cbcfd1f0a..d392b0b4ff 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 @@ -30,6 +30,7 @@ import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.getCoordinates import eu.kanade.tachiyomi.util.view.snack +import kotlinx.android.synthetic.main.chapters_controller.action_toolbar import kotlinx.android.synthetic.main.chapters_controller.fab import kotlinx.android.synthetic.main.chapters_controller.fast_scroller import kotlinx.android.synthetic.main.chapters_controller.recycler @@ -112,8 +113,9 @@ class ChaptersController : NucleusController(), } override fun onDestroyView(view: View) { + destroyActionModeIfNeeded() + action_toolbar.destroy() adapter = null - actionMode = null super.onDestroyView(view) } @@ -340,6 +342,10 @@ class ChaptersController : NucleusController(), private fun createActionModeIfNeeded() { if (actionMode == null) { actionMode = (activity as? AppCompatActivity)?.startSupportActionMode(this) + action_toolbar.show( + actionMode!!, + R.menu.chapter_selection + ) { onActionItemClicked(actionMode!!, it!!) } } } @@ -349,7 +355,7 @@ class ChaptersController : NucleusController(), } override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { - mode.menuInflater.inflate(R.menu.chapter_selection, menu) + mode.menuInflater.inflate(R.menu.generic_selection, menu) adapter?.mode = SelectableAdapter.Mode.MULTI return true } @@ -362,14 +368,8 @@ class ChaptersController : 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_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 + // Hide FAB to avoid interfering with the bottom action toolbar + fab.hide() } return false } @@ -382,18 +382,21 @@ class ChaptersController : NucleusController(), R.id.action_remove_bookmark -> bookmarkChapters(getSelectedChapters(), false) R.id.action_mark_as_read -> markAsRead(getSelectedChapters()) R.id.action_mark_as_unread -> markAsUnread(getSelectedChapters()) + R.id.action_mark_previous_as_read -> markPreviousAsRead(getSelectedChapters()) R.id.action_select_all -> selectAll() - R.id.action_mark_previous_as_read -> markPreviousAsRead(getSelectedChapters()[0]) else -> return false } return true } override fun onDestroyActionMode(mode: ActionMode) { + action_toolbar.hide() adapter?.mode = SelectableAdapter.Mode.SINGLE adapter?.clearSelection() selectedItems.clear() actionMode = null + + fab.show() } override fun onDetach(view: View) { @@ -441,12 +444,12 @@ class ChaptersController : NucleusController(), deleteChapters(getSelectedChapters()) } - private fun markPreviousAsRead(chapter: ChapterItem) { + private fun markPreviousAsRead(chapters: List) { val adapter = adapter ?: return - val chapters = if (presenter.sortDescending()) adapter.items.reversed() else adapter.items - val chapterPos = chapters.indexOf(chapter) + val prevChapters = if (presenter.sortDescending()) adapter.items.reversed() else adapter.items + val chapterPos = prevChapters.indexOf(chapters.last()) if (chapterPos != -1) { - markAsRead(chapters.take(chapterPos)) + markAsRead(prevChapters.take(chapterPos)) } } diff --git a/app/src/main/res/layout/chapters_controller.xml b/app/src/main/res/layout/chapters_controller.xml index 472b12213a..8bef044adb 100644 --- a/app/src/main/res/layout/chapters_controller.xml +++ b/app/src/main/res/layout/chapters_controller.xml @@ -44,6 +44,12 @@ app:fastScrollerBubbleEnabled="false" tools:visibility="visible"/> + + - @@ -7,43 +6,37 @@ 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" /> + app:showAsAction="always" /> - - + app:showAsAction="always" />