From 69fc3ad4e8eb549ee4eca49c9fbeda7d50450b8d Mon Sep 17 00:00:00 2001 From: tom5079 Date: Sat, 2 Nov 2019 21:50:03 +0900 Subject: [PATCH 01/25] typo --- app/src/main/res/values-ko/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 8f3dfa95..5d8411d1 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -66,7 +66,7 @@ 갤러리 번호로 열기 갤러리를 찾지 못했습니다 저장 공간 - 디스코드햐 + 디스코드 앱 잠금 앱 잠금 종류 앱 버전 From c004c7f71a829f0c5becde3d7ef44f8187beba31 Mon Sep 17 00:00:00 2001 From: tom5079 Date: Fri, 15 Nov 2019 19:47:09 +0900 Subject: [PATCH 02/25] Fixed bug fetching old galleries from hiyobi --- libpupil/src/main/java/xyz/quaver/hitomi/reader.kt | 2 +- libpupil/src/test/java/xyz/quaver/hitomi/UnitTest.kt | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libpupil/src/main/java/xyz/quaver/hitomi/reader.kt b/libpupil/src/main/java/xyz/quaver/hitomi/reader.kt index 355a3a31..23c9174d 100644 --- a/libpupil/src/main/java/xyz/quaver/hitomi/reader.kt +++ b/libpupil/src/main/java/xyz/quaver/hitomi/reader.kt @@ -26,7 +26,7 @@ fun webpUrlFromUrl(url: String) = url.replace("/galleries/", "/webp/") + ".webp" data class GalleryInfo( val width: Int, val hash: String? = null, - val haswebp: Int, + val haswebp: Int = 0, val name: String, val height: Int ) diff --git a/libpupil/src/test/java/xyz/quaver/hitomi/UnitTest.kt b/libpupil/src/test/java/xyz/quaver/hitomi/UnitTest.kt index b838048c..b8ef33fd 100644 --- a/libpupil/src/test/java/xyz/quaver/hitomi/UnitTest.kt +++ b/libpupil/src/test/java/xyz/quaver/hitomi/UnitTest.kt @@ -20,6 +20,7 @@ package xyz.quaver.hitomi import org.junit.Assert.assertEquals import org.junit.Test +import xyz.quaver.availableInHiyobi class UnitTest { @Test @@ -92,4 +93,11 @@ class UnitTest { print(url) } + + @Test + fun test_availableInHiyobi() { + val result = availableInHiyobi(1272781) + + print(result) + } } \ No newline at end of file From 2197de98eaf5f33c6d79c4f0c35faab6aa711d40 Mon Sep 17 00:00:00 2001 From: tom5079 Date: Mon, 25 Nov 2019 19:39:17 +0900 Subject: [PATCH 03/25] Potential fix for too large bitmap crash --- .../main/java/xyz/quaver/pupil/adapters/ReaderAdapter.kt | 1 + build.gradle | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) 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 10e42f86..8e076d07 100644 --- a/app/src/main/java/xyz/quaver/pupil/adapters/ReaderAdapter.kt +++ b/app/src/main/java/xyz/quaver/pupil/adapters/ReaderAdapter.kt @@ -59,6 +59,7 @@ class ReaderAdapter(private val glide: RequestManager, if (BuildConfig.CENSOR) override(5, 8) } + .fitCenter() .into(holder.view) } diff --git a/build.gradle b/build.gradle index eb4a1760..bebf91df 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,18 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.50' + ext.kotlin_version = '1.3.60' repositories { google() jcenter() maven { url 'https://maven.fabric.io/public' } } dependencies { - classpath 'com.android.tools.build:gradle:3.5.1' + classpath 'com.android.tools.build:gradle:3.5.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" - classpath 'com.google.gms:google-services:4.3.2' + classpath 'com.google.gms:google-services:4.3.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files classpath 'io.fabric.tools:gradle:1.29.0' From a97af592600497faa40e66d479982f386ad394b3 Mon Sep 17 00:00:00 2001 From: tom5079 Date: Sat, 30 Nov 2019 15:09:53 +0900 Subject: [PATCH 04/25] Potential fix for memory issues --- app/build.gradle | 12 ++++++------ .../xyz/quaver/pupil/adapters/GalleryBlockAdapter.kt | 1 + .../xyz/quaver/pupil/adapters/ThumbnailAdapter.kt | 1 + app/src/main/res/xml/root_preferences.xml | 1 + 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1c4eaa06..efc6af29 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,8 +13,8 @@ android { applicationId "xyz.quaver.pupil" minSdkVersion 16 targetSdkVersion 29 - versionCode 30 - versionName "4.1" + versionCode 31 + versionName "4.2" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" multiDexEnabled true vectorDrawables.useSupportLibrary = true @@ -26,7 +26,7 @@ android { } buildTypes.each { it.buildConfigField('boolean', 'PRERELEASE', 'false') - it.buildConfigField('boolean', 'CENSOR', 'false') + it.buildConfigField('boolean', 'CENSOR', 'true') } } kotlinOptions { @@ -55,12 +55,12 @@ dependencies { implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' - implementation "androidx.biometric:biometric:1.0.0-rc02" + implementation "androidx.biometric:biometric:1.0.0" implementation 'com.android.support:multidex:1.0.3' implementation "com.daimajia.swipelayout:library:1.2.0@aar" - implementation 'com.google.android.material:material:1.2.0-alpha01' + implementation 'com.google.android.material:material:1.2.0-alpha02' implementation 'com.google.firebase:firebase-core:17.2.1' - implementation 'com.google.firebase:firebase-perf:19.0.1' + implementation 'com.google.firebase:firebase-perf:19.0.2' implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1' implementation 'com.github.arimorty:floatingsearchview:2.1.1' implementation 'com.github.clans:fab:1.6.4' 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 37d3ee0b..b070a21b 100644 --- a/app/src/main/java/xyz/quaver/pupil/adapters/GalleryBlockAdapter.kt +++ b/app/src/main/java/xyz/quaver/pupil/adapters/GalleryBlockAdapter.kt @@ -95,6 +95,7 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri if (BuildConfig.CENSOR) override(5, 8) } + .fitCenter() .into(galleryblock_thumbnail) } diff --git a/app/src/main/java/xyz/quaver/pupil/adapters/ThumbnailAdapter.kt b/app/src/main/java/xyz/quaver/pupil/adapters/ThumbnailAdapter.kt index db85c79d..759f7523 100644 --- a/app/src/main/java/xyz/quaver/pupil/adapters/ThumbnailAdapter.kt +++ b/app/src/main/java/xyz/quaver/pupil/adapters/ThumbnailAdapter.kt @@ -39,6 +39,7 @@ class ThumbnailAdapter(private val glide: RequestManager, private val thumbnails if (BuildConfig.CENSOR) override(5, 8) } + .fitCenter() .into(holder.view) } diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index 3af7023a..26738748 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -73,6 +73,7 @@ app:key="nomedia" app:title="@string/settings_nomedia_title" app:summary="@string/settings_nomedia_title"/> + From e497d4737421b0e9ddff8ad4d001c1eda85219fe Mon Sep 17 00:00:00 2001 From: tom5079 Date: Sat, 30 Nov 2019 15:10:25 +0900 Subject: [PATCH 05/25] Fix for bug caused by changed hiyobi domain --- libpupil/src/main/java/xyz/quaver/hiyobi/reader.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libpupil/src/main/java/xyz/quaver/hiyobi/reader.kt b/libpupil/src/main/java/xyz/quaver/hiyobi/reader.kt index 4873aef1..f1ce9222 100644 --- a/libpupil/src/main/java/xyz/quaver/hiyobi/reader.kt +++ b/libpupil/src/main/java/xyz/quaver/hiyobi/reader.kt @@ -26,7 +26,7 @@ import xyz.quaver.hitomi.protocol import java.net.URL import javax.net.ssl.HttpsURLConnection -const val hiyobi = "xn--9w3b15m8vo.asia" +const val hiyobi = "hiyobi.me" const val user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36" var cookie: String = "" From 74033b9f4a6dcd3d280553912d51bdf3621579c2 Mon Sep 17 00:00:00 2001 From: tom5079 Date: Sat, 30 Nov 2019 16:10:09 +0900 Subject: [PATCH 06/25] Issue #27 fix --- .../main/java/xyz/quaver/pupil/ui/MainActivity.kt | 13 ++++++++++++- .../test/java/xyz/quaver/pupil/ExampleUnitTest.kt | 7 ++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt b/app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt index 21f417fa..1cba2562 100644 --- a/app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt +++ b/app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt @@ -576,6 +576,17 @@ class MainActivity : AppCompatActivity() { } } + histories.remove(galleryID) + + if (this@MainActivity.mode == Mode.HISTORY) { + runOnUiThread { + cancelFetch() + clearGalleries() + fetchGalleries(query, sortMode) + loadBlocks() + } + } + completeFlag.put(galleryID, false) } @@ -1165,7 +1176,7 @@ class MainActivity : AppCompatActivity() { } } ?: return@async null - val thumbnail = async { + val thumbnail = async(Dispatchers.IO) { val ext = galleryBlock.thumbnails[0].split('.').last() File(getCachedGallery(this@MainActivity, galleryBlock.id), "thumbnail.$ext").apply { if (!exists()) diff --git a/app/src/test/java/xyz/quaver/pupil/ExampleUnitTest.kt b/app/src/test/java/xyz/quaver/pupil/ExampleUnitTest.kt index fae6b731..2aef6c6b 100644 --- a/app/src/test/java/xyz/quaver/pupil/ExampleUnitTest.kt +++ b/app/src/test/java/xyz/quaver/pupil/ExampleUnitTest.kt @@ -20,22 +20,19 @@ package xyz.quaver.pupil -import org.junit.Test - /** * Example local unit test, which will execute on the development machine (host). * * See [testing documentation](http://d.android.com/tools/testing). */ +import org.junit.Test + class ExampleUnitTest { @Test fun test() { - val current = "0.1" - val latest = "0.2" - print(current < latest) } } From 8d16950f46dcdf801abcea52da7a663ca3807f3b Mon Sep 17 00:00:00 2001 From: tom5079 Date: Sat, 30 Nov 2019 16:10:47 +0900 Subject: [PATCH 07/25] Issue #27 fix --- app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt b/app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt index 1cba2562..f268d9a0 100644 --- a/app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt +++ b/app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt @@ -1176,7 +1176,7 @@ class MainActivity : AppCompatActivity() { } } ?: return@async null - val thumbnail = async(Dispatchers.IO) { + val thumbnail = async { val ext = galleryBlock.thumbnails[0].split('.').last() File(getCachedGallery(this@MainActivity, galleryBlock.id), "thumbnail.$ext").apply { if (!exists()) From f98f45dc54338bb717e44dc6db2154197b2e1cd7 Mon Sep 17 00:00:00 2001 From: tom5079 Date: Sun, 1 Dec 2019 16:58:29 +0900 Subject: [PATCH 08/25] Pupil-24 Absence of backing up favorites feature --- .../quaver/pupil/ExampleInstrumentedTest.kt | 6 +- app/src/main/AndroidManifest.xml | 12 +++ .../pupil/adapters/GalleryBlockAdapter.kt | 2 +- .../xyz/quaver/pupil/ui/SettingsActivity.kt | 90 ++++++++++++++++++- .../main/java/xyz/quaver/pupil/util/file.kt | 4 +- app/src/main/res/values-ja/strings.xml | 6 ++ app/src/main/res/values-ko/strings.xml | 6 ++ app/src/main/res/values/strings.xml | 7 +- app/src/main/res/xml/file_paths.xml | 22 +++++ app/src/main/res/xml/root_preferences.xml | 8 ++ 10 files changed, 154 insertions(+), 9 deletions(-) create mode 100644 app/src/main/res/xml/file_paths.xml diff --git a/app/src/androidTest/java/xyz/quaver/pupil/ExampleInstrumentedTest.kt b/app/src/androidTest/java/xyz/quaver/pupil/ExampleInstrumentedTest.kt index 6d23423b..4f3ce3c8 100644 --- a/app/src/androidTest/java/xyz/quaver/pupil/ExampleInstrumentedTest.kt +++ b/app/src/androidTest/java/xyz/quaver/pupil/ExampleInstrumentedTest.kt @@ -33,6 +33,7 @@ import xyz.quaver.hiyobi.createImgList import xyz.quaver.hiyobi.getReader import xyz.quaver.hiyobi.user_agent import xyz.quaver.pupil.ui.LockActivity +import xyz.quaver.pupil.util.getDownloadDirectory import java.net.URL import javax.net.ssl.HttpsURLConnection @@ -48,6 +49,7 @@ class ExampleInstrumentedTest { fun useAppContext() { // Context of the app under test. val appContext = InstrumentationRegistry.getInstrumentation().targetContext + Log.i("PUPILD", getDownloadDirectory(appContext).absolutePath ?: "") assertEquals("xyz.quaver.pupil", appContext.packageName) } @@ -57,8 +59,6 @@ class ExampleInstrumentedTest { val appContext = InstrumentationRegistry.getInstrumentation().targetContext activityTestRule.launchActivity(Intent()) - - while(true); } @Test @@ -76,4 +76,4 @@ class ExampleInstrumentedTest { Log.d("Pupil", data.size.toString()) } -} +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index be11229f..ac068015 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -20,6 +20,18 @@ android:theme="@style/AppTheme" tools:replace="android:theme"> + + + + + + holder.view.context.getString(R.string.main_download) - else -> holder.view.context.getString(R.string.main_cancel_download) + else -> holder.view.context.getString(android.R.string.cancel) } } diff --git a/app/src/main/java/xyz/quaver/pupil/ui/SettingsActivity.kt b/app/src/main/java/xyz/quaver/pupil/ui/SettingsActivity.kt index 0e28613b..0ecf34c0 100644 --- a/app/src/main/java/xyz/quaver/pupil/ui/SettingsActivity.kt +++ b/app/src/main/java/xyz/quaver/pupil/ui/SettingsActivity.kt @@ -32,10 +32,16 @@ import android.widget.TextView import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatDelegate +import androidx.core.content.ContextCompat +import androidx.core.content.FileProvider import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceManager +import com.google.android.material.snackbar.Snackbar import kotlinx.android.synthetic.main.dialog_default_query.view.* +import kotlinx.serialization.ImplicitReflectionSerializer +import kotlinx.serialization.json.Json +import kotlinx.serialization.parseList import xyz.quaver.pupil.Pupil import xyz.quaver.pupil.R import xyz.quaver.pupil.types.Tags @@ -43,10 +49,13 @@ import xyz.quaver.pupil.util.Lock import xyz.quaver.pupil.util.LockManager import xyz.quaver.pupil.util.getDownloadDirectory import java.io.File +import java.nio.charset.Charset +import java.util.* class SettingsActivity : AppCompatActivity() { val REQUEST_LOCK = 38238 + val REQUEST_RESTORE = 16546 override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -154,7 +163,7 @@ class SettingsActivity : AppCompatActivity() { with(findPreference("delete_downloads")) { this!! - val dir = getDownloadDirectory(context)!! + val dir = getDownloadDirectory(context) summary = getDirSize(dir) @@ -278,7 +287,7 @@ class SettingsActivity : AppCompatActivity() { s ?: return if (s.any { it.isUpperCase() }) - s.replace(0, s.length, s.toString().toLowerCase()) + s.replace(0, s.length, s.toString().toLowerCase(Locale.getDefault())) } }) } @@ -352,6 +361,55 @@ class SettingsActivity : AppCompatActivity() { true } } + + with(findPreference("backup")) { + this!! + + onPreferenceClickListener = Preference.OnPreferenceClickListener { + File(ContextCompat.getDataDir(context), "favorites.json").copyTo( + File(getDownloadDirectory(context), "favorites.json"), + true + ) + + Snackbar.make(this@SettingsFragment.listView, R.string.settings_backup_snackbar, Snackbar.LENGTH_LONG) + .setAction(R.string.settings_backup_checkout) { + + //Open folder that contains copied favorite file + val intent = Intent(Intent.ACTION_VIEW).apply { + val uri = FileProvider.getUriForFile(context, + "xyz.quaver.pupil.fileprovider", + getDownloadDirectory(context) + ) + + context.grantUriPermission(context.packageName, uri, + Intent.FLAG_GRANT_READ_URI_PERMISSION) + addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + + setDataAndType(uri, "resource/folder") + } + + startActivity(Intent.createChooser(intent , "Open folder")) + + }.show() + + true + } + } + + with(findPreference("restore")) { + this!! + + onPreferenceClickListener = Preference.OnPreferenceClickListener { + val intent = Intent(Intent.ACTION_GET_CONTENT).apply { + addCategory(Intent.CATEGORY_OPENABLE) + type = "*/*" + } + + activity?.startActivityForResult(intent, (activity as SettingsActivity).REQUEST_RESTORE) + + true + } + } } } @@ -415,6 +473,7 @@ class SettingsActivity : AppCompatActivity() { return true } + @UseExperimental(ImplicitReflectionSerializer::class) override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { when(requestCode) { REQUEST_LOCK -> { @@ -426,6 +485,33 @@ class SettingsActivity : AppCompatActivity() { .commitAllowingStateLoss() } } + REQUEST_RESTORE -> { + if (resultCode == Activity.RESULT_OK) { + val uri = data?.data ?: return + + try { + val json = contentResolver.openInputStream(uri).use { inputStream -> + inputStream!! + + inputStream.readBytes().toString(Charset.defaultCharset()) + } + + (application as Pupil).favorites.addAll(Json.parseList(json).also { + Snackbar.make( + window.decorView, + getString(R.string.settings_restore_successful, it.size), + Snackbar.LENGTH_LONG + ).show() + }) + } catch (e: Exception) { + Snackbar.make( + window.decorView, + R.string.settings_restore_failed, + Snackbar.LENGTH_LONG + ).show() + } + } + } else -> super.onActivityResult(requestCode, resultCode, data) } } 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 d1f3ba47..84342718 100644 --- a/app/src/main/java/xyz/quaver/pupil/util/file.kt +++ b/app/src/main/java/xyz/quaver/pupil/util/file.kt @@ -33,9 +33,9 @@ fun getCachedGallery(context: Context, galleryID: Int): File { } @Suppress("DEPRECATION") -fun getDownloadDirectory(context: Context): File? { +fun getDownloadDirectory(context: Context): File { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) - context.getExternalFilesDir("Pupil") + context.getExternalFilesDir("Pupil")!! else File(Environment.getExternalStorageDirectory(), "Pupil") } \ No newline at end of file diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 4cf3b38f..0c7f4353 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -105,4 +105,10 @@ 削除 ダウンロード キャンセル + お気に入りバックアップ + お気に入り復元 + バックアップファイルを作成しました + 確認 + 復元に失敗しました + %1$d項目を復元しました \ 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 5d8411d1..2965ce52 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -105,4 +105,10 @@ 삭제 다운로드 취소 + 즐겨찾기 백업 + 즐겨찾기 복원 + 백업 파일을 생성하였습니다 + 확인 + 복원에 실패했습니다 + %1$d개 항목을 복원했습니다 \ 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 513ec686..5f695d13 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -72,7 +72,6 @@ Error occurred during export DOWNLOAD - CANCEL DELETE Update available @@ -133,6 +132,12 @@ Protect yourself against light attacks! Hide image from gallery Hides image from gallery + Backup favorites + Backup file created + Check out + Restore favorites + Restore failed + %1$d entries restored None Pattern diff --git a/app/src/main/res/xml/file_paths.xml b/app/src/main/res/xml/file_paths.xml new file mode 100644 index 00000000..5992f8d4 --- /dev/null +++ b/app/src/main/res/xml/file_paths.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index 26738748..244a015f 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -74,6 +74,14 @@ app:title="@string/settings_nomedia_title" app:summary="@string/settings_nomedia_title"/> + + + + From 5052b6c074aebabfd8655ac2ba08ab471519f8e8 Mon Sep 17 00:00:00 2001 From: tom5079 Date: Mon, 2 Dec 2019 18:55:38 +0900 Subject: [PATCH 09/25] Removed folder opening feature due to its unstability --- app/build.gradle | 2 +- .../xyz/quaver/pupil/ui/SettingsActivity.kt | 21 +------------------ 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index efc6af29..5ef38efd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,7 +14,7 @@ android { minSdkVersion 16 targetSdkVersion 29 versionCode 31 - versionName "4.2" + versionName "4.2-beta1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" multiDexEnabled true vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/xyz/quaver/pupil/ui/SettingsActivity.kt b/app/src/main/java/xyz/quaver/pupil/ui/SettingsActivity.kt index 0ecf34c0..60f9a724 100644 --- a/app/src/main/java/xyz/quaver/pupil/ui/SettingsActivity.kt +++ b/app/src/main/java/xyz/quaver/pupil/ui/SettingsActivity.kt @@ -33,7 +33,6 @@ import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatDelegate import androidx.core.content.ContextCompat -import androidx.core.content.FileProvider import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceManager @@ -372,25 +371,7 @@ class SettingsActivity : AppCompatActivity() { ) Snackbar.make(this@SettingsFragment.listView, R.string.settings_backup_snackbar, Snackbar.LENGTH_LONG) - .setAction(R.string.settings_backup_checkout) { - - //Open folder that contains copied favorite file - val intent = Intent(Intent.ACTION_VIEW).apply { - val uri = FileProvider.getUriForFile(context, - "xyz.quaver.pupil.fileprovider", - getDownloadDirectory(context) - ) - - context.grantUriPermission(context.packageName, uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION) - addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - - setDataAndType(uri, "resource/folder") - } - - startActivity(Intent.createChooser(intent , "Open folder")) - - }.show() + .show() true } From 295285f132c18df4dc7f2aee4882c91d7ccea6e7 Mon Sep 17 00:00:00 2001 From: tom5079 Date: Mon, 2 Dec 2019 19:04:09 +0900 Subject: [PATCH 10/25] Turned off development only option --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 5ef38efd..8576c6f5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,7 +26,7 @@ android { } buildTypes.each { it.buildConfigField('boolean', 'PRERELEASE', 'false') - it.buildConfigField('boolean', 'CENSOR', 'true') + it.buildConfigField('boolean', 'CENSOR', 'false') } } kotlinOptions { From db5a221b56a9e7852c07b1fd12f2dae4abbcaefa Mon Sep 17 00:00:00 2001 From: tom5079 Date: Sun, 8 Dec 2019 18:10:35 +0900 Subject: [PATCH 11/25] kotlin plugin update --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index bebf91df..12b58e00 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.60' + ext.kotlin_version = '1.3.61' repositories { google() jcenter() maven { url 'https://maven.fabric.io/public' } } dependencies { - classpath 'com.android.tools.build:gradle:3.5.2' + classpath 'com.android.tools.build:gradle:3.5.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" From 0561d5f55cff9bf14b8fdea7e1669a47d469e3c8 Mon Sep 17 00:00:00 2001 From: tom5079 Date: Mon, 9 Dec 2019 09:36:36 +0900 Subject: [PATCH 12/25] Added code for saved reader --- .../java/xyz/quaver/pupil/util/GalleryDownloader.kt | 3 +-- libpupil/src/main/java/xyz/quaver/hitomi/reader.kt | 10 ++++++++-- libpupil/src/main/java/xyz/quaver/hiyobi/reader.kt | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/xyz/quaver/pupil/util/GalleryDownloader.kt b/app/src/main/java/xyz/quaver/pupil/util/GalleryDownloader.kt index 32a18e34..e942f0c8 100644 --- a/app/src/main/java/xyz/quaver/pupil/util/GalleryDownloader.kt +++ b/app/src/main/java/xyz/quaver/pupil/util/GalleryDownloader.kt @@ -31,7 +31,6 @@ import com.crashlytics.android.Crashlytics import kotlinx.coroutines.* import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonConfiguration -import xyz.quaver.availableInHiyobi import xyz.quaver.hitomi.Reader import xyz.quaver.hitomi.getReader import xyz.quaver.hitomi.getReferer @@ -124,7 +123,7 @@ class GalleryDownloader( val cached = json.parse(serializer, cache.readText()) if (cached.galleryInfo.isNotEmpty()) { - useHiyobi = availableInHiyobi(galleryID) + useHiyobi = cached.code == Reader.Code.HIYOBI onReaderLoadedHandler?.invoke(cached) diff --git a/libpupil/src/main/java/xyz/quaver/hitomi/reader.kt b/libpupil/src/main/java/xyz/quaver/hitomi/reader.kt index 23c9174d..b02df73f 100644 --- a/libpupil/src/main/java/xyz/quaver/hitomi/reader.kt +++ b/libpupil/src/main/java/xyz/quaver/hitomi/reader.kt @@ -32,7 +32,13 @@ data class GalleryInfo( ) @Serializable -open class Reader(val title: String, val galleryInfo: List) +class Reader(val code:Code, val title: String, val galleryInfo: List) { + enum class Code { + HITOMI, + HIYOBI, + SORALA + } +} //Set header `Referer` to reader url to avoid 403 error fun getReader(galleryID: Int) : Reader { @@ -40,5 +46,5 @@ fun getReader(galleryID: Int) : Reader { val doc = Jsoup.connect(readerUrl).get() - return Reader(doc.title(), getGalleryInfo(galleryID)) + return Reader(Reader.Code.HITOMI, doc.title(), getGalleryInfo(galleryID)) } \ No newline at end of file diff --git a/libpupil/src/main/java/xyz/quaver/hiyobi/reader.kt b/libpupil/src/main/java/xyz/quaver/hiyobi/reader.kt index f1ce9222..07c0a357 100644 --- a/libpupil/src/main/java/xyz/quaver/hiyobi/reader.kt +++ b/libpupil/src/main/java/xyz/quaver/hiyobi/reader.kt @@ -76,7 +76,7 @@ fun getReader(galleryID: Int) : Reader { } ) - return Reader(title, galleryInfo) + return Reader(Reader.Code.HIYOBI, title, galleryInfo) } fun createImgList(galleryID: Int, reader: Reader) = From 3f827d1bad2bbd42724007fe436478a765204941 Mon Sep 17 00:00:00 2001 From: tom5079 Date: Mon, 9 Dec 2019 10:15:53 +0900 Subject: [PATCH 13/25] bug fix --- libpupil/src/main/java/xyz/quaver/hitomi/common.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libpupil/src/main/java/xyz/quaver/hitomi/common.kt b/libpupil/src/main/java/xyz/quaver/hitomi/common.kt index 11c14bee..483fb7bf 100644 --- a/libpupil/src/main/java/xyz/quaver/hitomi/common.kt +++ b/libpupil/src/main/java/xyz/quaver/hitomi/common.kt @@ -79,7 +79,7 @@ fun urlFromURL(url: String, base: String? = null) : String { fun fullPathFromHash(hash: String?) : String? { return when { - hash?.length ?: 0 < 3 -> hash + (hash?.length ?: 0) < 3 -> hash else -> hash!!.replace(Regex("^.*(..)(.)$"), "$2/$1/$hash") } } From 865bf0ba83cab185fc75e145b8efef9ff38a6d1d Mon Sep 17 00:00:00 2001 From: tom5079 Date: Mon, 9 Dec 2019 10:33:26 +0900 Subject: [PATCH 14/25] Added code for differentiating readers --- libpupil/src/main/java/xyz/quaver/hitomi/reader.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libpupil/src/main/java/xyz/quaver/hitomi/reader.kt b/libpupil/src/main/java/xyz/quaver/hitomi/reader.kt index b02df73f..4ed503a9 100644 --- a/libpupil/src/main/java/xyz/quaver/hitomi/reader.kt +++ b/libpupil/src/main/java/xyz/quaver/hitomi/reader.kt @@ -32,7 +32,7 @@ data class GalleryInfo( ) @Serializable -class Reader(val code:Code, val title: String, val galleryInfo: List) { +data class Reader(val code: Code, val title: String, val galleryInfo: List) { enum class Code { HITOMI, HIYOBI, From 52c05e6888ab5283a603f8772158614616f85dc0 Mon Sep 17 00:00:00 2001 From: tom5079 Date: Wed, 11 Dec 2019 19:52:25 +0900 Subject: [PATCH 15/25] fixed #31 on libpupil #TODO: fix app side to completely resolve the issue --- .../src/main/java/xyz/quaver/hitomi/common.kt | 17 ++++++++++------- .../src/test/java/xyz/quaver/hitomi/UnitTest.kt | 6 +++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/libpupil/src/main/java/xyz/quaver/hitomi/common.kt b/libpupil/src/main/java/xyz/quaver/hitomi/common.kt index 483fb7bf..ee84c3e2 100644 --- a/libpupil/src/main/java/xyz/quaver/hitomi/common.kt +++ b/libpupil/src/main/java/xyz/quaver/hitomi/common.kt @@ -51,7 +51,7 @@ fun subdomainFromGalleryID(g: Int) : String { fun subdomainFromURL(url: String, base: String? = null) : String { var retval = "a" - if (!base.isNullOrEmpty()) + if (!base.isNullOrBlank()) retval = base val r = Regex("""/galleries/\d*(\d)/""") @@ -60,7 +60,7 @@ fun subdomainFromURL(url: String, base: String? = null) : String { if (m == null) { b = 16 - val r2 = Regex("""/images/[0-9a-f]/([0-9a-f]{2})/""") + val r2 = Regex("""/[0-9a-f]/([0-9a-f]{2})/""") m = r2.find(url) if (m == null) return retval @@ -84,12 +84,15 @@ fun fullPathFromHash(hash: String?) : String? { } } -fun urlFromHash(galleryID: Int, image: GalleryInfo, oldMethod: Boolean) : String { +fun urlFromHash(galleryID: Int, image: GalleryInfo, webp: String? = null) : String { + val ext = webp ?: image.name.split('.').last() return when { - oldMethod or image.hash.isNullOrEmpty() -> "$protocol//a.hitomi.la/galleries/$galleryID/${image.name}" - else -> "$protocol//a.hitomi.la/images/${fullPathFromHash(image.hash)}.${image.name.split('.').last()}" + image.hash.isNullOrBlank() -> + "$protocol//a.hitomi.la/galleries/$galleryID/${image.name}" + else -> + "$protocol//a.hitomi.la/${webp?:"images"}/${fullPathFromHash(image.hash)}.$ext" } } -fun urlFromUrlFromHash(galleryID: Int, image: GalleryInfo, oldMethod: Boolean = false) = - urlFromURL(urlFromHash(galleryID, image, oldMethod)) \ No newline at end of file +fun urlFromUrlFromHash(galleryID: Int, image: GalleryInfo, webp: String? = null) = + urlFromURL(urlFromHash(galleryID, image, webp)) \ No newline at end of file diff --git a/libpupil/src/test/java/xyz/quaver/hitomi/UnitTest.kt b/libpupil/src/test/java/xyz/quaver/hitomi/UnitTest.kt index b8ef33fd..7d40a893 100644 --- a/libpupil/src/test/java/xyz/quaver/hitomi/UnitTest.kt +++ b/libpupil/src/test/java/xyz/quaver/hitomi/UnitTest.kt @@ -87,9 +87,9 @@ class UnitTest { @Test fun test_urlFromUrlFromHash() { - val url = urlFromUrlFromHash(1510702, GalleryInfo( - 210, "56e9e1b8bb72194777ed93fee11b06070b905039dd11348b070bcf1793aaed7b", 1, "6.jpg", 300 - )) + val url = urlFromUrlFromHash(1531795, GalleryInfo( + 212, "719d46a7556be0d0021c5105878507129b5b3308b02cf67f18901b69dbb3b5ef", 1, "00.jpg", 300 + ), "webp") print(url) } From fa6b3ad7bad6f60430d24a3bbd7e57e46676ff01 Mon Sep 17 00:00:00 2001 From: tom5079 Date: Wed, 11 Dec 2019 20:03:55 +0900 Subject: [PATCH 16/25] resolves #31 --- .../xyz/quaver/pupil/util/GalleryDownloader.kt | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/xyz/quaver/pupil/util/GalleryDownloader.kt b/app/src/main/java/xyz/quaver/pupil/util/GalleryDownloader.kt index 32a18e34..55109694 100644 --- a/app/src/main/java/xyz/quaver/pupil/util/GalleryDownloader.kt +++ b/app/src/main/java/xyz/quaver/pupil/util/GalleryDownloader.kt @@ -187,15 +187,11 @@ class GalleryDownloader( async(Dispatchers.IO) { val url = when(useHiyobi) { true -> createImgList(galleryID, reader)[index].path - false -> when (galleryInfo.haswebp) { - 1 -> webpUrlFromUrl( - urlFromUrlFromHash( - galleryID, - galleryInfo, - true - ) - ) - else -> urlFromUrlFromHash(galleryID, galleryInfo) + false -> when { + (!galleryInfo.hash.isNullOrBlank()) and (galleryInfo.haswebp == 1) -> + urlFromUrlFromHash(galleryID, galleryInfo, "webp") + else -> + urlFromUrlFromHash(galleryID, galleryInfo) } } From 4eef0b93fb9aafb3530e49d72a807f53c91b64ea Mon Sep 17 00:00:00 2001 From: tom5079 Date: Mon, 9 Dec 2019 10:15:53 +0900 Subject: [PATCH 17/25] bug fix --- libpupil/src/main/java/xyz/quaver/hitomi/common.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libpupil/src/main/java/xyz/quaver/hitomi/common.kt b/libpupil/src/main/java/xyz/quaver/hitomi/common.kt index 11c14bee..483fb7bf 100644 --- a/libpupil/src/main/java/xyz/quaver/hitomi/common.kt +++ b/libpupil/src/main/java/xyz/quaver/hitomi/common.kt @@ -79,7 +79,7 @@ fun urlFromURL(url: String, base: String? = null) : String { fun fullPathFromHash(hash: String?) : String? { return when { - hash?.length ?: 0 < 3 -> hash + (hash?.length ?: 0) < 3 -> hash else -> hash!!.replace(Regex("^.*(..)(.)$"), "$2/$1/$hash") } } From 657fb488eef2d4fc3160c31f0130eb8cdb10bd91 Mon Sep 17 00:00:00 2001 From: tom5079 Date: Wed, 11 Dec 2019 19:52:25 +0900 Subject: [PATCH 18/25] fixed #31 on libpupil #TODO: fix app side to completely resolve the issue --- .../src/main/java/xyz/quaver/hitomi/common.kt | 17 ++++++++++------- .../src/test/java/xyz/quaver/hitomi/UnitTest.kt | 6 +++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/libpupil/src/main/java/xyz/quaver/hitomi/common.kt b/libpupil/src/main/java/xyz/quaver/hitomi/common.kt index 483fb7bf..ee84c3e2 100644 --- a/libpupil/src/main/java/xyz/quaver/hitomi/common.kt +++ b/libpupil/src/main/java/xyz/quaver/hitomi/common.kt @@ -51,7 +51,7 @@ fun subdomainFromGalleryID(g: Int) : String { fun subdomainFromURL(url: String, base: String? = null) : String { var retval = "a" - if (!base.isNullOrEmpty()) + if (!base.isNullOrBlank()) retval = base val r = Regex("""/galleries/\d*(\d)/""") @@ -60,7 +60,7 @@ fun subdomainFromURL(url: String, base: String? = null) : String { if (m == null) { b = 16 - val r2 = Regex("""/images/[0-9a-f]/([0-9a-f]{2})/""") + val r2 = Regex("""/[0-9a-f]/([0-9a-f]{2})/""") m = r2.find(url) if (m == null) return retval @@ -84,12 +84,15 @@ fun fullPathFromHash(hash: String?) : String? { } } -fun urlFromHash(galleryID: Int, image: GalleryInfo, oldMethod: Boolean) : String { +fun urlFromHash(galleryID: Int, image: GalleryInfo, webp: String? = null) : String { + val ext = webp ?: image.name.split('.').last() return when { - oldMethod or image.hash.isNullOrEmpty() -> "$protocol//a.hitomi.la/galleries/$galleryID/${image.name}" - else -> "$protocol//a.hitomi.la/images/${fullPathFromHash(image.hash)}.${image.name.split('.').last()}" + image.hash.isNullOrBlank() -> + "$protocol//a.hitomi.la/galleries/$galleryID/${image.name}" + else -> + "$protocol//a.hitomi.la/${webp?:"images"}/${fullPathFromHash(image.hash)}.$ext" } } -fun urlFromUrlFromHash(galleryID: Int, image: GalleryInfo, oldMethod: Boolean = false) = - urlFromURL(urlFromHash(galleryID, image, oldMethod)) \ No newline at end of file +fun urlFromUrlFromHash(galleryID: Int, image: GalleryInfo, webp: String? = null) = + urlFromURL(urlFromHash(galleryID, image, webp)) \ No newline at end of file diff --git a/libpupil/src/test/java/xyz/quaver/hitomi/UnitTest.kt b/libpupil/src/test/java/xyz/quaver/hitomi/UnitTest.kt index b8ef33fd..7d40a893 100644 --- a/libpupil/src/test/java/xyz/quaver/hitomi/UnitTest.kt +++ b/libpupil/src/test/java/xyz/quaver/hitomi/UnitTest.kt @@ -87,9 +87,9 @@ class UnitTest { @Test fun test_urlFromUrlFromHash() { - val url = urlFromUrlFromHash(1510702, GalleryInfo( - 210, "56e9e1b8bb72194777ed93fee11b06070b905039dd11348b070bcf1793aaed7b", 1, "6.jpg", 300 - )) + val url = urlFromUrlFromHash(1531795, GalleryInfo( + 212, "719d46a7556be0d0021c5105878507129b5b3308b02cf67f18901b69dbb3b5ef", 1, "00.jpg", 300 + ), "webp") print(url) } From 55ee841bd03a340eb87293cf6ac883c79d5bac1c Mon Sep 17 00:00:00 2001 From: tom5079 Date: Wed, 11 Dec 2019 20:03:55 +0900 Subject: [PATCH 19/25] resolves #31 --- .../xyz/quaver/pupil/util/GalleryDownloader.kt | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/xyz/quaver/pupil/util/GalleryDownloader.kt b/app/src/main/java/xyz/quaver/pupil/util/GalleryDownloader.kt index e942f0c8..07538401 100644 --- a/app/src/main/java/xyz/quaver/pupil/util/GalleryDownloader.kt +++ b/app/src/main/java/xyz/quaver/pupil/util/GalleryDownloader.kt @@ -186,15 +186,11 @@ class GalleryDownloader( async(Dispatchers.IO) { val url = when(useHiyobi) { true -> createImgList(galleryID, reader)[index].path - false -> when (galleryInfo.haswebp) { - 1 -> webpUrlFromUrl( - urlFromUrlFromHash( - galleryID, - galleryInfo, - true - ) - ) - else -> urlFromUrlFromHash(galleryID, galleryInfo) + false -> when { + (!galleryInfo.hash.isNullOrBlank()) and (galleryInfo.haswebp == 1) -> + urlFromUrlFromHash(galleryID, galleryInfo, "webp") + else -> + urlFromUrlFromHash(galleryID, galleryInfo) } } From d40b4f3748d8ac5b278a8593d15cc83637a6f320 Mon Sep 17 00:00:00 2001 From: tom5079 Date: Thu, 12 Dec 2019 20:14:55 +0900 Subject: [PATCH 20/25] Added update logic for outdated readers --- .../quaver/pupil/ExampleInstrumentedTest.kt | 34 ++++++++++++- .../main/java/xyz/quaver/pupil/util/update.kt | 49 +++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/app/src/androidTest/java/xyz/quaver/pupil/ExampleInstrumentedTest.kt b/app/src/androidTest/java/xyz/quaver/pupil/ExampleInstrumentedTest.kt index 4f3ce3c8..801d8d34 100644 --- a/app/src/androidTest/java/xyz/quaver/pupil/ExampleInstrumentedTest.kt +++ b/app/src/androidTest/java/xyz/quaver/pupil/ExampleInstrumentedTest.kt @@ -25,6 +25,10 @@ import android.util.Log import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry import androidx.test.rule.ActivityTestRule +import kotlinx.serialization.ImplicitReflectionSerializer +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonConfiguration +import kotlinx.serialization.json.JsonObject import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith @@ -34,6 +38,7 @@ import xyz.quaver.hiyobi.getReader import xyz.quaver.hiyobi.user_agent import xyz.quaver.pupil.ui.LockActivity import xyz.quaver.pupil.util.getDownloadDirectory +import java.io.File import java.net.URL import javax.net.ssl.HttpsURLConnection @@ -63,7 +68,7 @@ class ExampleInstrumentedTest { @Test fun test_doSearch() { - val reader = getReader(1426382) + val reader = getReader( 1426382) val data: ByteArray @@ -76,4 +81,31 @@ class ExampleInstrumentedTest { Log.d("Pupil", data.size.toString()) } + + @UseExperimental(ImplicitReflectionSerializer::class) + @Test + fun test_deleteCodeFromReader() { + val context = InstrumentationRegistry.getInstrumentation().targetContext + + val json = Json(JsonConfiguration.Stable) + + listOf( + getDownloadDirectory(context), + File(context.cacheDir, "imageCache") + ).forEach { root -> + root.listFiles()?.forEach gallery@{ gallery -> + val reader = json.parseJson(File(gallery, "reader.json").apply { + if (!exists()) + return@gallery + }.readText()) + .jsonObject.toMutableMap() + + Log.d("PUPILD", gallery.name) + + reader.remove("code") + + File(gallery, "reader.json").writeText(JsonObject(reader).toString()) + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/xyz/quaver/pupil/util/update.kt b/app/src/main/java/xyz/quaver/pupil/util/update.kt index 1c48f8e5..31e4fda0 100644 --- a/app/src/main/java/xyz/quaver/pupil/util/update.kt +++ b/app/src/main/java/xyz/quaver/pupil/util/update.kt @@ -18,8 +18,13 @@ package xyz.quaver.pupil.util +import android.content.Context +import kotlinx.serialization.ImplicitReflectionSerializer import kotlinx.serialization.json.* +import xyz.quaver.availableInHiyobi +import xyz.quaver.hitomi.Reader import xyz.quaver.pupil.BuildConfig +import java.io.File import java.net.URL fun getReleases(url: String) : JsonArray { @@ -61,4 +66,48 @@ fun getApkUrl(releases: JsonObject) : Pair? { else Pair(it.jsonObject["browser_download_url"]?.content, it.jsonObject["name"]?.content) } +} + +fun getOldReaderGalleries(context: Context) : List { + val oldGallery = mutableListOf() + + listOf( + getDownloadDirectory(context), + File(context.cacheDir, "imageCache") + ).forEach { root -> + root.listFiles()?.forEach { gallery -> + File(gallery, "reader.json").let { readerFile -> + if (!readerFile.exists()) + return@let + + Json(JsonConfiguration.Stable).parseJson(readerFile.readText()).jsonObject.let { reader -> + if (!reader.contains("code")) + oldGallery.add(gallery) + } + } + } + } + + return oldGallery +} + +@UseExperimental(ImplicitReflectionSerializer::class) +fun updateOldReaderGalleries(context: Context) { + + val json = Json(JsonConfiguration.Stable) + + getOldReaderGalleries(context).forEach { gallery -> + val reader = json.parseJson(File(gallery, "reader.json").readText()) + .jsonObject.toMutableMap() + + reader["code"] = when { + (File(gallery, "images").list()?. + all { !it.endsWith("webp") } ?: return@forEach) && + availableInHiyobi(gallery.name.toInt()) -> json.toJson(Reader.Code.HIYOBI) + else -> json.toJson(Reader.Code.HITOMI) + } + + File(gallery, "reader.json").writeText(JsonObject(reader).toString()) + } + } \ No newline at end of file From ed4911c4412161805a13be150179418627555d88 Mon Sep 17 00:00:00 2001 From: tom5079 Date: Fri, 13 Dec 2019 18:39:12 +0900 Subject: [PATCH 21/25] Updated serialization library --- app/build.gradle | 4 ++-- .../java/xyz/quaver/pupil/ExampleInstrumentedTest.kt | 8 ++++++++ app/src/main/java/xyz/quaver/pupil/util/update.kt | 11 +++++++---- libpupil/build.gradle | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8576c6f5..02530dd6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -46,7 +46,7 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.1' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.1' - implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.11.0" + implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.14.0" implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.preference:preference:1.1.0' @@ -60,7 +60,7 @@ dependencies { implementation "com.daimajia.swipelayout:library:1.2.0@aar" implementation 'com.google.android.material:material:1.2.0-alpha02' implementation 'com.google.firebase:firebase-core:17.2.1' - implementation 'com.google.firebase:firebase-perf:19.0.2' + implementation 'com.google.firebase:firebase-perf:19.0.3' implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1' implementation 'com.github.arimorty:floatingsearchview:2.1.1' implementation 'com.github.clans:fab:1.6.4' diff --git a/app/src/androidTest/java/xyz/quaver/pupil/ExampleInstrumentedTest.kt b/app/src/androidTest/java/xyz/quaver/pupil/ExampleInstrumentedTest.kt index 801d8d34..663d6fc3 100644 --- a/app/src/androidTest/java/xyz/quaver/pupil/ExampleInstrumentedTest.kt +++ b/app/src/androidTest/java/xyz/quaver/pupil/ExampleInstrumentedTest.kt @@ -38,6 +38,7 @@ import xyz.quaver.hiyobi.getReader import xyz.quaver.hiyobi.user_agent import xyz.quaver.pupil.ui.LockActivity import xyz.quaver.pupil.util.getDownloadDirectory +import xyz.quaver.pupil.util.updateOldReaderGalleries import java.io.File import java.net.URL import javax.net.ssl.HttpsURLConnection @@ -108,4 +109,11 @@ class ExampleInstrumentedTest { } } } + + @Test + fun test_updateOldReader() { + val context = InstrumentationRegistry.getInstrumentation().targetContext + + updateOldReaderGalleries(context) + } } \ No newline at end of file diff --git a/app/src/main/java/xyz/quaver/pupil/util/update.kt b/app/src/main/java/xyz/quaver/pupil/util/update.kt index 31e4fda0..0a2d76d0 100644 --- a/app/src/main/java/xyz/quaver/pupil/util/update.kt +++ b/app/src/main/java/xyz/quaver/pupil/util/update.kt @@ -19,7 +19,8 @@ package xyz.quaver.pupil.util import android.content.Context -import kotlinx.serialization.ImplicitReflectionSerializer +import kotlinx.serialization.InternalSerializationApi +import kotlinx.serialization.internal.EnumSerializer import kotlinx.serialization.json.* import xyz.quaver.availableInHiyobi import xyz.quaver.hitomi.Reader @@ -91,7 +92,7 @@ fun getOldReaderGalleries(context: Context) : List { return oldGallery } -@UseExperimental(ImplicitReflectionSerializer::class) +@UseExperimental(InternalSerializationApi::class) fun updateOldReaderGalleries(context: Context) { val json = Json(JsonConfiguration.Stable) @@ -100,11 +101,13 @@ fun updateOldReaderGalleries(context: Context) { val reader = json.parseJson(File(gallery, "reader.json").readText()) .jsonObject.toMutableMap() + val codeSerializer = EnumSerializer(Reader.Code::class) + reader["code"] = when { (File(gallery, "images").list()?. all { !it.endsWith("webp") } ?: return@forEach) && - availableInHiyobi(gallery.name.toInt()) -> json.toJson(Reader.Code.HIYOBI) - else -> json.toJson(Reader.Code.HITOMI) + availableInHiyobi(gallery.name.toInt()) -> json.toJson(codeSerializer, Reader.Code.HIYOBI) + else -> json.toJson(codeSerializer, Reader.Code.HITOMI) } File(gallery, "reader.json").writeText(JsonObject(reader).toString()) diff --git a/libpupil/build.gradle b/libpupil/build.gradle index 5a3ea8bf..055ae4dd 100644 --- a/libpupil/build.gradle +++ b/libpupil/build.gradle @@ -6,7 +6,7 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.1' - implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.11.0" + implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.14.0" implementation 'org.jsoup:jsoup:1.11.3' testImplementation 'junit:junit:4.12' } From d29c7bf91adb36d5344e5e26cace112f06dbff15 Mon Sep 17 00:00:00 2001 From: tom5079 Date: Fri, 13 Dec 2019 19:30:19 +0900 Subject: [PATCH 22/25] Apply update on startup --- app/src/main/java/xyz/quaver/pupil/Pupil.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/main/java/xyz/quaver/pupil/Pupil.kt b/app/src/main/java/xyz/quaver/pupil/Pupil.kt index b9363bef..52b9a947 100644 --- a/app/src/main/java/xyz/quaver/pupil/Pupil.kt +++ b/app/src/main/java/xyz/quaver/pupil/Pupil.kt @@ -30,7 +30,11 @@ import androidx.preference.PreferenceManager import com.google.android.gms.common.GooglePlayServicesNotAvailableException import com.google.android.gms.common.GooglePlayServicesRepairableException import com.google.android.gms.security.ProviderInstaller +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch import xyz.quaver.pupil.util.Histories +import xyz.quaver.pupil.util.updateOldReaderGalleries import java.io.File class Pupil : MultiDexApplication() { @@ -78,6 +82,10 @@ class Pupil : MultiDexApplication() { false -> AppCompatDelegate.MODE_NIGHT_NO }) + CoroutineScope(Dispatchers.IO).launch { + updateOldReaderGalleries(this@Pupil) + } + super.onCreate() } From 7a24c3c08ead66f2c60a809b0ce38782f7761ecf Mon Sep 17 00:00:00 2001 From: tom5079 Date: Fri, 13 Dec 2019 19:50:14 +0900 Subject: [PATCH 23/25] bug fix --- app/src/main/res/values-ja/strings.xml | 1 - app/src/main/res/values-ko/strings.xml | 1 - 2 files changed, 2 deletions(-) diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 0c7f4353..3614852e 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -104,7 +104,6 @@ ヘルプ 削除 ダウンロード - キャンセル お気に入りバックアップ お気に入り復元 バックアップファイルを作成しました diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 2965ce52..e93e36cf 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -104,7 +104,6 @@ 도움말 삭제 다운로드 - 취소 즐겨찾기 백업 즐겨찾기 복원 백업 파일을 생성하였습니다 From 6a8539106b3a4021b005d171c2cba3ec36e38694 Mon Sep 17 00:00:00 2001 From: tom5079 Date: Fri, 13 Dec 2019 20:01:45 +0900 Subject: [PATCH 24/25] bug fix --- app/release/output.json | 2 +- app/src/main/java/xyz/quaver/pupil/util/update.kt | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/release/output.json b/app/release/output.json index 28776d99..6014db92 100644 --- a/app/release/output.json +++ b/app/release/output.json @@ -1 +1 @@ -[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":30,"versionName":"4.1","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":31,"versionName":"4.2-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/util/update.kt b/app/src/main/java/xyz/quaver/pupil/util/update.kt index 0a2d76d0..150e958c 100644 --- a/app/src/main/java/xyz/quaver/pupil/util/update.kt +++ b/app/src/main/java/xyz/quaver/pupil/util/update.kt @@ -98,7 +98,10 @@ fun updateOldReaderGalleries(context: Context) { val json = Json(JsonConfiguration.Stable) getOldReaderGalleries(context).forEach { gallery -> - val reader = json.parseJson(File(gallery, "reader.json").readText()) + val reader = json.parseJson(File(gallery, "reader.json").apply { + if (!exists()) + return@forEach + }.readText()) .jsonObject.toMutableMap() val codeSerializer = EnumSerializer(Reader.Code::class) From ceaa930623c1dca7a12740f8da964178f8f9e698 Mon Sep 17 00:00:00 2001 From: tom5079 Date: Fri, 13 Dec 2019 20:03:11 +0900 Subject: [PATCH 25/25] bug fix