From 994aa99797acff8a1a9ee1920459bfcd579ee24d Mon Sep 17 00:00:00 2001 From: Pupil Date: Sun, 23 Feb 2020 10:28:29 +0900 Subject: [PATCH] Fixed image loading bug --- app/build.gradle | 4 ++-- app/release/output.json | 2 +- .../java/xyz/quaver/pupil/adapters/ReaderAdapter.kt | 5 ++--- .../main/java/xyz/quaver/pupil/util/download/Cache.kt | 11 +++++------ 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1e0376f8..1849eb92 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -19,8 +19,8 @@ android { applicationId "xyz.quaver.pupil" minSdkVersion 16 targetSdkVersion 29 - versionCode 42 - versionName "4.6" + versionCode 43 + versionName "4.7-beta1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" multiDexEnabled true vectorDrawables.useSupportLibrary = true diff --git a/app/release/output.json b/app/release/output.json index e58db7af..a2fe94d2 100644 --- a/app/release/output.json +++ b/app/release/output.json @@ -1 +1 @@ -[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":42,"versionName":"4.6","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] \ No newline at end of file +[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":43,"versionName":"4.7-beta1","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] \ No newline at end of file diff --git a/app/src/main/java/xyz/quaver/pupil/adapters/ReaderAdapter.kt b/app/src/main/java/xyz/quaver/pupil/adapters/ReaderAdapter.kt index d271f22e..2b75fe4d 100644 --- a/app/src/main/java/xyz/quaver/pupil/adapters/ReaderAdapter.kt +++ b/app/src/main/java/xyz/quaver/pupil/adapters/ReaderAdapter.kt @@ -119,8 +119,9 @@ class ReaderAdapter(private val context: Context, holder.view.reader_index.text = (position+1).toString() val images = Cache(context).getImage(galleryID, position) + val progress = DownloadWorker.getInstance(context).progress[galleryID]?.get(position) - if (images != null) { + if (progress?.isInfinite() == true && images != null) { glide .load(images) .diskCacheStrategy(DiskCacheStrategy.NONE) @@ -132,8 +133,6 @@ class ReaderAdapter(private val context: Context, } .into(holder.view.image) } else { - val progress = DownloadWorker.getInstance(context).progress[galleryID]?.get(position) - if (progress?.isNaN() == true) { if (Fabric.isInitialized()) Crashlytics.logException(DownloadWorker.getInstance(context).exception[galleryID]?.get(position)) diff --git a/app/src/main/java/xyz/quaver/pupil/util/download/Cache.kt b/app/src/main/java/xyz/quaver/pupil/util/download/Cache.kt index a4808a9a..195917c6 100644 --- a/app/src/main/java/xyz/quaver/pupil/util/download/Cache.kt +++ b/app/src/main/java/xyz/quaver/pupil/util/download/Cache.kt @@ -27,6 +27,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.withContext +import kotlinx.io.InputStream import xyz.quaver.Code import xyz.quaver.hitomi.GalleryBlock import xyz.quaver.hitomi.Reader @@ -34,6 +35,7 @@ import xyz.quaver.pupil.util.getCachedGallery import xyz.quaver.pupil.util.getDownloadDirectory import xyz.quaver.pupil.util.json import java.io.File +import java.io.FileOutputStream import java.net.URL class Cache(context: Context) : ContextWrapper(context) { @@ -212,16 +214,13 @@ class Cache(context: Context) : ContextWrapper(context) { return null } - fun putImage(galleryID: Int, name: String, data: ByteArray) { - val cache = File(getCachedGallery(galleryID), name).also { + fun putImage(galleryID: Int, index: Int, ext: String, data: InputStream) { + val cache = File(getCachedGallery(galleryID), "%05d.$ext".format(index)).also { if (!it.exists()) it.createNewFile() } - if (!Regex("""^[0-9]+.+$""").matches(name)) - throw IllegalArgumentException("File name is not a number") - - cache.writeBytes(data) + data.copyTo(FileOutputStream(cache)) } fun moveToDownload(galleryID: Int) {