Minor cleanup

This commit is contained in:
tarsin committed 2023-03-07 10:09:20 +08:00
1 parent a39bc1182a
commit f57917e2b6
3 files changed
+8 -16

No files matched your search

@@ -23,7 +23,7 @@ object EhCacheKeyFactory {
return "image:$gid:$index"
}
fun getImageKey(url: String): String {
fun getPreviewThumbKey(url: String): String {
return url.removePrefix(URL_PREFIX_THUMB_E)
.removePrefix(URL_PREFIX_THUMB_EX)
.removePrefix("t/")
@@ -5,7 +5,7 @@ import coil.request.ImageRequest
import com.hippo.ehviewer.client.EhCacheKeyFactory
fun ImageRequest.Builder.ehUrl(url: String) = apply {
val key = EhCacheKeyFactory.getImageKey(url)
val key = EhCacheKeyFactory.getPreviewThumbKey(url)
data(url)
memoryCacheKey(key)
diskCacheKey(key)
@@ -17,7 +17,6 @@ package com.hippo.ehviewer.gallery
import android.content.Context
import android.net.Uri
import android.os.ParcelFileDescriptor
import com.hippo.UriArchiveAccessor
import com.hippo.ehviewer.Settings
import com.hippo.image.Image
@@ -36,7 +35,6 @@ import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.Semaphore
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.sync.withPermit
import java.io.IOException
class ArchivePageLoader(context: Context, uri: Uri, passwdFlow: Flow<String>) : PageLoader2(),
CoroutineScope {
@@ -137,18 +135,12 @@ class ArchivePageLoader(context: Context, uri: Uri, passwdFlow: Flow<String>) :
}
override fun save(index: Int, file: UniFile): Boolean {
val fd: ParcelFileDescriptor
try {
fd = file.openFileDescriptor("w")
} catch (e: IOException) {
e.printStackTrace()
return false
}
archiveAccessor.extractToFd(index, fd.fd)
try {
fd.close()
} catch (e: IOException) {
e.printStackTrace()
runCatching {
file.openFileDescriptor("w").use {
archiveAccessor.extractToFd(index, it.fd)
}
}.onFailure {
it.printStackTrace()
return false
}
return true