From 458e761b458bb3cb41924e88643faf2ee7efd4d9 Mon Sep 17 00:00:00 2001 From: scb261 <65343233+scb261@users.noreply.github.com> Date: Sun, 27 Sep 2020 20:03:04 +0300 Subject: [PATCH] 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" --- .../ui/library/DeleteLibraryMangasDialog.kt | 25 ++++++++----------- .../tachiyomi/ui/library/LibraryController.kt | 4 +-- .../tachiyomi/ui/library/LibraryPresenter.kt | 17 +++++++------ app/src/main/res/values/arrays.xml | 5 ++++ app/src/main/res/values/strings.xml | 4 +-- 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/DeleteLibraryMangasDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/DeleteLibraryMangasDialog.kt index 969f19f578..4cd2f2bede 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/DeleteLibraryMangasDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/DeleteLibraryMangasDialog.kt @@ -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(bundle: Bundle? = null) : DialogController(bundle) where T : Controller, T : DeleteLibraryMangasDialog.Listener { @@ -21,25 +20,21 @@ class DeleteLibraryMangasDialog(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, deleteChapters: Boolean) + fun deleteMangas(mangas: List, deleteFromLibrary: Boolean, deleteChapters: Boolean) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 60cdfb9363..8aa545f3dc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -571,8 +571,8 @@ class LibraryController( destroyActionModeIfNeeded() } - override fun deleteMangasFromLibrary(mangas: List, deleteChapters: Boolean) { - presenter.removeMangaFromLibrary(mangas, deleteChapters) + override fun deleteMangas(mangas: List, deleteFromLibrary: Boolean, deleteChapters: Boolean) { + presenter.removeMangas(mangas, deleteFromLibrary, deleteChapters) destroyActionModeIfNeeded() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index e94530c141..7c99e69c92 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -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, deleteChapters: Boolean) { + fun removeMangas(mangas: List, deleteFromLibrary: Boolean, deleteChapters: Boolean) { launchIO { val mangaToDelete = mangas.distinctBy { it.id } - mangaToDelete.forEach { - it.favorite = false - it.removeCovers(coverCache) + if (deleteFromLibrary) { + mangaToDelete.forEach { + it.favorite = false + it.removeCovers(coverCache) + } + db.insertMangas(mangaToDelete).executeAsBlocking() } - db.insertMangas(mangaToDelete).executeAsBlocking() if (deleteChapters) { mangaToDelete.forEach { manga -> diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index eacccb2d18..d5b49c1752 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -86,4 +86,9 @@ @string/tapping_inverted_vertical @string/tapping_inverted_both + + + @string/manga_from_library + @string/downloaded_chapters + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6231321e58..ad558883c1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -445,8 +445,8 @@ Title or author… Updating category Local - Are you sure you want to remove selected manga? - Also delete downloaded chapters + Manga from library + Downloaded chapters Badges Tabs