Removing repeated manga paramater in manga presenter
This commit is contained in:
parent
161b741d04
commit
da7adb8197
2 changed files with 12 additions and 13 deletions
|
@ -1088,7 +1088,7 @@ class MangaDetailsController : BaseController,
|
||||||
presenter.toggleFavorite()
|
presenter.toggleFavorite()
|
||||||
showAddedSnack()
|
showAddedSnack()
|
||||||
}
|
}
|
||||||
val ids = presenter.getMangaCategoryIds(manga)
|
val ids = presenter.getMangaCategoryIds()
|
||||||
val preselected = ids.mapNotNull { id ->
|
val preselected = ids.mapNotNull { id ->
|
||||||
categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
|
categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
|
||||||
}.toTypedArray()
|
}.toTypedArray()
|
||||||
|
@ -1115,24 +1115,23 @@ class MangaDetailsController : BaseController,
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleMangaFavorite() {
|
private fun toggleMangaFavorite() {
|
||||||
val manga = presenter.manga
|
|
||||||
if (presenter.toggleFavorite()) {
|
if (presenter.toggleFavorite()) {
|
||||||
val categories = presenter.getCategories()
|
val categories = presenter.getCategories()
|
||||||
val defaultCategoryId = presenter.preferences.defaultCategory()
|
val defaultCategoryId = presenter.preferences.defaultCategory()
|
||||||
val defaultCategory = categories.find { it.id == defaultCategoryId }
|
val defaultCategory = categories.find { it.id == defaultCategoryId }
|
||||||
when {
|
when {
|
||||||
defaultCategory != null -> presenter.moveMangaToCategory(manga, defaultCategory)
|
defaultCategory != null -> presenter.moveMangaToCategory(defaultCategory)
|
||||||
defaultCategoryId == 0 || categories.isEmpty() -> // 'Default' or no category
|
defaultCategoryId == 0 || categories.isEmpty() -> // 'Default' or no category
|
||||||
presenter.moveMangaToCategory(manga, null)
|
presenter.moveMangaToCategory(null)
|
||||||
else -> {
|
else -> {
|
||||||
val ids = presenter.getMangaCategoryIds(manga)
|
val ids = presenter.getMangaCategoryIds()
|
||||||
val preselected = ids.mapNotNull { id ->
|
val preselected = ids.mapNotNull { id ->
|
||||||
categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
|
categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
|
||||||
}.toTypedArray()
|
}.toTypedArray()
|
||||||
|
|
||||||
AddToLibraryCategoriesDialog(
|
AddToLibraryCategoriesDialog(
|
||||||
this,
|
this,
|
||||||
manga,
|
presenter.manga,
|
||||||
categories,
|
categories,
|
||||||
preselected
|
preselected
|
||||||
).showDialog(router)
|
).showDialog(router)
|
||||||
|
@ -1174,12 +1173,11 @@ class MangaDetailsController : BaseController,
|
||||||
override fun mangaPresenter(): MangaDetailsPresenter = presenter
|
override fun mangaPresenter(): MangaDetailsPresenter = presenter
|
||||||
|
|
||||||
override fun updateCategoriesForMangas(mangas: List<Manga>, categories: List<Category>) {
|
override fun updateCategoriesForMangas(mangas: List<Manga>, categories: List<Category>) {
|
||||||
val manga = mangas.firstOrNull() ?: return
|
presenter.moveMangaToCategories(categories)
|
||||||
presenter.moveMangaToCategories(manga, categories)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateCategoriesForManga(manga: Manga?, categories: List<Category>) {
|
override fun updateCategoriesForManga(manga: Manga?, categories: List<Category>) {
|
||||||
manga?.let { presenter.moveMangaToCategories(manga, categories) }
|
manga?.let { presenter.moveMangaToCategories(categories) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun addToLibraryCancelled(manga: Manga?, position: Int) {
|
override fun addToLibraryCancelled(manga: Manga?, position: Int) {
|
||||||
|
|
|
@ -375,6 +375,7 @@ class MangaDetailsPresenter(
|
||||||
if (update) controller.updateChapters(this.chapters)
|
if (update) controller.updateChapters(this.chapters)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Refresh Manga Info and Chapter List (not tracking) */
|
||||||
fun refreshAll() {
|
fun refreshAll() {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
isLoading = true
|
isLoading = true
|
||||||
|
@ -590,8 +591,8 @@ class MangaDetailsPresenter(
|
||||||
* @param manga the manga to move.
|
* @param manga the manga to move.
|
||||||
* @param category the selected category, or null for default category.
|
* @param category the selected category, or null for default category.
|
||||||
*/
|
*/
|
||||||
fun moveMangaToCategory(manga: Manga, category: Category?) {
|
fun moveMangaToCategory(category: Category?) {
|
||||||
moveMangaToCategories(manga, listOfNotNull(category))
|
moveMangaToCategories(listOfNotNull(category))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -600,7 +601,7 @@ class MangaDetailsPresenter(
|
||||||
* @param manga the manga to move.
|
* @param manga the manga to move.
|
||||||
* @param categories the selected categories.
|
* @param categories the selected categories.
|
||||||
*/
|
*/
|
||||||
fun moveMangaToCategories(manga: Manga, categories: List<Category>) {
|
fun moveMangaToCategories(categories: List<Category>) {
|
||||||
val mc = categories.filter { it.id != 0 }.map { MangaCategory.create(manga, it) }
|
val mc = categories.filter { it.id != 0 }.map { MangaCategory.create(manga, it) }
|
||||||
db.setMangaCategories(mc, listOf(manga))
|
db.setMangaCategories(mc, listOf(manga))
|
||||||
}
|
}
|
||||||
|
@ -611,7 +612,7 @@ class MangaDetailsPresenter(
|
||||||
* @param manga the manga to get categories from.
|
* @param manga the manga to get categories from.
|
||||||
* @return Array of category ids the manga is in, if none returns default id
|
* @return Array of category ids the manga is in, if none returns default id
|
||||||
*/
|
*/
|
||||||
fun getMangaCategoryIds(manga: Manga): Array<Int> {
|
fun getMangaCategoryIds(): Array<Int> {
|
||||||
val categories = db.getCategoriesForManga(manga).executeAsBlocking()
|
val categories = db.getCategoriesForManga(manga).executeAsBlocking()
|
||||||
return categories.mapNotNull { it.id }.toTypedArray()
|
return categories.mapNotNull { it.id }.toTypedArray()
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue