Add a new manga category dialog (#221)

makes it more clear in browse and manga details when adding a manga
This commit is contained in:
Carlos 2020-04-27 21:57:45 -04:00 committed by GitHub
parent f645ac550e
commit 126cbbe36c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 94 additions and 10 deletions

View File

@ -0,0 +1,63 @@
package eu.kanade.tachiyomi.ui.library
import android.app.Dialog
import android.os.Bundle
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItemsMultiChoice
import com.bluelinelabs.conductor.Controller
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Category
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.ui.base.controller.DialogController
/**
* This class is used when adding new manga to your library
*/
class AddToLibraryCategoriesDialog<T>(bundle: Bundle? = null) :
DialogController(bundle) where T : Controller, T : AddToLibraryCategoriesDialog.Listener {
private var manga: Manga? = null
private var categories = emptyList<Category>()
private var preselected = emptyArray<Int>()
private var position = 0
constructor(
target: T,
manga: Manga,
categories: List<Category>,
preselected: Array<Int>,
position: Int = 0
) : this() {
this.manga = manga
this.categories = categories
this.preselected = preselected
this.position = position
targetController = target
}
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
return MaterialDialog(activity!!).title(R.string.add_to_library).message(R.string.add_to_categories)
.listItemsMultiChoice(
items = categories.map { it.name },
initialSelection = preselected.toIntArray(),
allowEmptySelection = true
) { _, selections, _ ->
val newCategories = selections.map { categories[it] }
(targetController as? Listener)?.updateCategoriesForManga(manga, newCategories)
}
.positiveButton(android.R.string.ok)
.negativeButton(android.R.string.cancel) {
(targetController as? Listener)?.addToLibraryCancelled(manga, position)
}
}
interface Listener {
fun updateCategoriesForManga(manga: Manga?, categories: List<Category>)
fun addToLibraryCancelled(manga: Manga?, position: Int)
}
}

View File

@ -77,6 +77,7 @@ import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.ui.base.controller.BaseController import eu.kanade.tachiyomi.ui.base.controller.BaseController
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
import eu.kanade.tachiyomi.ui.library.AddToLibraryCategoriesDialog
import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog
import eu.kanade.tachiyomi.ui.library.LibraryController import eu.kanade.tachiyomi.ui.library.LibraryController
import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.main.MainActivity
@ -128,7 +129,8 @@ class MangaDetailsController : BaseController,
ActionMode.Callback, ActionMode.Callback,
MangaDetailsAdapter.MangaDetailsInterface, MangaDetailsAdapter.MangaDetailsInterface,
FlexibleAdapter.OnItemMoveListener, FlexibleAdapter.OnItemMoveListener,
ChangeMangaCategoriesDialog.Listener { ChangeMangaCategoriesDialog.Listener,
AddToLibraryCategoriesDialog.Listener {
constructor( constructor(
manga: Manga?, manga: Manga?,
@ -1128,9 +1130,9 @@ class MangaDetailsController : BaseController,
categories.indexOfFirst { it.id == id }.takeIf { it != -1 } categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
}.toTypedArray() }.toTypedArray()
ChangeMangaCategoriesDialog( AddToLibraryCategoriesDialog(
this, this,
listOf(manga), manga,
categories, categories,
preselected preselected
).showDialog(router) ).showDialog(router)
@ -1176,6 +1178,14 @@ class MangaDetailsController : BaseController,
presenter.moveMangaToCategories(manga, categories) presenter.moveMangaToCategories(manga, categories)
} }
override fun updateCategoriesForManga(manga: Manga?, categories: List<Category>) {
manga?.let { presenter.moveMangaToCategories(manga, categories) }
}
override fun addToLibraryCancelled(manga: Manga?, position: Int) {
manga?.let { presenter.toggleFavorite() }
}
/** /**
* Copies a string to clipboard * Copies a string to clipboard
* *

View File

@ -27,7 +27,7 @@ import eu.kanade.tachiyomi.source.model.Filter
import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.NucleusController
import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog import eu.kanade.tachiyomi.ui.library.AddToLibraryCategoriesDialog
import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.ui.manga.MangaDetailsController import eu.kanade.tachiyomi.ui.manga.MangaDetailsController
import eu.kanade.tachiyomi.ui.source.SourceController import eu.kanade.tachiyomi.ui.source.SourceController
@ -61,7 +61,7 @@ open class BrowseSourceController(bundle: Bundle) :
FlexibleAdapter.OnItemClickListener, FlexibleAdapter.OnItemClickListener,
FlexibleAdapter.OnItemLongClickListener, FlexibleAdapter.OnItemLongClickListener,
FlexibleAdapter.EndlessScrollListener, FlexibleAdapter.EndlessScrollListener,
ChangeMangaCategoriesDialog.Listener { AddToLibraryCategoriesDialog.Listener {
constructor( constructor(
source: CatalogueSource, source: CatalogueSource,
@ -592,7 +592,7 @@ open class BrowseSourceController(bundle: Bundle) :
categories.indexOfFirst { it.id == id }.takeIf { it != -1 } categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
}.toTypedArray() }.toTypedArray()
ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected) AddToLibraryCategoriesDialog(this, manga, categories, preselected, position)
.showDialog(router) .showDialog(router)
} }
} }
@ -604,9 +604,18 @@ open class BrowseSourceController(bundle: Bundle) :
* @param mangas The list of manga to move to categories. * @param mangas The list of manga to move to categories.
* @param categories The list of categories where manga will be placed. * @param categories The list of categories where manga will be placed.
*/ */
override fun updateCategoriesForMangas(mangas: List<Manga>, categories: List<Category>) { override fun updateCategoriesForManga(manga: Manga?, categories: List<Category>) {
val manga = mangas.firstOrNull() ?: return manga?.let { presenter.updateMangaCategories(manga, categories) }
presenter.updateMangaCategories(manga, categories) }
/**
* Update manga to remove from favorites
*/
override fun addToLibraryCancelled(manga: Manga?, position: Int) {
manga?.let {
presenter.changeMangaFavorite(manga)
adapter?.notifyItemChanged(position)
}
} }
protected companion object { protected companion object {

View File

@ -400,6 +400,7 @@ open class BrowseSourcePresenter(
moveMangaToCategories(manga, selectedCategories.filter { it.id != 0 }) moveMangaToCategories(manga, selectedCategories.filter { it.id != 0 })
} else { } else {
if (!manga.favorite)
changeMangaFavorite(manga) changeMangaFavorite(manga)
} }
} }

View File

@ -81,6 +81,7 @@
<string name="manage_category">Manage category</string> <string name="manage_category">Manage category</string>
<string name="rename_category">Rename category</string> <string name="rename_category">Rename category</string>
<string name="move_to_categories">Move to categories</string> <string name="move_to_categories">Move to categories</string>
<string name="add_to_categories">Choose which categories to add this to. If none are selected, this will be added to the "default" category</string>
<string name="hide_categories">Hide categories</string> <string name="hide_categories">Hide categories</string>
<plurals name="category"> <plurals name="category">
<item quantity="one">%d category</item> <item quantity="one">%d category</item>