From e052bdef96c133b92dfad214c2b05ab03d4c5866 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 12 Feb 2023 16:14:12 -0500 Subject: [PATCH] Move reader preloading to IO scope Maybe fixes #8440 --- .../tachiyomi/ui/reader/ReaderActivity.kt | 2 +- .../tachiyomi/ui/reader/ReaderViewModel.kt | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 1fcf8a0fe..0d1d2ef09 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -871,7 +871,7 @@ class ReaderActivity : BaseActivity() { * the viewer is reaching the beginning or end of a chapter or the transition page is active. */ fun requestPreloadChapter(chapter: ReaderChapter) { - lifecycleScope.launch { viewModel.preloadChapter(chapter) } + lifecycleScope.launchIO { viewModel.preloadChapter(chapter) } } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt index 3498f1745..23a87204e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt @@ -388,20 +388,17 @@ class ReaderViewModel( return } - logcat { "Preloading ${chapter.chapter.url}" } - val loader = loader ?: return - withIOContext { - try { - loader.loadChapter(chapter) - } catch (e: Throwable) { - if (e is CancellationException) { - throw e - } - return@withIOContext + try { + logcat { "Preloading ${chapter.chapter.url}" } + loader.loadChapter(chapter) + } catch (e: Throwable) { + if (e is CancellationException) { + throw e } - eventChannel.trySend(Event.ReloadViewerChapters) + return } + eventChannel.trySend(Event.ReloadViewerChapters) } /**