Use UniFile for local source file handling

This commit is contained in:
arkon
2023-11-26 15:59:31 -05:00
parent 46aeab9a7a
commit ca54984344
20 changed files with 110 additions and 95 deletions

View File

@ -1,7 +1,9 @@
package eu.kanade.tachiyomi.util.storage
import com.hippo.unifile.UniFile
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import tachiyomi.core.storage.toFile
import java.io.Closeable
import java.io.File
import java.io.InputStream
@ -11,12 +13,12 @@ import java.util.zip.ZipFile
/**
* Wrapper over ZipFile to load files in epub format.
*/
class EpubFile(file: File) : Closeable {
class EpubFile(file: UniFile) : Closeable {
/**
* Zip file of this epub.
*/
private val zip = ZipFile(file)
private val zip = ZipFile(file.toFile())
/**
* Path separator used by this epub.

View File

@ -1,4 +1,4 @@
package tachiyomi.core.provider
package tachiyomi.core.storage
import android.content.Context
import android.os.Environment

View File

@ -1,4 +1,4 @@
package tachiyomi.core.provider
package tachiyomi.core.storage
import java.io.File

View File

@ -1,9 +1,12 @@
package tachiyomi.core.storage
import com.hippo.unifile.UniFile
import java.io.File
val UniFile.extension: String?
get() = name?.substringAfterLast('.')
val UniFile.nameWithoutExtension: String?
get() = name?.substringBeforeLast('.')
fun UniFile.toFile(): File? = filePath?.let { File(it) }

View File

@ -37,7 +37,9 @@ import kotlin.math.min
object ImageUtil {
fun isImage(name: String, openStream: (() -> InputStream)? = null): Boolean {
fun isImage(name: String?, openStream: (() -> InputStream)? = null): Boolean {
if (name == null) return false
val contentType = try {
URLConnection.guessContentTypeFromName(name)
} catch (e: Exception) {