mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Bottom action menu in chapters list
This commit is contained in:
parent
d6ea69a115
commit
c63d8e7a30
3 changed files with 32 additions and 30 deletions
|
@ -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<ChaptersPresenter>(),
|
|||
}
|
||||
|
||||
override fun onDestroyView(view: View) {
|
||||
destroyActionModeIfNeeded()
|
||||
action_toolbar.destroy()
|
||||
adapter = null
|
||||
actionMode = null
|
||||
super.onDestroyView(view)
|
||||
}
|
||||
|
||||
|
@ -340,6 +342,10 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
|
|||
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<ChaptersPresenter>(),
|
|||
}
|
||||
|
||||
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<ChaptersPresenter>(),
|
|||
} 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<ChaptersPresenter>(),
|
|||
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<ChaptersPresenter>(),
|
|||
deleteChapters(getSelectedChapters())
|
||||
}
|
||||
|
||||
private fun markPreviousAsRead(chapter: ChapterItem) {
|
||||
private fun markPreviousAsRead(chapters: List<ChapterItem>) {
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,12 @@
|
|||
app:fastScrollerBubbleEnabled="false"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<eu.kanade.tachiyomi.widget.ActionToolbar
|
||||
android:id="@+id/action_toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
style="@style/Theme.Widget.FAB"
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
|
@ -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" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_delete"
|
||||
android:icon="@drawable/ic_delete_white_24dp"
|
||||
android:title="@string/action_delete"
|
||||
app:showAsAction="ifRoom" />
|
||||
app:showAsAction="always" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_bookmark"
|
||||
android:icon="@drawable/ic_bookmark_white_24dp"
|
||||
android:title="@string/action_bookmark"
|
||||
app:showAsAction="ifRoom" />
|
||||
app:showAsAction="always" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_remove_bookmark"
|
||||
android:icon="@drawable/ic_bookmark_border_white_24dp"
|
||||
android:title="@string/action_remove_bookmark"
|
||||
app:showAsAction="ifRoom" />
|
||||
app:showAsAction="always" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_mark_as_read"
|
||||
android:icon="@drawable/ic_done_all_white_24dp"
|
||||
android:icon="@drawable/ic_done_all_grey_24dp"
|
||||
android:title="@string/action_mark_as_read"
|
||||
app:showAsAction="ifRoom" />
|
||||
app:showAsAction="always" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_mark_as_unread"
|
||||
android:icon="@drawable/ic_done_all_grey_24dp"
|
||||
android:icon="@drawable/ic_done_all_white_24dp"
|
||||
android:title="@string/action_mark_as_unread"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_select_all"
|
||||
android:icon="@drawable/ic_select_all_white_24dp"
|
||||
android:title="@string/action_select_all"
|
||||
app:showAsAction="ifRoom" />
|
||||
app:showAsAction="always" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_mark_previous_as_read"
|
||||
|
|
Loading…
Reference in a new issue