tachiyomi/source-local/src/main/java/tachiyomi/source/local/io/AndroidLocalSourceFileSystem.kt
Andreas f27dc19b37
Move Local Source to separate module (#9152)
* Move Local Source to separate module

* Review changes
2023-02-26 16:16:49 -05:00

40 lines
1.4 KiB
Kotlin

package tachiyomi.source.local.io
import android.content.Context
import eu.kanade.tachiyomi.util.storage.DiskUtil
import tachiyomi.source.local.R
import java.io.File
class AndroidLocalSourceFileSystem(
private val context: Context,
) : LocalSourceFileSystem {
private val baseFolderLocation = "${context.getString(R.string.app_name)}${File.separator}local"
override fun getBaseDirectories(): Sequence<File> {
return DiskUtil.getExternalStorages(context)
.map { File(it.absolutePath, baseFolderLocation) }
.asSequence()
}
override fun getFilesInBaseDirectories(): Sequence<File> {
return getBaseDirectories()
// Get all the files inside all baseDir
.flatMap { it.listFiles().orEmpty().toList() }
}
override fun getMangaDirectory(name: String): File? {
return getFilesInBaseDirectories()
// Get the first mangaDir or null
.firstOrNull { it.isDirectory && it.name == name }
}
override fun getFilesInMangaDirectory(name: String): Sequence<File> {
return getFilesInBaseDirectories()
// Filter out ones that are not related to the manga and is not a directory
.filter { it.isDirectory && it.name == name }
// Get all the files inside the filtered folders
.flatMap { it.listFiles().orEmpty().toList() }
}
}