From 9415ab4ef9409c0ae7466c940b566805669025c0 Mon Sep 17 00:00:00 2001 From: tom5079 Date: Sat, 8 Aug 2020 15:55:17 +0900 Subject: [PATCH] Fixed some images crashing Added auto pageturn timer --- app/build.gradle | 2 +- app/release/output-metadata.json | 2 +- .../pupil/adapters/GalleryBlockAdapter.kt | 11 ++++++-- .../xyz/quaver/pupil/ui/ReaderActivity.kt | 26 +++++++++++++++++++ .../pupil/ui/fragment/SettingsFragment.kt | 15 ++++++----- app/src/main/res/drawable/clock_end.xml | 8 ++++++ app/src/main/res/drawable/clock_start.xml | 8 ++++++ app/src/main/res/layout/activity_reader.xml | 7 +++++ app/src/main/res/values-ja/strings.xml | 1 + app/src/main/res/values-ko/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + .../src/main/java/xyz/quaver/hitomi/common.kt | 14 +++++++--- .../test/java/xyz/quaver/hitomi/UnitTest.kt | 7 +++++ 13 files changed, 89 insertions(+), 14 deletions(-) create mode 100644 app/src/main/res/drawable/clock_end.xml create mode 100644 app/src/main/res/drawable/clock_start.xml diff --git a/app/build.gradle b/app/build.gradle index d85819b5..8e4771d2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,7 +20,7 @@ android { minSdkVersion 16 targetSdkVersion 29 versionCode 57 - versionName "4.20-hotfix2" + versionName "4.21" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" multiDexEnabled true vectorDrawables.useSupportLibrary = true diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json index dd0cc893..c94127f9 100644 --- a/app/release/output-metadata.json +++ b/app/release/output-metadata.json @@ -12,7 +12,7 @@ "filters": [], "properties": [], "versionCode": 57, - "versionName": "4.20-hotfix2", + "versionName": "4.21", "enabled": true, "outputFile": "app-release.apk" } diff --git a/app/src/main/java/xyz/quaver/pupil/adapters/GalleryBlockAdapter.kt b/app/src/main/java/xyz/quaver/pupil/adapters/GalleryBlockAdapter.kt index c2886904..2daaa392 100644 --- a/app/src/main/java/xyz/quaver/pupil/adapters/GalleryBlockAdapter.kt +++ b/app/src/main/java/xyz/quaver/pupil/adapters/GalleryBlockAdapter.kt @@ -19,6 +19,9 @@ package xyz.quaver.pupil.adapters import android.content.Context +import android.graphics.Color +import android.graphics.PorterDuff +import android.graphics.PorterDuffColorFilter import android.graphics.drawable.Drawable import android.util.Base64 import android.util.SparseBooleanArray @@ -221,12 +224,16 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri "male" -> { setChipBackgroundColorResource(R.color.material_blue_700) setTextColor(ContextCompat.getColor(context, android.R.color.white)) - ContextCompat.getDrawable(context, R.drawable.gender_male) + ContextCompat.getDrawable(context, R.drawable.gender_male)?.apply { + colorFilter = PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP) + } } "female" -> { setChipBackgroundColorResource(R.color.material_pink_600) setTextColor(ContextCompat.getColor(context, android.R.color.white)) - ContextCompat.getDrawable(context, R.drawable.gender_female) + ContextCompat.getDrawable(context, R.drawable.gender_female)?.apply { + colorFilter = PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP) + } } else -> null } diff --git a/app/src/main/java/xyz/quaver/pupil/ui/ReaderActivity.kt b/app/src/main/java/xyz/quaver/pupil/ui/ReaderActivity.kt index f8c46611..9abdb37c 100644 --- a/app/src/main/java/xyz/quaver/pupil/ui/ReaderActivity.kt +++ b/app/src/main/java/xyz/quaver/pupil/ui/ReaderActivity.kt @@ -51,6 +51,7 @@ import xyz.quaver.pupil.util.download.Cache import xyz.quaver.pupil.util.download.DownloadWorker import java.util.* import kotlin.concurrent.schedule +import kotlin.concurrent.timer class ReaderActivity : AppCompatActivity() { @@ -71,6 +72,7 @@ class ReaderActivity : AppCompatActivity() { } private val timer = Timer() + private var autoTimer: Timer? = null private val snapHelper = PagerSnapHelper() @@ -380,6 +382,30 @@ class ReaderActivity : AppCompatActivity() { } } + with(reader_fab_auto) { + setImageResource(R.drawable.clock_start) + setOnClickListener { + if (autoTimer == null) { + autoTimer = timer(initialDelay = 10000L, period = 10000L) { + CoroutineScope(Dispatchers.Main).launch { + with(this@ReaderActivity.reader_recyclerview) { + val lastItem = + (layoutManager as LinearLayoutManager).findLastCompletelyVisibleItemPosition() + + if (lastItem < adapter!!.itemCount - 1) + (layoutManager as LinearLayoutManager).scrollToPosition(lastItem + 1) + } + } + } + setImageResource(R.drawable.clock_end) + } else { + autoTimer?.cancel() + autoTimer = null + setImageResource(R.drawable.clock_start) + } + } + } + with(reader_fab_fullscreen) { setImageResource(R.drawable.ic_fullscreen) setOnClickListener { diff --git a/app/src/main/java/xyz/quaver/pupil/ui/fragment/SettingsFragment.kt b/app/src/main/java/xyz/quaver/pupil/ui/fragment/SettingsFragment.kt index 233d8465..6973b2df 100644 --- a/app/src/main/java/xyz/quaver/pupil/ui/fragment/SettingsFragment.kt +++ b/app/src/main/java/xyz/quaver/pupil/ui/fragment/SettingsFragment.kt @@ -79,13 +79,16 @@ class SettingsFragment : } private fun getDirSize(dir: File) : String { - return getString(R.string.settings_storage_usage, - Runtime.getRuntime().exec("du -hs " + dir.absolutePath).let { - BufferedReader(InputStreamReader(it.inputStream)).use { reader -> - reader.readLine()?.split('\t')?.firstOrNull() ?: "0" + return if (activity != null) + getString(R.string.settings_storage_usage, + Runtime.getRuntime().exec("du -hs " + dir.absolutePath).let { + BufferedReader(InputStreamReader(it.inputStream)).use { reader -> + reader.readLine()?.split('\t')?.firstOrNull() ?: "0" + } } - } - ) + ) + else + "" } override fun onPreferenceClick(preference: Preference?): Boolean { diff --git a/app/src/main/res/drawable/clock_end.xml b/app/src/main/res/drawable/clock_end.xml new file mode 100644 index 00000000..fc81a0d0 --- /dev/null +++ b/app/src/main/res/drawable/clock_end.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/clock_start.xml b/app/src/main/res/drawable/clock_start.xml new file mode 100644 index 00000000..a4880732 --- /dev/null +++ b/app/src/main/res/drawable/clock_start.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_reader.xml b/app/src/main/res/layout/activity_reader.xml index dba09170..5bf25441 100644 --- a/app/src/main/res/layout/activity_reader.xml +++ b/app/src/main/res/layout/activity_reader.xml @@ -82,6 +82,13 @@ app:fab_label="@string/reader_fab_retry" app:fab_size="mini"/> + + ユーザーIDをクリップボードにコピーしました ダウンロードエラーが発生しました。リトライしますか? リトライ + 自動スクロール \ No newline at end of file diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 6b8ec322..51409db7 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -151,4 +151,5 @@ 유저 ID를 클립보드에 복사했습니다 다운로드 에러가 발생했습니. 재시도 하시겠습니까? 재시도 + 자동 스크롤 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f23b1e29..2f01ac8d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -115,6 +115,7 @@ Go to page Fullscreen> Retry + Automatic scroll Background download Cancel background download Downloading… diff --git a/libpupil/src/main/java/xyz/quaver/hitomi/common.kt b/libpupil/src/main/java/xyz/quaver/hitomi/common.kt index 56eea8c0..889950e2 100644 --- a/libpupil/src/main/java/xyz/quaver/hitomi/common.kt +++ b/libpupil/src/main/java/xyz/quaver/hitomi/common.kt @@ -33,12 +33,11 @@ fun getGalleryInfo(galleryID: Int) = //common.js var adapose = false -const val numberOfFrontends = 3 const val domain = "ltn.hitomi.la" const val galleryblockdir = "galleryblock" const val nozomiextension = ".nozomi" -fun subdomainFromGalleryID(g: Int) : String { +fun subdomainFromGalleryID(g: Int, numberOfFrontends: Int) : String { if (adapose) return "0" @@ -53,13 +52,20 @@ fun subdomainFromURL(url: String, base: String? = null) : String { if (!base.isNullOrBlank()) retval = base + var numberOfFrontends = 3 val b = 16 + val r = Regex("""/[0-9a-f]/([0-9a-f]{2})/""") val m = r.find(url) ?: return retval - val g = m.groupValues[1].toIntOrNull(b) ?: return retval + var g = m.groupValues[1].toIntOrNull(b) ?: return retval + + when { + g < 0x30 -> numberOfFrontends = 2 + g < 0x09 -> g = 1 + } - retval = subdomainFromGalleryID(g) + retval + retval = subdomainFromGalleryID(g, numberOfFrontends) + retval return retval } diff --git a/libpupil/src/test/java/xyz/quaver/hitomi/UnitTest.kt b/libpupil/src/test/java/xyz/quaver/hitomi/UnitTest.kt index b818b7fb..d368cc41 100644 --- a/libpupil/src/test/java/xyz/quaver/hitomi/UnitTest.kt +++ b/libpupil/src/test/java/xyz/quaver/hitomi/UnitTest.kt @@ -80,6 +80,13 @@ class UnitTest { print(reader) } + @Test + fun test_getImages() { + val reader = getReader(1702206) + + print(urlFromUrlFromHash(1702206, reader.galleryInfo.files.first(), "webp")) + } + @Test fun test_hiyobi() { val reader = xyz.quaver.hiyobi.getReader(1664762)