mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 11:17:25 +01:00
Long click to manage categories (#2045)
This commit is contained in:
parent
974a24d03b
commit
47f14e8555
@ -88,6 +88,9 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
|
|||||||
// Set onclickListener to toggle favorite when FAB clicked.
|
// Set onclickListener to toggle favorite when FAB clicked.
|
||||||
fab_favorite.clicks().subscribeUntilDestroy { onFabClick() }
|
fab_favorite.clicks().subscribeUntilDestroy { onFabClick() }
|
||||||
|
|
||||||
|
// Set onLongClickListener to manage categories when FAB is clicked.
|
||||||
|
fab_favorite.longClicks().subscribeUntilDestroy{ onFabLongClick() }
|
||||||
|
|
||||||
// Set SwipeRefresh to refresh manga data.
|
// Set SwipeRefresh to refresh manga data.
|
||||||
swipe_refresh.refreshes().subscribeUntilDestroy { fetchMangaFromSource() }
|
swipe_refresh.refreshes().subscribeUntilDestroy { fetchMangaFromSource() }
|
||||||
|
|
||||||
@ -400,6 +403,33 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the fab is long clicked.
|
||||||
|
*/
|
||||||
|
private fun onFabLongClick() {
|
||||||
|
val manga = presenter.manga
|
||||||
|
if (!manga.favorite) {
|
||||||
|
toggleFavorite()
|
||||||
|
activity?.toast(activity?.getString(R.string.manga_added_library))
|
||||||
|
}
|
||||||
|
val categories = presenter.getCategories()
|
||||||
|
val defaultCategory = categories.find { it.id == preferences.defaultCategory() }
|
||||||
|
when {
|
||||||
|
defaultCategory != null -> presenter.moveMangaToCategory(manga, defaultCategory)
|
||||||
|
categories.size <= 1 -> // default or the one from the user
|
||||||
|
presenter.moveMangaToCategory(manga, categories.firstOrNull())
|
||||||
|
else -> {
|
||||||
|
val ids = presenter.getMangaCategoryIds(manga)
|
||||||
|
val preselected = ids.mapNotNull { id ->
|
||||||
|
categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
|
||||||
|
}.toTypedArray()
|
||||||
|
|
||||||
|
ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected)
|
||||||
|
.showDialog(router)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun updateCategoriesForMangas(mangas: List<Manga>, categories: List<Category>) {
|
override fun updateCategoriesForMangas(mangas: List<Manga>, categories: List<Category>) {
|
||||||
val manga = mangas.firstOrNull() ?: return
|
val manga = mangas.firstOrNull() ?: return
|
||||||
presenter.moveMangaToCategories(manga, categories)
|
presenter.moveMangaToCategories(manga, categories)
|
||||||
|
Loading…
Reference in New Issue
Block a user