diff --git a/app/build.gradle b/app/build.gradle
index 1c4eaa06..02530dd6 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-beta1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
@@ -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'
@@ -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.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/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/androidTest/java/xyz/quaver/pupil/ExampleInstrumentedTest.kt b/app/src/androidTest/java/xyz/quaver/pupil/ExampleInstrumentedTest.kt
index 6d23423b..663d6fc3 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
@@ -33,6 +37,9 @@ 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 xyz.quaver.pupil.util.updateOldReaderGalleries
+import java.io.File
import java.net.URL
import javax.net.ssl.HttpsURLConnection
@@ -48,6 +55,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,13 +65,11 @@ class ExampleInstrumentedTest {
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
activityTestRule.launchActivity(Intent())
-
- while(true);
}
@Test
fun test_doSearch() {
- val reader = getReader(1426382)
+ val reader = getReader( 1426382)
val data: ByteArray
@@ -76,4 +82,38 @@ 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())
+ }
+ }
+ }
+
+ @Test
+ fun test_updateOldReader() {
+ val context = InstrumentationRegistry.getInstrumentation().targetContext
+
+ updateOldReaderGalleries(context)
+ }
+}
\ 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">
+
+
+
+
+
+
AppCompatDelegate.MODE_NIGHT_NO
})
+ CoroutineScope(Dispatchers.IO).launch {
+ updateOldReaderGalleries(this@Pupil)
+ }
+
super.onCreate()
}
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..a177925c 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)
}
@@ -337,7 +338,7 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri
holder.view.galleryblock_download.text = when(GalleryDownloader.get(gallery.first.id)) {
null -> 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/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/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/java/xyz/quaver/pupil/ui/MainActivity.kt b/app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt
index 21f417fa..f268d9a0 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)
}
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..60f9a724 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,15 @@ 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.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 +48,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 +162,7 @@ class SettingsActivity : AppCompatActivity() {
with(findPreference("delete_downloads")) {
this!!
- val dir = getDownloadDirectory(context)!!
+ val dir = getDownloadDirectory(context)
summary = getDirSize(dir)
@@ -278,7 +286,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 +360,37 @@ 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)
+ .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 +454,7 @@ class SettingsActivity : AppCompatActivity() {
return true
}
+ @UseExperimental(ImplicitReflectionSerializer::class)
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when(requestCode) {
REQUEST_LOCK -> {
@@ -426,6 +466,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/GalleryDownloader.kt b/app/src/main/java/xyz/quaver/pupil/util/GalleryDownloader.kt
index 32a18e34..07538401 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)
@@ -187,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)
}
}
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/java/xyz/quaver/pupil/util/update.kt b/app/src/main/java/xyz/quaver/pupil/util/update.kt
index 1c48f8e5..150e958c 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,14 @@
package xyz.quaver.pupil.util
+import android.content.Context
+import kotlinx.serialization.InternalSerializationApi
+import kotlinx.serialization.internal.EnumSerializer
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 +67,53 @@ 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(InternalSerializationApi::class)
+fun updateOldReaderGalleries(context: Context) {
+
+ val json = Json(JsonConfiguration.Stable)
+
+ getOldReaderGalleries(context).forEach { gallery ->
+ val reader = json.parseJson(File(gallery, "reader.json").apply {
+ if (!exists())
+ return@forEach
+ }.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(codeSerializer, Reader.Code.HIYOBI)
+ else -> json.toJson(codeSerializer, Reader.Code.HITOMI)
+ }
+
+ File(gallery, "reader.json").writeText(JsonObject(reader).toString())
+ }
+
}
\ 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..3614852e 100644
--- a/app/src/main/res/values-ja/strings.xml
+++ b/app/src/main/res/values-ja/strings.xml
@@ -104,5 +104,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 8f3dfa95..e93e36cf 100644
--- a/app/src/main/res/values-ko/strings.xml
+++ b/app/src/main/res/values-ko/strings.xml
@@ -66,7 +66,7 @@
갤러리 번호로 열기
갤러리를 찾지 못했습니다
저장 공간
- 디스코드햐
+ 디스코드
앱 잠금
앱 잠금 종류
앱 버전
@@ -104,5 +104,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 3af7023a..244a015f 100644
--- a/app/src/main/res/xml/root_preferences.xml
+++ b/app/src/main/res/xml/root_preferences.xml
@@ -73,6 +73,15 @@
app:key="nomedia"
app:title="@string/settings_nomedia_title"
app:summary="@string/settings_nomedia_title"/>
+
+
+
+
+
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)
}
}
diff --git a/build.gradle b/build.gradle
index eb4a1760..12b58e00 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.61'
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.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"
- 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'
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'
}
diff --git a/libpupil/src/main/java/xyz/quaver/hitomi/common.kt b/libpupil/src/main/java/xyz/quaver/hitomi/common.kt
index 11c14bee..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
@@ -79,17 +79,20 @@ 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")
}
}
-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/main/java/xyz/quaver/hitomi/reader.kt b/libpupil/src/main/java/xyz/quaver/hitomi/reader.kt
index 355a3a31..4ed503a9 100644
--- a/libpupil/src/main/java/xyz/quaver/hitomi/reader.kt
+++ b/libpupil/src/main/java/xyz/quaver/hitomi/reader.kt
@@ -26,13 +26,19 @@ 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
)
@Serializable
-open class Reader(val title: String, val galleryInfo: List)
+data 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 4873aef1..07c0a357 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 = ""
@@ -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) =
diff --git a/libpupil/src/test/java/xyz/quaver/hitomi/UnitTest.kt b/libpupil/src/test/java/xyz/quaver/hitomi/UnitTest.kt
index b838048c..7d40a893 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
@@ -86,10 +87,17 @@ 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)
}
+
+ @Test
+ fun test_availableInHiyobi() {
+ val result = availableInHiyobi(1272781)
+
+ print(result)
+ }
}
\ No newline at end of file