Fixed image loading error

This commit is contained in:
Pupil
2020-02-22 09:30:24 +09:00
parent b967bf9a26
commit c0e7c87ca4
6 changed files with 14 additions and 16 deletions

View File

@@ -178,24 +178,27 @@ class Cache(context: Context) : ContextWrapper(context) {
return reader
}
val imageNameRegex = Regex("""^\d+\..+$""")
fun getImages(galleryID: Int): List<File?>? {
val gallery = getCachedGallery(galleryID)
val reader = getReaderOrNull(galleryID) ?: return null
val images = gallery.listFiles() ?: return null
return reader.galleryInfo.indices.map { index ->
images.firstOrNull { file -> file.name.startsWith("%05d".format(index)) }
return gallery.list { _, name ->
imageNameRegex.matches(name)
}?.map {
File(gallery, it)
}
}
val imageExts = listOf(
val imageExtensions = listOf(
"png",
"jpg",
"webp"
"webp",
"gif"
)
fun getImage(galleryID: Int, index: Int): File? {
val gallery = getCachedGallery(galleryID)
for (ext in imageExts) {
for (ext in imageExtensions) {
File(gallery, "%05d.$ext".format(index)).let {
if (it.exists())
return it

View File

@@ -23,7 +23,6 @@ import android.content.Context
import android.content.ContextWrapper
import android.content.Intent
import android.content.SharedPreferences
import android.util.Log
import android.util.SparseArray
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
@@ -253,15 +252,13 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont
val cache = Cache(this@DownloadWorker).getImages(galleryID)
progress.put(galleryID, reader.galleryInfo.indices.map { index ->
if (cache?.get(index) != null)
if (cache?.getOrNull(index) != null)
Float.POSITIVE_INFINITY
else
0F
}.toMutableList())
exception.put(galleryID, reader.galleryInfo.map { null }.toMutableList())
Log.i("PUPILD", "READER HERE!")
if (notification[galleryID] == null)
initNotification(galleryID)