diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/CompositeMutex.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/CompositeMutex.kt index 9c9c9f0d3..7c7394c63 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/CompositeMutex.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/CompositeMutex.kt @@ -8,6 +8,7 @@ import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import kotlin.coroutines.coroutineContext +@Deprecated("", replaceWith = ReplaceWith("CompositeMutex2")) class CompositeMutex : Set { private val state = ArrayMap>() diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChapterListItemAD.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChapterListItemAD.kt index 00efda3c3..fbe80b9d4 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChapterListItemAD.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChapterListItemAD.kt @@ -7,6 +7,7 @@ import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.ui.list.AdapterDelegateClickListenerAdapter import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener import org.koitharu.kotatsu.core.util.ext.drawableEnd +import org.koitharu.kotatsu.core.util.ext.drawableStart import org.koitharu.kotatsu.core.util.ext.getThemeColor import org.koitharu.kotatsu.core.util.ext.textAndVisible import org.koitharu.kotatsu.databinding.ItemChapterBinding @@ -47,7 +48,7 @@ fun chapterListItemAD( } binding.imageViewBookmarked.isVisible = item.isBookmarked binding.imageViewDownloaded.isVisible = item.isDownloaded - binding.textViewTitle.drawableEnd = if (item.isNew) { + binding.textViewTitle.drawableStart = if (item.isNew) { ContextCompat.getDrawable(context, R.drawable.ic_new) } else { null 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 620901296..97029d856 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 @@ -129,7 +129,11 @@ class LocalMangaRepository @Inject constructor( } suspend fun findSavedManga(remoteManga: Manga): LocalManga? { - // TODO fast path by name + // fast path + LocalMangaInput.find(storageManager.getReadableDirs(), remoteManga)?.let { + return it.getManga() + } + // slow path val files = getAllFiles() return channelFlow { for (file in files) { 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 c88b0af05..262bee5ee 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,12 +2,18 @@ package org.koitharu.kotatsu.local.data.input import android.net.Uri import androidx.core.net.toFile +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.channelFlow +import kotlinx.coroutines.flow.firstOrNull +import kotlinx.coroutines.flow.flowOn +import kotlinx.coroutines.launch 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 import org.koitharu.kotatsu.parsers.model.MangaPage import org.koitharu.kotatsu.parsers.model.MangaSource +import org.koitharu.kotatsu.parsers.util.toFileNameSafe import java.io.File sealed class LocalMangaInput( @@ -37,6 +43,24 @@ sealed class LocalMangaInput( else -> null } + suspend fun find(roots: Iterable, manga: Manga): LocalMangaInput? = channelFlow { + val fileName = manga.title.toFileNameSafe() + for (root in roots) { + launch { + val dir = File(root, fileName) + val zip = File(root, "$fileName.cbz") + val input = when { + dir.isDirectory -> LocalMangaDirInput(dir) + zip.isFile -> LocalMangaZipInput(zip) + else -> null + } + if (input?.getMangaInfo()?.id == manga.id) { + send(input) + } + } + } + }.flowOn(Dispatchers.Default).firstOrNull() + @JvmStatic protected fun zipUri(file: File, entryName: String): String = Uri.fromParts("cbz", file.path, entryName).toString()