fix(manga): Group currentManga setup together

This commit is contained in:
Ahmad Ansori Palembani 2024-12-17 08:09:09 +07:00
parent 60fe907cc0
commit 4a0f578211
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6

View file

@ -200,6 +200,14 @@ class MangaDetailsPresenter(
val controller = view ?: return val controller = view ?: return
isLockedFromSearch = controller.shouldLockIfNeeded && SecureActivityDelegate.shouldBeLocked() isLockedFromSearch = controller.shouldLockIfNeeded && SecureActivityDelegate.shouldBeLocked()
presenterScope.launchUI {
currentManga.collectLatest {
if (it == null) return@collectLatest
controller.updateHeader()
}
}
if (currentManga.value == null) runBlocking { refreshMangaFromDb() } if (currentManga.value == null) runBlocking { refreshMangaFromDb() }
syncData() syncData()
@ -218,13 +226,6 @@ class MangaDetailsPresenter(
presenterScope.launchIO { presenterScope.launchIO {
downloadManager.queueState.collectLatest(::onQueueUpdate) downloadManager.queueState.collectLatest(::onQueueUpdate)
} }
presenterScope.launchUI {
currentManga.collectLatest {
if (it == null) return@collectLatest
controller.updateHeader()
}
}
presenterScope.launchIO { presenterScope.launchIO {
currentChapters.collectLatest { chapters -> currentChapters.collectLatest { chapters ->
allChapters = if (!isScanlatorFiltered()) chapters else getChapter.awaitAll(mangaId, false).map { it.toModel() } allChapters = if (!isScanlatorFiltered()) chapters else getChapter.awaitAll(mangaId, false).map { it.toModel() }
@ -258,7 +259,7 @@ class MangaDetailsPresenter(
.onEach { onUpdateManga() } .onEach { onUpdateManga() }
.launchIn(presenterScope) .launchIn(presenterScope)
val updateMangaNeeded = !manga.initialized val updateMangaNeeded = currentManga.value?.initialized != true
val updateChaptersNeeded = runBlocking { setAndGetChapters() }.isEmpty() val updateChaptersNeeded = runBlocking { setAndGetChapters() }.isEmpty()
presenterScope.launch { presenterScope.launch {
@ -496,7 +497,7 @@ class MangaDetailsPresenter(
.build() .build()
if (preferences.context.imageLoader.execute(request) is SuccessResult) { if (preferences.context.imageLoader.execute(request) is SuccessResult) {
withContext(Dispatchers.Main) { withUIContext {
view?.setPaletteColor() view?.setPaletteColor()
} }
} }