From 68c2b2dbfaea93de7e4b217b8bfda926de347c7d Mon Sep 17 00:00:00 2001 From: Pupil Date: Fri, 21 Feb 2020 20:11:27 +0900 Subject: [PATCH 1/2] Update README.md Added discord banner --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eafc2df6..5c3f7dc2 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,10 @@ # Pupil ![Banner](https://github.com/tom5079/Pupil/blob/gh-pages/assets/images/pupil-banner.png?raw=true) -*Pupil, Hitomi.la viewer for Android* +*Pupil, Hitomi.la viewer for Android* + +[![](https://discordapp.com/api/guilds/610452916612104194/embed.png?style=banner2)](https://discord.gg/Stj4b5v) +I can speak English, Japanese and Korean. If you have any questions, head over to my discord server or DM me! # Screenshot ![Main Screen](https://github.com/tom5079/Pupil/blob/gh-pages/assets/images/main-screenshot.png?raw=true) From 8204a15276314ef46da6ce563feb7a62281d6708 Mon Sep 17 00:00:00 2001 From: Pupil Date: Sat, 22 Feb 2020 20:30:42 +0900 Subject: [PATCH 2/2] Proxy applied to thumbnails --- .../xyz/quaver/pupil/util/download/Cache.kt | 5 +- .../pupil/util/download/DownloadWorker.kt | 62 ++++++++++++------- 2 files changed, 44 insertions(+), 23 deletions(-) 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..d851b75b 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 @@ -30,6 +30,7 @@ import kotlinx.coroutines.withContext import xyz.quaver.Code import xyz.quaver.hitomi.GalleryBlock import xyz.quaver.hitomi.Reader +import xyz.quaver.proxy import xyz.quaver.pupil.util.getCachedGallery import xyz.quaver.pupil.util.getDownloadDirectory import xyz.quaver.pupil.util.json @@ -78,7 +79,9 @@ class Cache(context: Context) : ContextWrapper(context) { withContext(Dispatchers.IO) { val thumbnails = getGalleryBlock(galleryID)?.thumbnails try { - Base64.encodeToString(URL(thumbnails?.firstOrNull()).readBytes(), Base64.DEFAULT) + Base64.encodeToString(URL(thumbnails?.firstOrNull()).openConnection(proxy).getInputStream().use { + it.readBytes() + }, Base64.DEFAULT) } catch (e: Exception) { null } 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 bb3a2716..b729a6c7 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 @@ -23,6 +23,7 @@ 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 @@ -159,7 +160,7 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont fun buildClient() = OkHttpClient.Builder() .addInterceptor(interceptor) - .dispatcher(Dispatcher(Executors.newFixedThreadPool(4))) + .dispatcher(Dispatcher(Executors.newSingleThreadExecutor())) .proxy(proxy) .build() @@ -279,6 +280,7 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont for (i in reader.galleryInfo.files.indices) { val callback = object : Callback { override fun onFailure(call: Call, e: IOException) { + Log.i("PUPILD", "FAIL ${call.request().tag()} (${e.message})") if (Fabric.isInitialized() && e.message != "Canceled") Crashlytics.logException(e) @@ -287,43 +289,59 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont notify(galleryID) - if (isCompleted(galleryID)) { - with(Cache(this@DownloadWorker)) { - if (isDownloading(galleryID)) { - moveToDownload(galleryID) - setDownloading(galleryID, false) + 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) + } } } - clients.remove(galleryID) } } override fun onResponse(call: Call, response: Response) { - response.body().use { - val res = it.bytes() - val ext = - call.request().url().encodedPath().split('.').last() + Log.i("PUPILD", "OK ${call.request().tag()}") - Cache(this@DownloadWorker).putImage(galleryID, "%05d.%s".format(i, ext), res) - progress[galleryID]?.set(i, Float.POSITIVE_INFINITY) - } + try { + response.body().use { + val res = it.bytes() + val ext = + call.request().url().encodedPath().split('.').last() - notify(galleryID) + Cache(this@DownloadWorker).putImage(galleryID, "%05d.%s".format(i, ext), res) + progress[galleryID]?.set(i, Float.POSITIVE_INFINITY) + } - if (isCompleted(galleryID)) { - with(Cache(this@DownloadWorker)) { - if (isDownloading(galleryID)) { - moveToDownload(galleryID) - setDownloading(galleryID, false) + 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) + } + } } } - clients.remove(galleryID) + + Log.i("PUPILD", "SUCCESS ${call.request().tag()}") + } catch (e: Exception) { + Log.i("PUPILD", "FAIL ON OK ${call.request().tag()} (${e.message})") } } } - if (progress[galleryID]?.get(i)?.isFinite() == true) + if (progress[galleryID]?.get(i)?.isFinite() == true) { queueDownload(galleryID, reader, i, callback) + Log.i("PUPILD", "$galleryID QUEUED $i") + } else { + Log.i("PUPILD", "$galleryID SKIPPED $i (${progress[galleryID]?.get(i)})") + } } }