diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/local/data/LocalMangaRepository.kt b/app/src/main/kotlin/org/koitharu/kotatsu/local/data/LocalMangaRepository.kt index 9405629cf..439cdc847 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/local/data/LocalMangaRepository.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/local/data/LocalMangaRepository.kt @@ -29,6 +29,7 @@ import org.koitharu.kotatsu.parsers.model.SortOrder import org.koitharu.kotatsu.parsers.util.runCatchingCancellable import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import java.io.File +import java.io.FilenameFilter import java.util.EnumSet import javax.inject.Inject import javax.inject.Singleton @@ -192,7 +193,7 @@ class LocalMangaRepository @Inject constructor( val dispatcher = Dispatchers.IO.limitedParallelism(MAX_PARALLELISM) files.map { file -> async(dispatcher) { - runCatchingCancellable { LocalMangaInput.of(file).getManga() }.getOrNull() + runCatchingCancellable { LocalMangaInput.ofOrNull(file)?.getManga() }.getOrNull() } }.awaitAll() }.filterNotNullTo(ArrayList(files.size)) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/local/data/input/LocalMangaInput.kt b/app/src/main/kotlin/org/koitharu/kotatsu/local/data/input/LocalMangaInput.kt index f203912e5..c88b0af05 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/local/data/input/LocalMangaInput.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/local/data/input/LocalMangaInput.kt @@ -2,6 +2,7 @@ package org.koitharu.kotatsu.local.data.input import android.net.Uri import androidx.core.net.toFile +import org.koitharu.kotatsu.local.data.CbzFilter import org.koitharu.kotatsu.local.domain.model.LocalManga import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.model.MangaChapter @@ -30,6 +31,12 @@ sealed class LocalMangaInput( else -> LocalMangaZipInput(file) } + fun ofOrNull(file: File): LocalMangaInput? = when { + file.isDirectory -> LocalMangaDirInput(file) + CbzFilter.isFileSupported(file.name) -> LocalMangaZipInput(file) + else -> null + } + @JvmStatic protected fun zipUri(file: File, entryName: String): String = Uri.fromParts("cbz", file.path, entryName).toString() diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/shelf/domain/ShelfContentObserveUseCase.kt b/app/src/main/kotlin/org/koitharu/kotatsu/shelf/domain/ShelfContentObserveUseCase.kt index b2104c199..b3f23a9c6 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/shelf/domain/ShelfContentObserveUseCase.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/shelf/domain/ShelfContentObserveUseCase.kt @@ -4,6 +4,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map @@ -11,6 +12,8 @@ import kotlinx.coroutines.flow.mapLatest import kotlinx.coroutines.flow.onStart import org.koitharu.kotatsu.core.db.MangaDatabase import org.koitharu.kotatsu.core.model.FavouriteCategory +import org.koitharu.kotatsu.core.prefs.AppSettings +import org.koitharu.kotatsu.core.prefs.observeAsFlow import org.koitharu.kotatsu.favourites.data.FavouriteCategoryEntity import org.koitharu.kotatsu.favourites.data.toFavouriteCategory import org.koitharu.kotatsu.favourites.data.toMangaList @@ -32,6 +35,7 @@ class ShelfContentObserveUseCase @Inject constructor( private val trackingRepository: TrackingRepository, private val suggestionRepository: SuggestionRepository, private val db: MangaDatabase, + private val settings: AppSettings, @LocalStorageChanges private val localStorageChanges: SharedFlow, ) { @@ -46,7 +50,10 @@ class ShelfContentObserveUseCase @Inject constructor( } private fun observeLocalManga(sortOrder: SortOrder, limit: Int): Flow> { - return localStorageChanges + return combine( + localStorageChanges, + settings.observe().filter { it == AppSettings.KEY_LOCAL_MANGA_DIRS } + ) { _, _ -> Any() } .onStart { emit(null) } .mapLatest { localMangaRepository.getList(0, null, sortOrder).take(limit)