mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 19:31:48 +01:00
Add select inverse action
This commit is contained in:
parent
9c44cae5b8
commit
985bb44559
@ -133,6 +133,15 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
}
|
}
|
||||||
controller.invalidateActionMode()
|
controller.invalidateActionMode()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subscriptions += controller.selectInverseRelay
|
||||||
|
.filter { it == category.id }
|
||||||
|
.subscribe {
|
||||||
|
adapter.currentItems.forEach { item ->
|
||||||
|
controller.toggleSelection(item.manga)
|
||||||
|
}
|
||||||
|
controller.invalidateActionMode()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onRecycle() {
|
fun onRecycle() {
|
||||||
|
@ -100,6 +100,11 @@ class LibraryController(
|
|||||||
*/
|
*/
|
||||||
val selectAllRelay: PublishRelay<Int> = PublishRelay.create()
|
val selectAllRelay: PublishRelay<Int> = PublishRelay.create()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relay to notify the library's viewpager to select the inverse
|
||||||
|
*/
|
||||||
|
val selectInverseRelay: PublishRelay<Int> = PublishRelay.create()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of manga per row in grid mode.
|
* Number of manga per row in grid mode.
|
||||||
*/
|
*/
|
||||||
@ -407,6 +412,7 @@ class LibraryController(
|
|||||||
R.id.action_move_to_category -> showChangeMangaCategoriesDialog()
|
R.id.action_move_to_category -> showChangeMangaCategoriesDialog()
|
||||||
R.id.action_delete -> showDeleteMangaDialog()
|
R.id.action_delete -> showDeleteMangaDialog()
|
||||||
R.id.action_select_all -> selectAllCategoryManga()
|
R.id.action_select_all -> selectAllCategoryManga()
|
||||||
|
R.id.action_select_inverse -> selectInverseCategoryManga()
|
||||||
else -> return false
|
else -> return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@ -445,6 +451,19 @@ class LibraryController(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggles the current selection state for a given manga.
|
||||||
|
*
|
||||||
|
* @param manga the manga whose selection to change.
|
||||||
|
*/
|
||||||
|
fun toggleSelection(manga: Manga) {
|
||||||
|
if (selectedMangas.add(manga)) {
|
||||||
|
selectionRelay.call(LibrarySelectionEvent.Selected(manga))
|
||||||
|
} else if (selectedMangas.remove(manga)) {
|
||||||
|
selectionRelay.call(LibrarySelectionEvent.Unselected(manga))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the selected manga to a list of categories.
|
* Move the selected manga to a list of categories.
|
||||||
*/
|
*/
|
||||||
@ -501,6 +520,12 @@ class LibraryController(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun selectInverseCategoryManga() {
|
||||||
|
adapter?.categories?.getOrNull(library_pager.currentItem)?.id?.let {
|
||||||
|
selectInverseRelay.call(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
if (requestCode == REQUEST_IMAGE_OPEN) {
|
if (requestCode == REQUEST_IMAGE_OPEN) {
|
||||||
if (data == null || resultCode != Activity.RESULT_OK) return
|
if (data == null || resultCode != Activity.RESULT_OK) return
|
||||||
|
@ -399,6 +399,8 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
|
|||||||
|
|
||||||
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_select_inverse -> selectInverse()
|
||||||
R.id.action_download -> downloadChapters(getSelectedChapters())
|
R.id.action_download -> downloadChapters(getSelectedChapters())
|
||||||
R.id.action_delete -> showDeleteChaptersConfirmationDialog()
|
R.id.action_delete -> showDeleteChaptersConfirmationDialog()
|
||||||
R.id.action_bookmark -> bookmarkChapters(getSelectedChapters(), true)
|
R.id.action_bookmark -> bookmarkChapters(getSelectedChapters(), true)
|
||||||
@ -406,7 +408,6 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
|
|||||||
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_mark_previous_as_read -> markPreviousAsRead(getSelectedChapters())
|
||||||
R.id.action_select_all -> selectAll()
|
|
||||||
else -> return false
|
else -> return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@ -436,6 +437,15 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
|
|||||||
actionMode?.invalidate()
|
actionMode?.invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun selectInverse() {
|
||||||
|
val adapter = adapter ?: return
|
||||||
|
for (i in 0..adapter.itemCount) {
|
||||||
|
adapter.toggleSelection(i)
|
||||||
|
}
|
||||||
|
actionMode?.invalidate()
|
||||||
|
adapter.notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
private fun markAsRead(chapters: List<ChapterItem>) {
|
private fun markAsRead(chapters: List<ChapterItem>) {
|
||||||
presenter.markChaptersRead(chapters, true)
|
presenter.markChaptersRead(chapters, true)
|
||||||
if (presenter.preferences.removeAfterMarkedAsRead()) {
|
if (presenter.preferences.removeAfterMarkedAsRead()) {
|
||||||
|
@ -338,6 +338,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_select_all -> selectAll()
|
||||||
|
R.id.action_select_inverse -> selectInverse()
|
||||||
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)
|
||||||
@ -364,4 +365,13 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
|||||||
adapter.selectAll()
|
adapter.selectAll()
|
||||||
actionMode?.invalidate()
|
actionMode?.invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun selectInverse() {
|
||||||
|
val adapter = adapter ?: return
|
||||||
|
for (i in 0..adapter.itemCount) {
|
||||||
|
adapter.toggleSelection(i)
|
||||||
|
}
|
||||||
|
actionMode?.invalidate()
|
||||||
|
adapter.notifyDataSetChanged()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
9
app/src/main/res/drawable/ic_flip_to_back_24dp.xml
Normal file
9
app/src/main/res/drawable/ic_flip_to_back_24dp.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:pathData="M9,7L7,7v2h2L9,7zM9,11L7,11v2h2v-2zM9,3c-1.11,0 -2,0.9 -2,2h2L9,3zM13,15h-2v2h2v-2zM19,3v2h2c0,-1.1 -0.9,-2 -2,-2zM13,3h-2v2h2L13,3zM9,17v-2L7,15c0,1.1 0.89,2 2,2zM19,13h2v-2h-2v2zM19,9h2L21,7h-2v2zM19,17c1.1,0 2,-0.9 2,-2h-2v2zM5,7L3,7v12c0,1.1 0.89,2 2,2h12v-2L5,19L5,7zM15,5h2L17,3h-2v2zM15,17h2v-2h-2v2z"
|
||||||
|
android:fillColor="#000000"/>
|
||||||
|
</vector>
|
@ -9,4 +9,11 @@
|
|||||||
app:iconTint="?attr/colorOnPrimary"
|
app:iconTint="?attr/colorOnPrimary"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="ifRoom" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_select_inverse"
|
||||||
|
android:icon="@drawable/ic_flip_to_back_24dp"
|
||||||
|
android:title="@string/action_select_inverse"
|
||||||
|
app:iconTint="?attr/colorOnPrimary"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
<string name="action_search">Search</string>
|
<string name="action_search">Search</string>
|
||||||
<string name="action_global_search">Global search</string>
|
<string name="action_global_search">Global search</string>
|
||||||
<string name="action_select_all">Select all</string>
|
<string name="action_select_all">Select all</string>
|
||||||
|
<string name="action_select_inverse">Select inverse</string>
|
||||||
<string name="action_mark_as_read">Mark as read</string>
|
<string name="action_mark_as_read">Mark as read</string>
|
||||||
<string name="action_mark_as_unread">Mark as unread</string>
|
<string name="action_mark_as_unread">Mark as unread</string>
|
||||||
<string name="action_mark_previous_as_read">Mark previous as read</string>
|
<string name="action_mark_previous_as_read">Mark previous as read</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user