Add ability to choose what to remove for selected mangas (#3796)

* [wip] started to change manga delete options

* Change dialog for deleting selected manga

* Move array to appropriate file

* Make first option enabled by default

* Use radio buttons to reduce amount of clicks

* Revert "Use radio buttons to reduce amount of clicks"
This commit is contained in:
scb261 2020-09-27 20:03:04 +03:00 committed by GitHub
parent 371b0b2132
commit 458e761b45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 26 deletions

View File

@ -3,12 +3,11 @@ package eu.kanade.tachiyomi.ui.library
import android.app.Dialog
import android.os.Bundle
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.customview.customView
import com.afollestad.materialdialogs.list.listItemsMultiChoice
import com.bluelinelabs.conductor.Controller
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.widget.DialogCheckboxView
class DeleteLibraryMangasDialog<T>(bundle: Bundle? = null) :
DialogController(bundle) where T : Controller, T : DeleteLibraryMangasDialog.Listener {
@ -21,25 +20,21 @@ class DeleteLibraryMangasDialog<T>(bundle: Bundle? = null) :
}
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
val view = DialogCheckboxView(activity!!).apply {
setDescription(R.string.confirm_delete_manga)
setOptionDescription(R.string.also_delete_chapters)
}
return MaterialDialog(activity!!)
.title(R.string.action_remove)
.customView(
view = view,
horizontalPadding = true
)
.positiveButton(android.R.string.ok) {
val deleteChapters = view.isChecked()
(targetController as? Listener)?.deleteMangasFromLibrary(mangas, deleteChapters)
.listItemsMultiChoice(
R.array.delete_selected_mangas,
initialSelection = intArrayOf(0)
) { _, selections, _ ->
val deleteFromLibrary = 0 in selections
val deleteChapters = 1 in selections
(targetController as? Listener)?.deleteMangas(mangas, deleteFromLibrary, deleteChapters)
}
.positiveButton(android.R.string.ok)
.negativeButton(android.R.string.cancel)
}
interface Listener {
fun deleteMangasFromLibrary(mangas: List<Manga>, deleteChapters: Boolean)
fun deleteMangas(mangas: List<Manga>, deleteFromLibrary: Boolean, deleteChapters: Boolean)
}
}

View File

@ -571,8 +571,8 @@ class LibraryController(
destroyActionModeIfNeeded()
}
override fun deleteMangasFromLibrary(mangas: List<Manga>, deleteChapters: Boolean) {
presenter.removeMangaFromLibrary(mangas, deleteChapters)
override fun deleteMangas(mangas: List<Manga>, deleteFromLibrary: Boolean, deleteChapters: Boolean) {
presenter.removeMangas(mangas, deleteFromLibrary, deleteChapters)
destroyActionModeIfNeeded()
}

View File

@ -371,20 +371,23 @@ class LibraryPresenter(
}
/**
* Remove the selected manga from the library.
* Remove the selected manga.
*
* @param mangas the list of manga to delete.
* @param deleteChapters whether to also delete downloaded chapters.
* @param deleteFromLibrary whether to delete manga from library.
* @param deleteChapters whether to delete downloaded chapters.
*/
fun removeMangaFromLibrary(mangas: List<Manga>, deleteChapters: Boolean) {
fun removeMangas(mangas: List<Manga>, deleteFromLibrary: Boolean, deleteChapters: Boolean) {
launchIO {
val mangaToDelete = mangas.distinctBy { it.id }
if (deleteFromLibrary) {
mangaToDelete.forEach {
it.favorite = false
it.removeCovers(coverCache)
}
db.insertMangas(mangaToDelete).executeAsBlocking()
}
if (deleteChapters) {
mangaToDelete.forEach { manga ->

View File

@ -86,4 +86,9 @@
<item>@string/tapping_inverted_vertical</item>
<item>@string/tapping_inverted_both</item>
</string-array>
<string-array name="delete_selected_mangas">
<item>@string/manga_from_library</item>
<item>@string/downloaded_chapters</item>
</string-array>
</resources>

View File

@ -445,8 +445,8 @@
<string name="library_search_hint">Title or author…</string>
<string name="updating_category">Updating category</string>
<string name="local_source_badge">Local</string>
<string name="confirm_delete_manga">Are you sure you want to remove selected manga?</string>
<string name="also_delete_chapters">Also delete downloaded chapters</string>
<string name="manga_from_library">Manga from library</string>
<string name="downloaded_chapters">Downloaded chapters</string>
<string name="badges_header">Badges</string>
<string name="tabs_header">Tabs</string>