Remove uses of File#listFiles()
parent
df05211561
commit
9f7ec888a6
@ -0,0 +1,18 @@
|
||||
package org.koitharu.kotatsu.core.util.ext
|
||||
|
||||
import android.net.Uri
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.runInterruptible
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.ExperimentalPathApi
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.fileSize
|
||||
import kotlin.io.path.walk
|
||||
|
||||
@OptIn(ExperimentalPathApi::class)
|
||||
suspend fun Path.computeSize(): Long = runInterruptible(Dispatchers.IO) {
|
||||
// Directories are not included by default
|
||||
walk().sumOf { it.fileSize() }
|
||||
}
|
||||
|
||||
fun Uri.toPathOrNull() = if (scheme == "file") path?.let { Path(it) } else null
|
||||
@ -1,31 +1,13 @@
|
||||
package org.koitharu.kotatsu.local.data
|
||||
|
||||
import android.net.Uri
|
||||
import java.io.File
|
||||
import java.io.FileFilter
|
||||
import java.io.FilenameFilter
|
||||
import java.util.Locale
|
||||
|
||||
class CbzFilter : FileFilter, FilenameFilter {
|
||||
|
||||
override fun accept(dir: File, name: String): Boolean {
|
||||
return isFileSupported(name)
|
||||
}
|
||||
|
||||
override fun accept(pathname: File?): Boolean {
|
||||
return isFileSupported(pathname?.name ?: return false)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun isFileSupported(name: String): Boolean {
|
||||
val ext = name.substringAfterLast('.', "").lowercase(Locale.ROOT)
|
||||
return ext == "cbz" || ext == "zip"
|
||||
}
|
||||
fun isCbzExtension(string: String): Boolean {
|
||||
return string.equals("cbz", ignoreCase = true) || string.equals("zip", ignoreCase = true)
|
||||
}
|
||||
|
||||
fun isUriSupported(uri: Uri): Boolean {
|
||||
val scheme = uri.scheme?.lowercase(Locale.ROOT)
|
||||
return scheme != null && scheme == "cbz" || scheme == "zip"
|
||||
}
|
||||
}
|
||||
fun hasCbzExtension(name: String): Boolean {
|
||||
return isCbzExtension(name.substringAfterLast('.', ""))
|
||||
}
|
||||
|
||||
fun hasCbzExtension(uri: Uri) = uri.scheme?.let { isCbzExtension(it) } ?: false
|
||||
|
||||
@ -1,29 +1,16 @@
|
||||
package org.koitharu.kotatsu.local.data
|
||||
|
||||
import java.io.File
|
||||
import java.io.FileFilter
|
||||
import java.io.FilenameFilter
|
||||
import java.util.Locale
|
||||
import java.util.zip.ZipEntry
|
||||
|
||||
class ImageFileFilter : FilenameFilter, FileFilter {
|
||||
|
||||
override fun accept(dir: File, name: String): Boolean {
|
||||
val ext = name.substringAfterLast('.', "").lowercase(Locale.ROOT)
|
||||
return isExtensionValid(ext)
|
||||
}
|
||||
|
||||
override fun accept(pathname: File?): Boolean {
|
||||
val ext = pathname?.extension?.lowercase(Locale.ROOT) ?: return false
|
||||
return isExtensionValid(ext)
|
||||
}
|
||||
fun isImageExtension(string: String): Boolean {
|
||||
return string.equals("png", ignoreCase = true) || string.equals("jpg", ignoreCase = true)
|
||||
|| string.equals("jpeg", ignoreCase = true) || string.equals("webp", ignoreCase = true)
|
||||
}
|
||||
|
||||
fun accept(entry: ZipEntry): Boolean {
|
||||
val ext = entry.name.substringAfterLast('.', "").lowercase(Locale.ROOT)
|
||||
return isExtensionValid(ext)
|
||||
}
|
||||
fun hasImageExtension(name: String): Boolean {
|
||||
return isImageExtension(name.substringAfterLast('.', ""))
|
||||
}
|
||||
|
||||
fun isExtensionValid(ext: String): Boolean {
|
||||
return ext == "png" || ext == "jpg" || ext == "jpeg" || ext == "webp"
|
||||
}
|
||||
fun hasImageExtension(entry: ZipEntry): Boolean {
|
||||
return hasImageExtension(entry.name)
|
||||
}
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
package org.koitharu.kotatsu.local.data
|
||||
|
||||
import java.io.File
|
||||
import java.io.FilenameFilter
|
||||
|
||||
class TempFileFilter : FilenameFilter {
|
||||
|
||||
override fun accept(dir: File, name: String): Boolean {
|
||||
return name.endsWith(".tmp", ignoreCase = true)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue