From aa5e428222c238e12cafe52f41bfe825ea5e2ea1 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 5 Feb 2022 17:27:28 -0500 Subject: [PATCH] Filter archive files as sequence --- .../eu/kanade/tachiyomi/ui/reader/loader/RarPageLoader.kt | 8 +++----- .../eu/kanade/tachiyomi/ui/reader/loader/ZipPageLoader.kt | 7 +++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/RarPageLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/RarPageLoader.kt index 01c7a632e..3776aec34 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/RarPageLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/RarPageLoader.kt @@ -42,18 +42,16 @@ class RarPageLoader(file: File) : PageLoader() { * comparator. */ override fun getPages(): Observable> { - return archive.fileHeaders + return archive.fileHeaders.asSequence() .filter { !it.isDirectory && ImageUtil.isImage(it.fileName) { archive.getInputStream(it) } } .sortedWith { f1, f2 -> f1.fileName.compareToCaseInsensitiveNaturalOrder(f2.fileName) } .mapIndexed { i, header -> - val streamFn = { getStream(header) } - ReaderPage(i).apply { - stream = streamFn + stream = { getStream(header) } status = Page.READY } } - .let { Observable.just(it) } + .let { Observable.just(it.toList()) } } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/ZipPageLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/ZipPageLoader.kt index bee0d372a..f06af6562 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/ZipPageLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/ZipPageLoader.kt @@ -37,17 +37,16 @@ class ZipPageLoader(file: File) : PageLoader() { * comparator. */ override fun getPages(): Observable> { - return zip.entries().toList() + return zip.entries().asSequence() .filter { !it.isDirectory && ImageUtil.isImage(it.name) { zip.getInputStream(it) } } .sortedWith { f1, f2 -> f1.name.compareToCaseInsensitiveNaturalOrder(f2.name) } .mapIndexed { i, entry -> - val streamFn = { zip.getInputStream(entry) } ReaderPage(i).apply { - stream = streamFn + stream = { zip.getInputStream(entry) } status = Page.READY } } - .let { Observable.just(it) } + .let { Observable.just(it.toList()) } } /**