Removing repeated manga paramater in manga presenter

This commit is contained in:
Jay 2020-04-28 16:49:32 -04:00
parent 161b741d04
commit da7adb8197
2 changed files with 12 additions and 13 deletions

View File

@ -1088,7 +1088,7 @@ class MangaDetailsController : BaseController,
presenter.toggleFavorite()
showAddedSnack()
}
val ids = presenter.getMangaCategoryIds(manga)
val ids = presenter.getMangaCategoryIds()
val preselected = ids.mapNotNull { id ->
categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
}.toTypedArray()
@ -1115,24 +1115,23 @@ class MangaDetailsController : BaseController,
}
private fun toggleMangaFavorite() {
val manga = presenter.manga
if (presenter.toggleFavorite()) {
val categories = presenter.getCategories()
val defaultCategoryId = presenter.preferences.defaultCategory()
val defaultCategory = categories.find { it.id == defaultCategoryId }
when {
defaultCategory != null -> presenter.moveMangaToCategory(manga, defaultCategory)
defaultCategory != null -> presenter.moveMangaToCategory(defaultCategory)
defaultCategoryId == 0 || categories.isEmpty() -> // 'Default' or no category
presenter.moveMangaToCategory(manga, null)
presenter.moveMangaToCategory(null)
else -> {
val ids = presenter.getMangaCategoryIds(manga)
val ids = presenter.getMangaCategoryIds()
val preselected = ids.mapNotNull { id ->
categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
}.toTypedArray()
AddToLibraryCategoriesDialog(
this,
manga,
presenter.manga,
categories,
preselected
).showDialog(router)
@ -1174,12 +1173,11 @@ class MangaDetailsController : BaseController,
override fun mangaPresenter(): MangaDetailsPresenter = presenter
override fun updateCategoriesForMangas(mangas: List<Manga>, categories: List<Category>) {
val manga = mangas.firstOrNull() ?: return
presenter.moveMangaToCategories(manga, categories)
presenter.moveMangaToCategories(categories)
}
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) {

View File

@ -375,6 +375,7 @@ class MangaDetailsPresenter(
if (update) controller.updateChapters(this.chapters)
}
/** Refresh Manga Info and Chapter List (not tracking) */
fun refreshAll() {
scope.launch {
isLoading = true
@ -590,8 +591,8 @@ class MangaDetailsPresenter(
* @param manga the manga to move.
* @param category the selected category, or null for default category.
*/
fun moveMangaToCategory(manga: Manga, category: Category?) {
moveMangaToCategories(manga, listOfNotNull(category))
fun moveMangaToCategory(category: Category?) {
moveMangaToCategories(listOfNotNull(category))
}
/**
@ -600,7 +601,7 @@ class MangaDetailsPresenter(
* @param manga the manga to move.
* @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) }
db.setMangaCategories(mc, listOf(manga))
}
@ -611,7 +612,7 @@ class MangaDetailsPresenter(
* @param manga the manga to get categories from.
* @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()
return categories.mapNotNull { it.id }.toTypedArray()
}