mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-24 13:31:51 +01:00
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:
parent
f645ac550e
commit
126cbbe36c
@ -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)
|
||||
}
|
||||
}
|
@ -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.DialogController
|
||||
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.LibraryController
|
||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||
@ -128,7 +129,8 @@ class MangaDetailsController : BaseController,
|
||||
ActionMode.Callback,
|
||||
MangaDetailsAdapter.MangaDetailsInterface,
|
||||
FlexibleAdapter.OnItemMoveListener,
|
||||
ChangeMangaCategoriesDialog.Listener {
|
||||
ChangeMangaCategoriesDialog.Listener,
|
||||
AddToLibraryCategoriesDialog.Listener {
|
||||
|
||||
constructor(
|
||||
manga: Manga?,
|
||||
@ -1128,9 +1130,9 @@ class MangaDetailsController : BaseController,
|
||||
categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
|
||||
}.toTypedArray()
|
||||
|
||||
ChangeMangaCategoriesDialog(
|
||||
AddToLibraryCategoriesDialog(
|
||||
this,
|
||||
listOf(manga),
|
||||
manga,
|
||||
categories,
|
||||
preselected
|
||||
).showDialog(router)
|
||||
@ -1176,6 +1178,14 @@ class MangaDetailsController : BaseController,
|
||||
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
|
||||
*
|
||||
|
@ -27,7 +27,7 @@ import eu.kanade.tachiyomi.source.model.Filter
|
||||
import eu.kanade.tachiyomi.source.model.FilterList
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
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.manga.MangaDetailsController
|
||||
import eu.kanade.tachiyomi.ui.source.SourceController
|
||||
@ -61,7 +61,7 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||
FlexibleAdapter.OnItemClickListener,
|
||||
FlexibleAdapter.OnItemLongClickListener,
|
||||
FlexibleAdapter.EndlessScrollListener,
|
||||
ChangeMangaCategoriesDialog.Listener {
|
||||
AddToLibraryCategoriesDialog.Listener {
|
||||
|
||||
constructor(
|
||||
source: CatalogueSource,
|
||||
@ -592,7 +592,7 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||
categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
|
||||
}.toTypedArray()
|
||||
|
||||
ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected)
|
||||
AddToLibraryCategoriesDialog(this, manga, categories, preselected, position)
|
||||
.showDialog(router)
|
||||
}
|
||||
}
|
||||
@ -604,9 +604,18 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||
* @param mangas The list of manga to move to categories.
|
||||
* @param categories The list of categories where manga will be placed.
|
||||
*/
|
||||
override fun updateCategoriesForMangas(mangas: List<Manga>, categories: List<Category>) {
|
||||
val manga = mangas.firstOrNull() ?: return
|
||||
presenter.updateMangaCategories(manga, categories)
|
||||
override fun updateCategoriesForManga(manga: Manga?, categories: List<Category>) {
|
||||
manga?.let { 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 {
|
||||
|
@ -400,7 +400,8 @@ open class BrowseSourcePresenter(
|
||||
|
||||
moveMangaToCategories(manga, selectedCategories.filter { it.id != 0 })
|
||||
} else {
|
||||
changeMangaFavorite(manga)
|
||||
if (!manga.favorite)
|
||||
changeMangaFavorite(manga)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,6 +81,7 @@
|
||||
<string name="manage_category">Manage category</string>
|
||||
<string name="rename_category">Rename category</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>
|
||||
<plurals name="category">
|
||||
<item quantity="one">%d category</item>
|
||||
|
Loading…
Reference in New Issue
Block a user