mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-29 11:23:16 -05:00
Detect identical mangas when long pressing to add to library (#7095)
* Detect identical mangas when long pressing to add to library * Use extracted duplicate manga dialog to avoid duplication * Partially revert previous commit * Review changes * Review changes part 2
This commit is contained in:
parent
f75d632740
commit
f1afeac0bc
2 changed files with 47 additions and 31 deletions
|
@ -38,6 +38,7 @@ import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchController
|
||||||
import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog
|
import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog
|
||||||
import eu.kanade.tachiyomi.ui.library.setting.DisplayModeSetting
|
import eu.kanade.tachiyomi.ui.library.setting.DisplayModeSetting
|
||||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||||
|
import eu.kanade.tachiyomi.ui.manga.AddDuplicateMangaDialog
|
||||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||||
import eu.kanade.tachiyomi.ui.more.MoreController
|
import eu.kanade.tachiyomi.ui.more.MoreController
|
||||||
import eu.kanade.tachiyomi.ui.webview.WebViewActivity
|
import eu.kanade.tachiyomi.ui.webview.WebViewActivity
|
||||||
|
@ -591,6 +592,7 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||||
override fun onItemLongClick(position: Int) {
|
override fun onItemLongClick(position: Int) {
|
||||||
val activity = activity ?: return
|
val activity = activity ?: return
|
||||||
val manga = (adapter?.getItem(position) as? SourceItem?)?.manga ?: return
|
val manga = (adapter?.getItem(position) as? SourceItem?)?.manga ?: return
|
||||||
|
val duplicateManga = presenter.getDuplicateLibraryManga(manga)
|
||||||
|
|
||||||
if (manga.favorite) {
|
if (manga.favorite) {
|
||||||
MaterialAlertDialogBuilder(activity)
|
MaterialAlertDialogBuilder(activity)
|
||||||
|
@ -606,43 +608,53 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
} else {
|
} else {
|
||||||
val categories = presenter.getCategories()
|
if (duplicateManga != null) {
|
||||||
val defaultCategoryId = preferences.defaultCategory()
|
AddDuplicateMangaDialog(this, duplicateManga) { addToLibrary(manga, position) }
|
||||||
val defaultCategory = categories.find { it.id == defaultCategoryId }
|
.showDialog(router)
|
||||||
|
} else {
|
||||||
|
addToLibrary(manga, position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
when {
|
private fun addToLibrary(newManga: Manga, position: Int) {
|
||||||
// Default category set
|
val activity = activity ?: return
|
||||||
defaultCategory != null -> {
|
val categories = presenter.getCategories()
|
||||||
presenter.moveMangaToCategory(manga, defaultCategory)
|
val defaultCategoryId = preferences.defaultCategory()
|
||||||
|
val defaultCategory = categories.find { it.id == defaultCategoryId }
|
||||||
|
|
||||||
presenter.changeMangaFavorite(manga)
|
when {
|
||||||
adapter?.notifyItemChanged(position)
|
// Default category set
|
||||||
activity.toast(activity.getString(R.string.manga_added_library))
|
defaultCategory != null -> {
|
||||||
}
|
presenter.moveMangaToCategory(newManga, defaultCategory)
|
||||||
|
|
||||||
// Automatic 'Default' or no categories
|
presenter.changeMangaFavorite(newManga)
|
||||||
defaultCategoryId == 0 || categories.isEmpty() -> {
|
adapter?.notifyItemChanged(position)
|
||||||
presenter.moveMangaToCategory(manga, null)
|
activity.toast(activity.getString(R.string.manga_added_library))
|
||||||
|
}
|
||||||
|
|
||||||
presenter.changeMangaFavorite(manga)
|
// Automatic 'Default' or no categories
|
||||||
adapter?.notifyItemChanged(position)
|
defaultCategoryId == 0 || categories.isEmpty() -> {
|
||||||
activity.toast(activity.getString(R.string.manga_added_library))
|
presenter.moveMangaToCategory(newManga, null)
|
||||||
}
|
|
||||||
|
|
||||||
// Choose a category
|
presenter.changeMangaFavorite(newManga)
|
||||||
else -> {
|
adapter?.notifyItemChanged(position)
|
||||||
val ids = presenter.getMangaCategoryIds(manga)
|
activity.toast(activity.getString(R.string.manga_added_library))
|
||||||
val preselected = categories.map {
|
}
|
||||||
if (it.id in ids) {
|
|
||||||
QuadStateTextView.State.CHECKED.ordinal
|
|
||||||
} else {
|
|
||||||
QuadStateTextView.State.UNCHECKED.ordinal
|
|
||||||
}
|
|
||||||
}.toTypedArray()
|
|
||||||
|
|
||||||
ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected)
|
// Choose a category
|
||||||
.showDialog(router)
|
else -> {
|
||||||
}
|
val ids = presenter.getMangaCategoryIds(newManga)
|
||||||
|
val preselected = categories.map {
|
||||||
|
if (it.id in ids) {
|
||||||
|
QuadStateTextView.State.CHECKED.ordinal
|
||||||
|
} else {
|
||||||
|
QuadStateTextView.State.UNCHECKED.ordinal
|
||||||
|
}
|
||||||
|
}.toTypedArray()
|
||||||
|
|
||||||
|
ChangeMangaCategoriesDialog(this, listOf(newManga), categories, preselected)
|
||||||
|
.showDialog(router)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -351,6 +351,10 @@ open class BrowseSourcePresenter(
|
||||||
return db.getCategories().executeAsBlocking()
|
return db.getCategories().executeAsBlocking()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getDuplicateLibraryManga(manga: Manga): Manga? {
|
||||||
|
return db.getDuplicateLibraryManga(manga).executeAsBlocking()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the category id's the manga is in, if the manga is not in a category, returns the default id.
|
* Gets the category id's the manga is in, if the manga is not in a category, returns the default id.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue