Fixed image loading error
This commit is contained in:
@@ -1 +1 @@
|
||||
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":42,"versionName":"4.6-alpha6","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
|
||||
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":42,"versionName":"4.6-alpha7","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
|
||||
@@ -58,7 +58,7 @@ class ReaderAdapter(private val context: Context,
|
||||
}
|
||||
val modelProvider = object: ListPreloader.PreloadModelProvider<File> {
|
||||
override fun getPreloadItems(position: Int): MutableList<File> {
|
||||
return listOf(Cache(context).getImages(galleryID)?.get(position)).filterNotNullTo(mutableListOf())
|
||||
return listOf(Cache(context).getImages(galleryID)?.getOrNull(position)).filterNotNullTo(mutableListOf())
|
||||
}
|
||||
|
||||
override fun getPreloadRequestBuilder(item: File): RequestBuilder<*>? {
|
||||
|
||||
@@ -300,7 +300,7 @@ class ReaderActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
//addOnScrollListener((adapter as ReaderAdapter).preloader)
|
||||
addOnScrollListener((adapter as ReaderAdapter).preloader)
|
||||
addOnScrollListener(object: RecyclerView.OnScrollListener() {
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user