diff --git a/source-local/src/androidMain/kotlin/tachiyomi/source/local/LocalSource.kt b/source-local/src/androidMain/kotlin/tachiyomi/source/local/LocalSource.kt index 247174eea..f7b692edb 100644 --- a/source-local/src/androidMain/kotlin/tachiyomi/source/local/LocalSource.kt +++ b/source-local/src/androidMain/kotlin/tachiyomi/source/local/LocalSource.kt @@ -75,7 +75,7 @@ actual class LocalSource( private val mangaRepository: MangaRepository by injectLazy() - private var localManga: MutableList> = mutableListOf() + private var localMangaChunks: MutableList> = mutableListOf() private var mangaChunks: List> = fileSystem.getFilesInBaseDirectory() @@ -85,7 +85,7 @@ actual class LocalSource( .distinctBy { it.name } .sortedBy { it.name } .toList() - .chunked(MANGA_LOADING_CHUNK_SIZE) + .chunked(CHUNK_SIZE) .toList() private var loadedPages = 0 @@ -114,7 +114,7 @@ actual class LocalSource( // Filter out files that are hidden and is not a folder .asSequence() .filter { it.isDirectory && it.name?.startsWith('.') == false } - .filterNot { mangaDir -> mangaChunks.flatten().map { it.name }.contains(mangaDir.name) } + .filterNot { mangaDir -> mangaChunks.flatten().map { it }.contains(mangaDir) } .distinctBy { it.name } .sortedBy { it.lastModified() } .toList() @@ -124,11 +124,11 @@ actual class LocalSource( .flatten() .plus(newManga) .distinctBy { it.name } - .chunked(MANGA_LOADING_CHUNK_SIZE) + .chunked(CHUNK_SIZE) allMangaLoaded = false - if (localManga.last().size % MANGA_LOADING_CHUNK_SIZE != 0) { - localManga = localManga.dropLast(1).toMutableList() + if (localMangaChunks.last().size % CHUNK_SIZE != 0) { + localMangaChunks = localMangaChunks.dropLast(1).toMutableList() loadedPages-- } } @@ -184,7 +184,7 @@ actual class LocalSource( } }.toList() - localManga.add(mangaPage) + localMangaChunks.add(mangaPage) loadedPages++ currentlyLoadingPage = null } @@ -324,7 +324,7 @@ actual class LocalSource( } } - includedManga = localManga.flatten().filter { manga -> + includedManga = localMangaChunks.flatten().filter { manga -> (manga.title.contains(query, ignoreCase = true) || File(manga.url).name.contains(query, ignoreCase = true)) && areAllElementsInMangaEntry(includedGenres, manga.genre) && areAllElementsInMangaEntry(includedAuthors, manga.author) && @@ -338,7 +338,7 @@ actual class LocalSource( includedArtists.isEmpty() && includedStatuses.isEmpty() ) { - includedManga = localManga.flatten().toMutableList() + includedManga = localMangaChunks.flatten().toMutableList() isFilteredSearch = false } else { isFilteredSearch = true @@ -452,7 +452,7 @@ actual class LocalSource( val mangaPageList = if (includedManga.isNotEmpty()) { - includedManga.toList().chunked(MANGA_LOADING_CHUNK_SIZE) + includedManga.toList().chunked(CHUNK_SIZE) } else { listOf(emptyList()) } @@ -652,13 +652,13 @@ actual class LocalSource( // Filters override fun getFilterList(): FilterList { - val genres = localManga.flatten().mapNotNull { it.genre?.split(",") } + val genres = localMangaChunks.flatten().mapNotNull { it.genre?.split(",") } .flatMap { it.map { genre -> genre.trim() } }.toSet() - val authors = localManga.flatten().mapNotNull { it.author?.split(",") } + val authors = localMangaChunks.flatten().mapNotNull { it.author?.split(",") } .flatMap { it.map { author -> author.trim() } }.toSet() - val artists = localManga.flatten().mapNotNull { it.artist?.split(",") } + val artists = localMangaChunks.flatten().mapNotNull { it.artist?.split(",") } .flatMap { it.map { artist -> artist.trim() } }.toSet() val filters = try { @@ -767,7 +767,7 @@ actual class LocalSource( const val ID = 0L const val HELP_URL = "https://mihon.app/docs/guides/local-source/" - private const val MANGA_LOADING_CHUNK_SIZE = 10 + private const val CHUNK_SIZE = 10 } }