From 5fd35b492c93e805b98d151d7a00ecb601e24290 Mon Sep 17 00:00:00 2001 From: Pupil Date: Mon, 24 Feb 2020 12:49:19 +0900 Subject: [PATCH] Bug fix --- app/build.gradle | 2 +- app/release/output.json | 2 +- .../quaver/pupil/adapters/ReaderAdapter.kt | 20 ++++++++- .../pupil/util/download/DownloadWorker.kt | 42 ++++++++++++++++--- app/src/main/res/layout/item_reader.xml | 1 - 5 files changed, 58 insertions(+), 9 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4cb4355a..a9284b02 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,7 +20,7 @@ android { minSdkVersion 16 targetSdkVersion 29 versionCode 43 - versionName "4.7-beta2" + versionName "4.7" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" multiDexEnabled true vectorDrawables.useSupportLibrary = true diff --git a/app/release/output.json b/app/release/output.json index a14f3503..cc20512c 100644 --- a/app/release/output.json +++ b/app/release/output.json @@ -1 +1 @@ -[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":43,"versionName":"4.7-beta2","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","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 ef560f17..c0ec6ce1 100644 --- a/app/src/main/java/xyz/quaver/pupil/adapters/ReaderAdapter.kt +++ b/app/src/main/java/xyz/quaver/pupil/adapters/ReaderAdapter.kt @@ -19,6 +19,7 @@ package xyz.quaver.pupil.adapters import android.content.Context +import android.graphics.BitmapFactory import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -122,12 +123,23 @@ class ReaderAdapter(private val context: Context, val progress = DownloadWorker.getInstance(context).progress[galleryID]?.get(position) if (progress?.isInfinite() == true && images != null) { - holder.view.reader_item_progressbar.visibility = View.GONE + holder.view.reader_item_progressbar.visibility = View.INVISIBLE + holder.view.container.apply { + val options = BitmapFactory.Options().apply { + inJustDecodeBounds = true + } + + BitmapFactory.decodeFile(images.canonicalPath, options) + + maxWidth = options.outWidth + maxHeight = options.outHeight + } glide .load(images) .diskCacheStrategy(DiskCacheStrategy.NONE) .skipMemoryCache(true) + .dontTransform() .error(R.drawable.image_broken_variant) .apply { if (BuildConfig.CENSOR) @@ -135,6 +147,12 @@ class ReaderAdapter(private val context: Context, } .into(holder.view.image) } else { + holder.view.reader_item_progressbar.visibility = View.VISIBLE + holder.view.container.apply { + maxWidth = Integer.MAX_VALUE + maxHeight = Integer.MAX_VALUE + } + 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/DownloadWorker.kt b/app/src/main/java/xyz/quaver/pupil/util/download/DownloadWorker.kt index 9af62271..2d54ef0c 100644 --- a/app/src/main/java/xyz/quaver/pupil/util/download/DownloadWorker.kt +++ b/app/src/main/java/xyz/quaver/pupil/util/download/DownloadWorker.kt @@ -333,7 +333,26 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont Log.i("PUPILD", "SUCCESS ${call.request().tag()}") } catch (e: Exception) { + + progress[galleryID]?.set(i, Float.NaN) + exception[galleryID]?.set(i, e) + + notify(galleryID) + + CoroutineScope(Dispatchers.IO).launch { + if (isCompleted(galleryID) && clients.indexOfKey(galleryID) >= 0) { + clients.remove(galleryID) + with(Cache(this@DownloadWorker)) { + if (isDownloading(galleryID)) { + moveToDownload(galleryID) + setDownloading(galleryID, false) + } + } + } + } + File(Cache(this@DownloadWorker).getCachedGallery(galleryID), "%05d.$ext".format(i)).delete() + Log.i("PUPILD", "FAIL ON OK ${call.request().tag()} (${e.message})") } } @@ -352,13 +371,17 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont val max = progress[galleryID]?.size ?: 0 val progress = progress[galleryID]?.count { !it.isFinite() } ?: 0 - if (isCompleted(galleryID)) + Log.i("PUPILD", "NOTIFY $galleryID ${isCompleted(galleryID)} $progress/$max") + + if (isCompleted(galleryID)) { notification[galleryID] ?.setContentText(getString(R.string.reader_notification_complete)) ?.setSmallIcon(android.R.drawable.stat_sys_download_done) ?.setProgress(0, 0, false) ?.setOngoing(false) - else + + notificationManager.cancel(galleryID) + } else notification[galleryID] ?.setProgress(max, progress, false) ?.setContentText("$progress/$max") @@ -390,18 +413,27 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont private fun loop() = CoroutineScope(Dispatchers.Default).launch { while (true) { - if (queue.isEmpty() || clients.size() >= preferences.getInt("max_download", 4)) + if (queue.isEmpty()) continue - val galleryID = queue.poll() ?: continue + val galleryID = queue.peek() ?: continue if (clients.indexOfKey(galleryID) >= 0) // Gallery already downloading! continue - initNotification(galleryID) + if (notification[galleryID] == null) + initNotification(galleryID) + if (Cache(this@DownloadWorker).isDownloading(galleryID)) notificationManager.notify(galleryID, notification[galleryID].build()) + + if (clients.size() >= preferences.getInt("max_download", 4)) + continue + + Log.i("PUPILD", "QUEUED $galleryID #${clients.size()+1}") + worker.put(galleryID, download(galleryID)) + queue.poll() } } diff --git a/app/src/main/res/layout/item_reader.xml b/app/src/main/res/layout/item_reader.xml index dc1a1359..01a50804 100644 --- a/app/src/main/res/layout/item_reader.xml +++ b/app/src/main/res/layout/item_reader.xml @@ -27,7 +27,6 @@ android:id="@+id/container" android:layout_width="match_parent" android:layout_height="0dp" - android:maxHeight="5000dp" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent"