|
|
|
|
@ -1,6 +1,5 @@
|
|
|
|
|
package org.koitharu.kotatsu.local.data
|
|
|
|
|
|
|
|
|
|
import android.net.Uri
|
|
|
|
|
import androidx.core.net.toFile
|
|
|
|
|
import androidx.core.net.toUri
|
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
|
@ -17,7 +16,6 @@ import org.koitharu.kotatsu.core.parser.MangaRepository
|
|
|
|
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
|
|
|
|
import org.koitharu.kotatsu.core.util.AlphanumComparator
|
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.deleteAwait
|
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.isWriteable
|
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug
|
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.takeIfWriteable
|
|
|
|
|
import org.koitharu.kotatsu.core.util.ext.withChildren
|
|
|
|
|
@ -45,6 +43,7 @@ import javax.inject.Inject
|
|
|
|
|
import javax.inject.Singleton
|
|
|
|
|
|
|
|
|
|
private const val MAX_PARALLELISM = 4
|
|
|
|
|
private const val FILENAME_SKIP = ".notamanga"
|
|
|
|
|
|
|
|
|
|
@Singleton
|
|
|
|
|
class LocalMangaRepository @Inject constructor(
|
|
|
|
|
@ -140,7 +139,7 @@ class LocalMangaRepository @Inject constructor(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
suspend fun delete(manga: Manga): Boolean {
|
|
|
|
|
val file = Uri.parse(manga.url).toFile()
|
|
|
|
|
val file = manga.url.toUri().toFile()
|
|
|
|
|
val result = file.deleteAwait()
|
|
|
|
|
if (result) {
|
|
|
|
|
localMangaIndex.delete(manga.id)
|
|
|
|
|
@ -256,8 +255,10 @@ class LocalMangaRepository @Inject constructor(
|
|
|
|
|
private suspend fun getAllFiles() = storageManager.getReadableDirs()
|
|
|
|
|
.asSequence()
|
|
|
|
|
.flatMap { dir ->
|
|
|
|
|
dir.withChildren { children -> children.filterNot { it.isHidden }.toList() }
|
|
|
|
|
dir.withChildren { children -> children.filterNot { it.isHidden || it.shouldSkip() }.toList() }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun Collection<LocalManga>.unwrap(): List<Manga> = map { it.manga }
|
|
|
|
|
|
|
|
|
|
private fun File.shouldSkip(): Boolean = isDirectory && File(this, FILENAME_SKIP).exists()
|
|
|
|
|
}
|
|
|
|
|
|