From c0bbbdb7ee0bca090a1c848abd258e5b5b7dd170 Mon Sep 17 00:00:00 2001 From: arkon Date: Thu, 23 Apr 2020 23:03:20 -0400 Subject: [PATCH] Separate categories picker from long pressing manga favorite button --- .../ui/manga/info/MangaInfoController.kt | 37 +++++++++---------- .../ui/setting/SettingsBackupController.kt | 4 +- .../main/res/layout/manga_info_controller.xml | 11 ++++++ app/src/main/res/values/strings.xml | 2 +- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt index dd68f12462..d3b9ccb16a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt @@ -40,6 +40,7 @@ import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.toggle import eu.kanade.tachiyomi.util.view.visible +import eu.kanade.tachiyomi.util.view.visibleIf import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import reactivecircus.flowbinding.android.view.clicks @@ -77,15 +78,16 @@ class MangaInfoController(private val fromSource: Boolean = false) : override fun onViewCreated(view: View) { super.onViewCreated(view) - // Set onclickListener to toggle favorite when favorite button clicked. binding.btnFavorite.clicks() .onEach { onFavoriteClick() } .launchIn(scope) - // Set onLongClickListener to manage categories when favorite button is clicked. - binding.btnFavorite.longClicks() - .onEach { onFavoriteLongClick() } - .launchIn(scope) + if (presenter.manga.favorite && presenter.getCategories().isNotEmpty()) { + binding.btnCategories.visible() + binding.btnCategories.clicks() + .onEach { onCategoriesClick() } + .launchIn(scope) + } if (presenter.source is HttpSource) { binding.btnWebview.visible() @@ -332,6 +334,8 @@ class MangaInfoController(private val fromSource: Boolean = false) : } } } + + binding.btnCategories.visibleIf { isNowFavorite && presenter.getCategories().isNotEmpty() } } private fun openInWebView() { @@ -455,22 +459,17 @@ class MangaInfoController(private val fromSource: Boolean = false) : } } - private fun onFavoriteLongClick() { + private fun onCategoriesClick() { val manga = presenter.manga + val categories = presenter.getCategories() - if (manga.favorite && presenter.getCategories().isNotEmpty()) { - val categories = presenter.getCategories() + val ids = presenter.getMangaCategoryIds(manga) + val preselected = ids.mapNotNull { id -> + categories.indexOfFirst { it.id == id }.takeIf { it != -1 } + }.toTypedArray() - 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) - } else { - onFavoriteClick() - } + ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected) + .showDialog(router) } override fun updateCategoriesForMangas(mangas: List, categories: List) { @@ -478,10 +477,10 @@ class MangaInfoController(private val fromSource: Boolean = false) : if (!manga.favorite) { toggleFavorite() + activity?.toast(activity?.getString(R.string.manga_added_library)) } presenter.moveMangaToCategories(manga, categories) - activity?.toast(activity?.getString(R.string.manga_added_library)) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt index 93e4ff0f62..64ccfca608 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt @@ -197,9 +197,7 @@ class SettingsBackupController : SettingsController() { CODE_BACKUP_RESTORE -> if (data != null && resultCode == Activity.RESULT_OK) { val uri = data.data if (uri != null) { - val ctrl = RestoreBackupDialog(uri) - ctrl.targetController = this@SettingsBackupController - ctrl.showDialog(router) + RestoreBackupDialog(uri).showDialog(router) } } } diff --git a/app/src/main/res/layout/manga_info_controller.xml b/app/src/main/res/layout/manga_info_controller.xml index a724c1edca..badaae3602 100644 --- a/app/src/main/res/layout/manga_info_controller.xml +++ b/app/src/main/res/layout/manga_info_controller.xml @@ -206,6 +206,17 @@ android:text="@string/add_to_library" app:icon="@drawable/ic_add_to_library_24dp" /> + + Add category Edit categories Rename category - Move to categories + Set categories Edit the cover picture Sort up Sort down