Skip to content

Commit

Permalink
Add ability to choose what to remove for selected mangas (#3796)
Browse files Browse the repository at this point in the history
* [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"
  • Loading branch information
scb261 authored Sep 27, 2020
1 parent 371b0b2 commit 458e761
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

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 ->
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down

0 comments on commit 458e761

Please sign in to comment.