mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 11:17:25 +01:00
Bottom action menu in chapters list
This commit is contained in:
parent
d6ea69a115
commit
c63d8e7a30
@ -30,6 +30,7 @@ import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
|||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import eu.kanade.tachiyomi.util.view.getCoordinates
|
import eu.kanade.tachiyomi.util.view.getCoordinates
|
||||||
import eu.kanade.tachiyomi.util.view.snack
|
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.fab
|
||||||
import kotlinx.android.synthetic.main.chapters_controller.fast_scroller
|
import kotlinx.android.synthetic.main.chapters_controller.fast_scroller
|
||||||
import kotlinx.android.synthetic.main.chapters_controller.recycler
|
import kotlinx.android.synthetic.main.chapters_controller.recycler
|
||||||
@ -112,8 +113,9 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView(view: View) {
|
override fun onDestroyView(view: View) {
|
||||||
|
destroyActionModeIfNeeded()
|
||||||
|
action_toolbar.destroy()
|
||||||
adapter = null
|
adapter = null
|
||||||
actionMode = null
|
|
||||||
super.onDestroyView(view)
|
super.onDestroyView(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,6 +342,10 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
|
|||||||
private fun createActionModeIfNeeded() {
|
private fun createActionModeIfNeeded() {
|
||||||
if (actionMode == null) {
|
if (actionMode == null) {
|
||||||
actionMode = (activity as? AppCompatActivity)?.startSupportActionMode(this)
|
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 {
|
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
|
adapter?.mode = SelectableAdapter.Mode.MULTI
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -362,14 +368,8 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
|
|||||||
} else {
|
} else {
|
||||||
mode.title = count.toString()
|
mode.title = count.toString()
|
||||||
|
|
||||||
val chapters = getSelectedChapters()
|
// Hide FAB to avoid interfering with the bottom action toolbar
|
||||||
menu.findItem(R.id.action_download).isVisible = chapters.any { !it.isDownloaded }
|
fab.hide()
|
||||||
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
|
return false
|
||||||
}
|
}
|
||||||
@ -382,18 +382,21 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
|
|||||||
R.id.action_remove_bookmark -> bookmarkChapters(getSelectedChapters(), false)
|
R.id.action_remove_bookmark -> bookmarkChapters(getSelectedChapters(), false)
|
||||||
R.id.action_mark_as_read -> markAsRead(getSelectedChapters())
|
R.id.action_mark_as_read -> markAsRead(getSelectedChapters())
|
||||||
R.id.action_mark_as_unread -> markAsUnread(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_select_all -> selectAll()
|
||||||
R.id.action_mark_previous_as_read -> markPreviousAsRead(getSelectedChapters()[0])
|
|
||||||
else -> return false
|
else -> return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyActionMode(mode: ActionMode) {
|
override fun onDestroyActionMode(mode: ActionMode) {
|
||||||
|
action_toolbar.hide()
|
||||||
adapter?.mode = SelectableAdapter.Mode.SINGLE
|
adapter?.mode = SelectableAdapter.Mode.SINGLE
|
||||||
adapter?.clearSelection()
|
adapter?.clearSelection()
|
||||||
selectedItems.clear()
|
selectedItems.clear()
|
||||||
actionMode = null
|
actionMode = null
|
||||||
|
|
||||||
|
fab.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDetach(view: View) {
|
override fun onDetach(view: View) {
|
||||||
@ -441,12 +444,12 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
|
|||||||
deleteChapters(getSelectedChapters())
|
deleteChapters(getSelectedChapters())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun markPreviousAsRead(chapter: ChapterItem) {
|
private fun markPreviousAsRead(chapters: List<ChapterItem>) {
|
||||||
val adapter = adapter ?: return
|
val adapter = adapter ?: return
|
||||||
val chapters = if (presenter.sortDescending()) adapter.items.reversed() else adapter.items
|
val prevChapters = if (presenter.sortDescending()) adapter.items.reversed() else adapter.items
|
||||||
val chapterPos = chapters.indexOf(chapter)
|
val chapterPos = prevChapters.indexOf(chapters.last())
|
||||||
if (chapterPos != -1) {
|
if (chapterPos != -1) {
|
||||||
markAsRead(chapters.take(chapterPos))
|
markAsRead(prevChapters.take(chapterPos))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,12 @@
|
|||||||
app:fastScrollerBubbleEnabled="false"
|
app:fastScrollerBubbleEnabled="false"
|
||||||
tools:visibility="visible"/>
|
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
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
android:id="@+id/fab"
|
android:id="@+id/fab"
|
||||||
style="@style/Theme.Widget.FAB"
|
style="@style/Theme.Widget.FAB"
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
@ -7,43 +6,37 @@
|
|||||||
android:id="@+id/action_download"
|
android:id="@+id/action_download"
|
||||||
android:icon="@drawable/ic_file_download_white_24dp"
|
android:icon="@drawable/ic_file_download_white_24dp"
|
||||||
android:title="@string/action_download"
|
android:title="@string/action_download"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="always" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_delete"
|
android:id="@+id/action_delete"
|
||||||
android:icon="@drawable/ic_delete_white_24dp"
|
android:icon="@drawable/ic_delete_white_24dp"
|
||||||
android:title="@string/action_delete"
|
android:title="@string/action_delete"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="always" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_bookmark"
|
android:id="@+id/action_bookmark"
|
||||||
android:icon="@drawable/ic_bookmark_white_24dp"
|
android:icon="@drawable/ic_bookmark_white_24dp"
|
||||||
android:title="@string/action_bookmark"
|
android:title="@string/action_bookmark"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="always" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_remove_bookmark"
|
android:id="@+id/action_remove_bookmark"
|
||||||
android:icon="@drawable/ic_bookmark_border_white_24dp"
|
android:icon="@drawable/ic_bookmark_border_white_24dp"
|
||||||
android:title="@string/action_remove_bookmark"
|
android:title="@string/action_remove_bookmark"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="always" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_mark_as_read"
|
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"
|
android:title="@string/action_mark_as_read"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="always" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_mark_as_unread"
|
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"
|
android:title="@string/action_mark_as_unread"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="always" />
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/action_select_all"
|
|
||||||
android:icon="@drawable/ic_select_all_white_24dp"
|
|
||||||
android:title="@string/action_select_all"
|
|
||||||
app:showAsAction="ifRoom" />
|
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_mark_previous_as_read"
|
android:id="@+id/action_mark_previous_as_read"
|
||||||
|
Loading…
Reference in New Issue
Block a user