From 69e85f8b90f70047891a5264661cdf1094fef2b9 Mon Sep 17 00:00:00 2001 From: Pupil Date: Mon, 24 Feb 2020 21:10:10 +0900 Subject: [PATCH] Bug fix --- app/build.gradle | 4 +- app/release/output.json | 2 +- .../quaver/pupil/adapters/ReaderAdapter.kt | 24 +++---- .../xyz/quaver/pupil/util/download/Cache.kt | 1 + .../main/java/xyz/quaver/pupil/util/file.kt | 63 +++++++++++++++++++ app/src/main/res/layout/item_reader.xml | 7 +-- 6 files changed, 82 insertions(+), 19 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 76e0fa34..42901c2d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -19,8 +19,8 @@ android { applicationId "xyz.quaver.pupil" minSdkVersion 16 targetSdkVersion 29 - versionCode 44 - versionName "4.8" + versionCode 45 + versionName "4.9" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" multiDexEnabled true vectorDrawables.useSupportLibrary = true diff --git a/app/release/output.json b/app/release/output.json index f445680f..a2d117d1 100644 --- a/app/release/output.json +++ b/app/release/output.json @@ -1 +1 @@ -[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":44,"versionName":"4.8","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":45,"versionName":"4.9","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 d531e55b..8804798e 100644 --- a/app/src/main/java/xyz/quaver/pupil/adapters/ReaderAdapter.kt +++ b/app/src/main/java/xyz/quaver/pupil/adapters/ReaderAdapter.kt @@ -110,10 +110,9 @@ class ReaderAdapter(private val context: Context, onItemClickListener?.invoke(position) } - if (!isFullScreen) { + if (!isFullScreen) (holder.view.container.layoutParams as ConstraintLayout.LayoutParams) - .dimensionRatio = "${reader!!.galleryInfo.files[position].width}:${reader!!.galleryInfo.files[position].height}" - } + .dimensionRatio = "W,${reader!!.galleryInfo.files[position].width}:${reader!!.galleryInfo.files[position].height}" holder.view.reader_index.text = (position+1).toString() @@ -123,18 +122,19 @@ class ReaderAdapter(private val context: Context, if (progress?.isInfinite() == true && images != null) { holder.view.reader_item_progressbar.visibility = View.INVISIBLE - glide - .load(images) - .fitCenter() - .error(R.drawable.image_broken_variant) - .apply { - if (BuildConfig.CENSOR) - override(5, 8) - } - .into(holder.view.image) + holder.view.image.post { + glide + .load(images) + .fitCenter() + .error(R.drawable.image_broken_variant) + .into(holder.view.image) + } + } else { holder.view.reader_item_progressbar.visibility = View.VISIBLE + glide.clear(holder.view.image) + 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 ddca6c04..757dbf9a 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 @@ -33,6 +33,7 @@ import xyz.quaver.Code import xyz.quaver.hitomi.GalleryBlock import xyz.quaver.hitomi.Reader import xyz.quaver.proxy +import xyz.quaver.pupil.util.copyRecursively import xyz.quaver.pupil.util.getCachedGallery import xyz.quaver.pupil.util.getDownloadDirectory import xyz.quaver.pupil.util.json diff --git a/app/src/main/java/xyz/quaver/pupil/util/file.kt b/app/src/main/java/xyz/quaver/pupil/util/file.kt index 8a25c4b8..497424c1 100644 --- a/app/src/main/java/xyz/quaver/pupil/util/file.kt +++ b/app/src/main/java/xyz/quaver/pupil/util/file.kt @@ -26,6 +26,7 @@ import android.os.storage.StorageManager import android.provider.DocumentsContract import androidx.core.content.ContextCompat import androidx.preference.PreferenceManager +import kotlinx.io.IOException import java.io.File import java.io.FileOutputStream import java.lang.reflect.Array @@ -211,4 +212,66 @@ fun Uri.toFile(context: Context): File? { } return File(context.getExternalFilesDir(null)?.canonicalPath?.substringBeforeLast("/Android/data") ?: return null, folderName) +} + +fun File.copyRecursively( + target: File, + overwrite: Boolean = false, + onError: (File, IOException) -> OnErrorAction = { _, exception -> throw exception } +): Boolean { + if (!exists()) { + return onError(this, NoSuchFileException(file = this, reason = "The source file doesn't exist.")) != + OnErrorAction.TERMINATE + } + try { + // We cannot break for loop from inside a lambda, so we have to use an exception here + for (src in walkTopDown().onFail { f, e -> if (onError(f, e) == OnErrorAction.TERMINATE) throw IOException("Walk failed") }) { + if (!src.exists()) { + if (onError(src, NoSuchFileException(file = src, reason = "The source file doesn't exist.")) == + OnErrorAction.TERMINATE) + return false + } else { + val relPath = src.toRelativeString(this) + val dstFile = File(target, relPath) + if (dstFile.exists() && !(src.isDirectory && dstFile.isDirectory)) { + val stillExists = if (!overwrite) true else { + if (dstFile.isDirectory) + !dstFile.deleteRecursively() + else + !dstFile.delete() + } + + if (stillExists) { + if (onError(dstFile, FileAlreadyExistsException(file = src, + other = dstFile, + reason = "The destination file already exists.")) == OnErrorAction.TERMINATE) + return false + + continue + } + } + + if (src.isDirectory) { + dstFile.mkdirs() + } else { + val length = try { + src.copyTo(dstFile, overwrite).length() + } catch (e: IOException) { + if (onError(src, e) == OnErrorAction.TERMINATE) + return false + else + -1 + } + + if (length != src.length()) { + if (onError(src, IOException("Source file wasn't copied completely, length of destination file differs.")) == OnErrorAction.TERMINATE) + return false + } + } + } + } + return true + } catch (e: IOException) { + return false + } } \ No newline at end of file diff --git a/app/src/main/res/layout/item_reader.xml b/app/src/main/res/layout/item_reader.xml index f3ba20d6..0dd78f9a 100644 --- a/app/src/main/res/layout/item_reader.xml +++ b/app/src/main/res/layout/item_reader.xml @@ -25,9 +25,8 @@