mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 03:07:25 +01:00
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
This commit is contained in:
parent
96c3116af6
commit
b4e15263db
@ -150,8 +150,13 @@ class MangaController :
|
|||||||
|
|
||||||
// Let compose view handle this
|
// Let compose view handle this
|
||||||
override fun handleBack(): Boolean {
|
override fun handleBack(): Boolean {
|
||||||
(activity as? OnBackPressedDispatcherOwner)?.onBackPressedDispatcher?.onBackPressed()
|
val dispatcher = (activity as? OnBackPressedDispatcherOwner)?.onBackPressedDispatcher ?: return false
|
||||||
return true
|
return if (dispatcher.hasEnabledCallbacks()) {
|
||||||
|
dispatcher.onBackPressed()
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedViewState: Bundle?): View {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedViewState: Bundle?): View {
|
||||||
|
@ -166,10 +166,28 @@ class MangaPresenter(
|
|||||||
// Manga info - start
|
// Manga info - start
|
||||||
|
|
||||||
presenterScope.launchIO {
|
presenterScope.launchIO {
|
||||||
if (!getMangaAndChapters.awaitManga(mangaId).favorite) {
|
val manga = getMangaAndChapters.awaitManga(mangaId)
|
||||||
|
|
||||||
|
if (!manga.favorite) {
|
||||||
ChapterSettingsHelper.applySettingDefaults(mangaId)
|
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<SourceManager>().getOrStub(manga.source),
|
||||||
|
isFromSource = isFromSource,
|
||||||
|
trackingAvailable = trackManager.hasLoggedServices(),
|
||||||
|
chapters = emptyList(),
|
||||||
|
isRefreshingChapter = true,
|
||||||
|
isIncognitoMode = incognitoMode,
|
||||||
|
isDownloadedOnlyMode = downloadedOnlyMode,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
getMangaAndChapters.subscribe(mangaId)
|
getMangaAndChapters.subscribe(mangaId)
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.collectLatest { (manga, chapters) ->
|
.collectLatest { (manga, chapters) ->
|
||||||
@ -179,22 +197,13 @@ class MangaPresenter(
|
|||||||
dateRelativeTime = preferences.relativeTime().get(),
|
dateRelativeTime = preferences.relativeTime().get(),
|
||||||
dateFormat = preferences.dateFormat(),
|
dateFormat = preferences.dateFormat(),
|
||||||
)
|
)
|
||||||
_state.update { currentState ->
|
updateSuccessState {
|
||||||
when (currentState) {
|
it.copy(
|
||||||
// Initialize success state
|
manga = manga,
|
||||||
MangaScreenState.Loading -> MangaScreenState.Success(
|
chapters = chapterItems,
|
||||||
manga = manga,
|
isRefreshingChapter = false,
|
||||||
source = Injekt.get<SourceManager>().getOrStub(manga.source),
|
isRefreshingInfo = false,
|
||||||
isFromSource = isFromSource,
|
)
|
||||||
trackingAvailable = trackManager.hasLoggedServices(),
|
|
||||||
chapters = chapterItems,
|
|
||||||
isIncognitoMode = incognitoMode,
|
|
||||||
isDownloadedOnlyMode = downloadedOnlyMode,
|
|
||||||
)
|
|
||||||
|
|
||||||
// Update state
|
|
||||||
is MangaScreenState.Success -> currentState.copy(manga = manga, chapters = chapterItems)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
observeTrackers()
|
observeTrackers()
|
||||||
|
Loading…
Reference in New Issue
Block a user