From b4e15263db3d00326abe5886fffb3608c9a85c47 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Tue, 9 Aug 2022 20:10:48 +0700 Subject: [PATCH] Fix issues related to Manga screen slow load (#7708) * Fix back handling when manga is still loading * MangaPresenter: Show what we have earlier to reduce percepted slowness --- .../tachiyomi/ui/manga/MangaController.kt | 9 +++- .../tachiyomi/ui/manga/MangaPresenter.kt | 43 +++++++++++-------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index a34c97bfd9..4b62156e79 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -150,8 +150,13 @@ class MangaController : // Let compose view handle this override fun handleBack(): Boolean { - (activity as? OnBackPressedDispatcherOwner)?.onBackPressedDispatcher?.onBackPressed() - return true + val dispatcher = (activity as? OnBackPressedDispatcherOwner)?.onBackPressedDispatcher ?: return false + return if (dispatcher.hasEnabledCallbacks()) { + dispatcher.onBackPressed() + true + } else { + false + } } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedViewState: Bundle?): View { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt index 35e1a66d1a..29947300b5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt @@ -166,10 +166,28 @@ class MangaPresenter( // Manga info - start presenterScope.launchIO { - if (!getMangaAndChapters.awaitManga(mangaId).favorite) { + val manga = getMangaAndChapters.awaitManga(mangaId) + + if (!manga.favorite) { ChapterSettingsHelper.applySettingDefaults(mangaId) } + // Show what we have earlier. + // Defaults set by the block above won't apply until next update but it doesn't matter + // since we don't have any chapter yet. + _state.update { + MangaScreenState.Success( + manga = manga, + source = Injekt.get().getOrStub(manga.source), + isFromSource = isFromSource, + trackingAvailable = trackManager.hasLoggedServices(), + chapters = emptyList(), + isRefreshingChapter = true, + isIncognitoMode = incognitoMode, + isDownloadedOnlyMode = downloadedOnlyMode, + ) + } + getMangaAndChapters.subscribe(mangaId) .distinctUntilChanged() .collectLatest { (manga, chapters) -> @@ -179,22 +197,13 @@ class MangaPresenter( dateRelativeTime = preferences.relativeTime().get(), dateFormat = preferences.dateFormat(), ) - _state.update { currentState -> - when (currentState) { - // Initialize success state - MangaScreenState.Loading -> MangaScreenState.Success( - manga = manga, - source = Injekt.get().getOrStub(manga.source), - isFromSource = isFromSource, - trackingAvailable = trackManager.hasLoggedServices(), - chapters = chapterItems, - isIncognitoMode = incognitoMode, - isDownloadedOnlyMode = downloadedOnlyMode, - ) - - // Update state - is MangaScreenState.Success -> currentState.copy(manga = manga, chapters = chapterItems) - } + updateSuccessState { + it.copy( + manga = manga, + chapters = chapterItems, + isRefreshingChapter = false, + isRefreshingInfo = false, + ) } observeTrackers()