mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 22:01:51 +01:00
Bottom action menu for updates
This commit is contained in:
parent
a4410f3a02
commit
af05c34da3
@ -27,6 +27,8 @@ import eu.kanade.tachiyomi.ui.manga.MangaController
|
|||||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||||
import eu.kanade.tachiyomi.util.system.notificationManager
|
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
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.empty_view
|
||||||
import kotlinx.android.synthetic.main.updates_controller.recycler
|
import kotlinx.android.synthetic.main.updates_controller.recycler
|
||||||
import kotlinx.android.synthetic.main.updates_controller.swipe_refresh
|
import kotlinx.android.synthetic.main.updates_controller.swipe_refresh
|
||||||
@ -100,11 +102,14 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
|||||||
// It can be a very long operation, so we disable swipe refresh and show a toast.
|
// It can be a very long operation, so we disable swipe refresh and show a toast.
|
||||||
swipe_refresh.isRefreshing = false
|
swipe_refresh.isRefreshing = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bottom_menu.setOnMenuItemClickListener { onActionItemClicked(actionMode!!, it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView(view: View) {
|
override fun onDestroyView(view: View) {
|
||||||
adapter = null
|
adapter = null
|
||||||
actionMode = null
|
actionMode = null
|
||||||
|
bottom_menu.setOnMenuItemClickListener(null)
|
||||||
super.onDestroyView(view)
|
super.onDestroyView(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +176,6 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
|||||||
* @param chapters list of selected [UpdatesItem]s
|
* @param chapters list of selected [UpdatesItem]s
|
||||||
*/
|
*/
|
||||||
fun downloadChapters(chapters: List<UpdatesItem>) {
|
fun downloadChapters(chapters: List<UpdatesItem>) {
|
||||||
destroyActionModeIfNeeded()
|
|
||||||
presenter.downloadChapters(chapters)
|
presenter.downloadChapters(chapters)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,7 +224,6 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun deleteChapters(chaptersToDelete: List<UpdatesItem>) {
|
override fun deleteChapters(chaptersToDelete: List<UpdatesItem>) {
|
||||||
destroyActionModeIfNeeded()
|
|
||||||
DeletingChaptersDialog().showDialog(router)
|
DeletingChaptersDialog().showDialog(router)
|
||||||
presenter.deleteChapters(chaptersToDelete)
|
presenter.deleteChapters(chaptersToDelete)
|
||||||
}
|
}
|
||||||
@ -228,7 +231,7 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
|||||||
/**
|
/**
|
||||||
* Destory [ActionMode] if it's shown
|
* Destory [ActionMode] if it's shown
|
||||||
*/
|
*/
|
||||||
fun destroyActionModeIfNeeded() {
|
private fun destroyActionModeIfNeeded() {
|
||||||
actionMode?.finish()
|
actionMode?.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,23 +243,6 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
|||||||
presenter.markChapterRead(chapters, false)
|
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) {
|
override fun onCoverClick(position: Int) {
|
||||||
val chapterClicked = adapter?.getItem(position) as? UpdatesItem ?: return
|
val chapterClicked = adapter?.getItem(position) as? UpdatesItem ?: return
|
||||||
openManga(chapterClicked)
|
openManga(chapterClicked)
|
||||||
@ -296,8 +282,14 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
|||||||
* @param menu menu object of ActionMode
|
* @param menu menu object of ActionMode
|
||||||
*/
|
*/
|
||||||
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
|
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
|
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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,11 +301,7 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
|||||||
} else {
|
} else {
|
||||||
mode.title = count.toString()
|
mode.title = count.toString()
|
||||||
|
|
||||||
val chapters = getSelectedChapters()
|
bottom_menu_bar.visibility = View.VISIBLE
|
||||||
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 }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
@ -326,6 +314,7 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
|||||||
*/
|
*/
|
||||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
|
R.id.action_select_all -> selectAll()
|
||||||
R.id.action_download -> downloadChapters(getSelectedChapters())
|
R.id.action_download -> downloadChapters(getSelectedChapters())
|
||||||
R.id.action_delete -> ConfirmDeleteChaptersDialog(this, getSelectedChapters())
|
R.id.action_delete -> ConfirmDeleteChaptersDialog(this, getSelectedChapters())
|
||||||
.showDialog(router)
|
.showDialog(router)
|
||||||
@ -341,8 +330,15 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
|||||||
* @param mode the ActionMode object
|
* @param mode the ActionMode object
|
||||||
*/
|
*/
|
||||||
override fun onDestroyActionMode(mode: ActionMode?) {
|
override fun onDestroyActionMode(mode: ActionMode?) {
|
||||||
|
bottom_menu_bar.visibility = View.GONE
|
||||||
adapter?.mode = SelectableAdapter.Mode.IDLE
|
adapter?.mode = SelectableAdapter.Mode.IDLE
|
||||||
adapter?.clearSelection()
|
adapter?.clearSelection()
|
||||||
actionMode = null
|
actionMode = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun selectAll() {
|
||||||
|
val adapter = adapter ?: return
|
||||||
|
adapter.selectAll()
|
||||||
|
actionMode?.invalidate()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/swipe_refresh"
|
android:id="@+id/swipe_refresh"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
@ -23,6 +24,24 @@
|
|||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.Toolbar
|
||||||
|
android:id="@+id/bottom_menu_bar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
android:layout_gravity="bottom"
|
||||||
|
android:background="?attr/colorPrimary"
|
||||||
|
android:theme="?attr/actionBarTheme"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:contentInsetStart="8dp"
|
||||||
|
app:contentInsetEnd="8dp">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.ActionMenuView
|
||||||
|
android:id="@+id/bottom_menu"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
</androidx.appcompat.widget.Toolbar>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
11
app/src/main/res/menu/generic_selection.xml
Normal file
11
app/src/main/res/menu/generic_selection.xml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?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">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_select_all"
|
||||||
|
android:icon="@drawable/ic_select_all_white_24dp"
|
||||||
|
android:title="@string/action_select_all"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
|
|
||||||
|
</menu>
|
@ -6,24 +6,24 @@
|
|||||||
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_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" />
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
|
Loading…
Reference in New Issue
Block a user