From 818468c58f14fc676014833d240cf4978c5478bd Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Fri, 14 May 2021 04:36:05 +0700 Subject: [PATCH] Open migrated/copied MangaController right away (#5005) --- .../ui/browse/migration/search/SearchController.kt | 14 +++++++++----- .../ui/browse/migration/search/SearchPresenter.kt | 12 ++++++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt index 0da6a6c626..c97cf93a71 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt @@ -6,6 +6,7 @@ import androidx.core.view.isVisible import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.list.listItemsMultiChoice import com.bluelinelabs.conductor.Controller +import com.bluelinelabs.conductor.RouterTransaction import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.preference.PreferencesHelper @@ -15,6 +16,7 @@ import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.browse.migration.MigrationFlags import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchController import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchPresenter +import eu.kanade.tachiyomi.ui.manga.MangaController import uy.kohesive.injekt.injectLazy class SearchController( @@ -69,12 +71,14 @@ class SearchController( super.onMangaClick(manga) } - fun renderIsReplacingManga(isReplacingManga: Boolean) { - if (isReplacingManga) { - binding.progress.isVisible = true - } else { - binding.progress.isVisible = false + fun renderIsReplacingManga(isReplacingManga: Boolean, newManga: Manga?) { + binding.progress.isVisible = isReplacingManga + if (!isReplacingManga) { router.popController(this) + if (newManga != null) { + // Replaces old MangaController + router.replaceTopController(RouterTransaction.with(MangaController(newManga))) + } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt index 059f7afeba..ae5e544e2b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt @@ -26,12 +26,16 @@ class SearchPresenter( private val manga: Manga ) : GlobalSearchPresenter(initialQuery) { - private val replacingMangaRelay = BehaviorRelay.create() + private val replacingMangaRelay = BehaviorRelay.create>() override fun onCreate(savedState: Bundle?) { super.onCreate(savedState) - replacingMangaRelay.subscribeLatestCache({ controller, isReplacingManga -> (controller as? SearchController)?.renderIsReplacingManga(isReplacingManga) }) + replacingMangaRelay.subscribeLatestCache( + { controller, (isReplacingManga, newManga) -> + (controller as? SearchController)?.renderIsReplacingManga(isReplacingManga, newManga) + } + ) } override fun getEnabledSources(): List { @@ -55,7 +59,7 @@ class SearchPresenter( fun migrateManga(prevManga: Manga, manga: Manga, replace: Boolean) { val source = sourceManager.get(manga.source) ?: return - replacingMangaRelay.call(true) + replacingMangaRelay.call(Pair(true, null)) presenterScope.launchIO { try { @@ -67,7 +71,7 @@ class SearchPresenter( withUIContext { view?.applicationContext?.toast(e.message) } } - presenterScope.launchUI { replacingMangaRelay.call(false) } + presenterScope.launchUI { replacingMangaRelay.call(Pair(false, manga)) } } }