Fix cbz cover fetcher closing, update Kotlin and other small fixes
This commit is contained in:
@@ -20,19 +20,22 @@ class CbzFetcher : Fetcher<Uri> {
|
||||
pool: BitmapPool,
|
||||
data: Uri,
|
||||
size: Size,
|
||||
options: Options
|
||||
options: Options,
|
||||
): FetchResult {
|
||||
val zip = ZipFile(data.schemeSpecificPart)
|
||||
val entry = zip.getEntry(data.fragment)
|
||||
val ext = MimeTypeMap.getFileExtensionFromUrl(entry.name)
|
||||
return SourceResult(
|
||||
source = zip.getInputStream(entry).source().buffer(),
|
||||
source = ExtraCloseableBufferedSource(
|
||||
zip.getInputStream(entry).source().buffer(),
|
||||
zip,
|
||||
),
|
||||
mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext),
|
||||
dataSource = DataSource.DISK
|
||||
)
|
||||
}
|
||||
|
||||
override fun key(data: Uri): String? = data.toString()
|
||||
override fun key(data: Uri) = data.toString()
|
||||
|
||||
override fun handles(data: Uri) = data.scheme == "cbz"
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import java.util.*
|
||||
class CbzFilter : FilenameFilter {
|
||||
|
||||
override fun accept(dir: File, name: String): Boolean {
|
||||
val ext = name.substringAfterLast('.', "").toLowerCase(Locale.ROOT)
|
||||
val ext = name.substringAfterLast('.', "").lowercase(Locale.ROOT)
|
||||
return ext == "cbz" || ext == "zip"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.koitharu.kotatsu.local.data
|
||||
|
||||
import okhttp3.internal.closeQuietly
|
||||
import okio.BufferedSource
|
||||
import okio.Closeable
|
||||
|
||||
class ExtraCloseableBufferedSource(
|
||||
private val delegate: BufferedSource,
|
||||
vararg closeable: Closeable,
|
||||
) : BufferedSource by delegate {
|
||||
|
||||
private val extraCloseable = closeable
|
||||
|
||||
override fun close() {
|
||||
delegate.close()
|
||||
extraCloseable.forEach { x -> x.closeQuietly() }
|
||||
}
|
||||
}
|
||||
@@ -15,10 +15,7 @@ import org.koitharu.kotatsu.local.data.CbzFilter
|
||||
import org.koitharu.kotatsu.local.data.MangaIndex
|
||||
import org.koitharu.kotatsu.local.data.MangaZip
|
||||
import org.koitharu.kotatsu.utils.AlphanumComparator
|
||||
import org.koitharu.kotatsu.utils.ext.longHashCode
|
||||
import org.koitharu.kotatsu.utils.ext.readText
|
||||
import org.koitharu.kotatsu.utils.ext.sub
|
||||
import org.koitharu.kotatsu.utils.ext.toCamelCase
|
||||
import org.koitharu.kotatsu.utils.ext.*
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import java.util.zip.ZipEntry
|
||||
@@ -78,9 +75,9 @@ class LocalMangaRepository(private val context: Context) : MangaRepository {
|
||||
}
|
||||
}
|
||||
|
||||
fun delete(manga: Manga): Boolean {
|
||||
suspend fun delete(manga: Manga): Boolean {
|
||||
val file = Uri.parse(manga.url).toFile()
|
||||
return file.delete()
|
||||
return file.deleteAwait()
|
||||
}
|
||||
|
||||
@SuppressLint("DefaultLocale")
|
||||
|
||||
Reference in New Issue
Block a user