Open migrated/copied MangaController right away (#5005)

This commit is contained in:
Ivan Iskandar 2021-05-14 04:36:05 +07:00 committed by GitHub
parent 7ba43ae5c2
commit 818468c58f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 9 deletions

View File

@ -6,6 +6,7 @@ import androidx.core.view.isVisible
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItemsMultiChoice import com.afollestad.materialdialogs.list.listItemsMultiChoice
import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.Controller
import com.bluelinelabs.conductor.RouterTransaction
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.preference.PreferencesHelper 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.migration.MigrationFlags
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchController import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchController
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchPresenter import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchPresenter
import eu.kanade.tachiyomi.ui.manga.MangaController
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
class SearchController( class SearchController(
@ -69,12 +71,14 @@ class SearchController(
super.onMangaClick(manga) super.onMangaClick(manga)
} }
fun renderIsReplacingManga(isReplacingManga: Boolean) { fun renderIsReplacingManga(isReplacingManga: Boolean, newManga: Manga?) {
if (isReplacingManga) { binding.progress.isVisible = isReplacingManga
binding.progress.isVisible = true if (!isReplacingManga) {
} else {
binding.progress.isVisible = false
router.popController(this) router.popController(this)
if (newManga != null) {
// Replaces old MangaController
router.replaceTopController(RouterTransaction.with(MangaController(newManga)))
}
} }
} }

View File

@ -26,12 +26,16 @@ class SearchPresenter(
private val manga: Manga private val manga: Manga
) : GlobalSearchPresenter(initialQuery) { ) : GlobalSearchPresenter(initialQuery) {
private val replacingMangaRelay = BehaviorRelay.create<Boolean>() private val replacingMangaRelay = BehaviorRelay.create<Pair<Boolean, Manga?>>()
override fun onCreate(savedState: Bundle?) { override fun onCreate(savedState: Bundle?) {
super.onCreate(savedState) 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<CatalogueSource> { override fun getEnabledSources(): List<CatalogueSource> {
@ -55,7 +59,7 @@ class SearchPresenter(
fun migrateManga(prevManga: Manga, manga: Manga, replace: Boolean) { fun migrateManga(prevManga: Manga, manga: Manga, replace: Boolean) {
val source = sourceManager.get(manga.source) ?: return val source = sourceManager.get(manga.source) ?: return
replacingMangaRelay.call(true) replacingMangaRelay.call(Pair(true, null))
presenterScope.launchIO { presenterScope.launchIO {
try { try {
@ -67,7 +71,7 @@ class SearchPresenter(
withUIContext { view?.applicationContext?.toast(e.message) } withUIContext { view?.applicationContext?.toast(e.message) }
} }
presenterScope.launchUI { replacingMangaRelay.call(false) } presenterScope.launchUI { replacingMangaRelay.call(Pair(false, manga)) }
} }
} }