@@ -46,7 +46,7 @@ dependencies {
|
|||||||
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
|
||||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.1'
|
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-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.appcompat:appcompat:1.1.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||||
implementation 'androidx.preference:preference:1.1.0'
|
implementation 'androidx.preference:preference:1.1.0'
|
||||||
@@ -60,7 +60,7 @@ dependencies {
|
|||||||
implementation "com.daimajia.swipelayout:library:1.2.0@aar"
|
implementation "com.daimajia.swipelayout:library:1.2.0@aar"
|
||||||
implementation 'com.google.android.material:material:1.2.0-alpha02'
|
implementation 'com.google.android.material:material:1.2.0-alpha02'
|
||||||
implementation 'com.google.firebase:firebase-core:17.2.1'
|
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.crashlytics.sdk.android:crashlytics:2.10.1'
|
||||||
implementation 'com.github.arimorty:floatingsearchview:2.1.1'
|
implementation 'com.github.arimorty:floatingsearchview:2.1.1'
|
||||||
implementation 'com.github.clans:fab:1.6.4'
|
implementation 'com.github.clans:fab:1.6.4'
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ import android.util.Log
|
|||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
import androidx.test.platform.app.InstrumentationRegistry
|
||||||
import androidx.test.rule.ActivityTestRule
|
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.Assert.assertEquals
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
@@ -34,6 +38,8 @@ import xyz.quaver.hiyobi.getReader
|
|||||||
import xyz.quaver.hiyobi.user_agent
|
import xyz.quaver.hiyobi.user_agent
|
||||||
import xyz.quaver.pupil.ui.LockActivity
|
import xyz.quaver.pupil.ui.LockActivity
|
||||||
import xyz.quaver.pupil.util.getDownloadDirectory
|
import xyz.quaver.pupil.util.getDownloadDirectory
|
||||||
|
import xyz.quaver.pupil.util.updateOldReaderGalleries
|
||||||
|
import java.io.File
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import javax.net.ssl.HttpsURLConnection
|
import javax.net.ssl.HttpsURLConnection
|
||||||
|
|
||||||
@@ -63,7 +69,7 @@ class ExampleInstrumentedTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun test_doSearch() {
|
fun test_doSearch() {
|
||||||
val reader = getReader(1426382)
|
val reader = getReader( 1426382)
|
||||||
|
|
||||||
val data: ByteArray
|
val data: ByteArray
|
||||||
|
|
||||||
@@ -76,4 +82,38 @@ class ExampleInstrumentedTest {
|
|||||||
|
|
||||||
Log.d("Pupil", data.size.toString())
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,11 @@ import androidx.preference.PreferenceManager
|
|||||||
import com.google.android.gms.common.GooglePlayServicesNotAvailableException
|
import com.google.android.gms.common.GooglePlayServicesNotAvailableException
|
||||||
import com.google.android.gms.common.GooglePlayServicesRepairableException
|
import com.google.android.gms.common.GooglePlayServicesRepairableException
|
||||||
import com.google.android.gms.security.ProviderInstaller
|
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.Histories
|
||||||
|
import xyz.quaver.pupil.util.updateOldReaderGalleries
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class Pupil : MultiDexApplication() {
|
class Pupil : MultiDexApplication() {
|
||||||
@@ -78,6 +82,10 @@ class Pupil : MultiDexApplication() {
|
|||||||
false -> AppCompatDelegate.MODE_NIGHT_NO
|
false -> AppCompatDelegate.MODE_NIGHT_NO
|
||||||
})
|
})
|
||||||
|
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
updateOldReaderGalleries(this@Pupil)
|
||||||
|
}
|
||||||
|
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import com.crashlytics.android.Crashlytics
|
|||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import kotlinx.serialization.json.JsonConfiguration
|
import kotlinx.serialization.json.JsonConfiguration
|
||||||
import xyz.quaver.availableInHiyobi
|
|
||||||
import xyz.quaver.hitomi.Reader
|
import xyz.quaver.hitomi.Reader
|
||||||
import xyz.quaver.hitomi.getReader
|
import xyz.quaver.hitomi.getReader
|
||||||
import xyz.quaver.hitomi.getReferer
|
import xyz.quaver.hitomi.getReferer
|
||||||
@@ -124,7 +123,7 @@ class GalleryDownloader(
|
|||||||
val cached = json.parse(serializer, cache.readText())
|
val cached = json.parse(serializer, cache.readText())
|
||||||
|
|
||||||
if (cached.galleryInfo.isNotEmpty()) {
|
if (cached.galleryInfo.isNotEmpty()) {
|
||||||
useHiyobi = availableInHiyobi(galleryID)
|
useHiyobi = cached.code == Reader.Code.HIYOBI
|
||||||
|
|
||||||
onReaderLoadedHandler?.invoke(cached)
|
onReaderLoadedHandler?.invoke(cached)
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,14 @@
|
|||||||
|
|
||||||
package xyz.quaver.pupil.util
|
package xyz.quaver.pupil.util
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import kotlinx.serialization.InternalSerializationApi
|
||||||
|
import kotlinx.serialization.internal.EnumSerializer
|
||||||
import kotlinx.serialization.json.*
|
import kotlinx.serialization.json.*
|
||||||
|
import xyz.quaver.availableInHiyobi
|
||||||
|
import xyz.quaver.hitomi.Reader
|
||||||
import xyz.quaver.pupil.BuildConfig
|
import xyz.quaver.pupil.BuildConfig
|
||||||
|
import java.io.File
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
fun getReleases(url: String) : JsonArray {
|
fun getReleases(url: String) : JsonArray {
|
||||||
@@ -61,4 +67,50 @@ fun getApkUrl(releases: JsonObject) : Pair<String?, String?>? {
|
|||||||
else
|
else
|
||||||
Pair(it.jsonObject["browser_download_url"]?.content, it.jsonObject["name"]?.content)
|
Pair(it.jsonObject["browser_download_url"]?.content, it.jsonObject["name"]?.content)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getOldReaderGalleries(context: Context) : List<File> {
|
||||||
|
val oldGallery = mutableListOf<File>()
|
||||||
|
|
||||||
|
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").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())
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@ dependencies {
|
|||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.1'
|
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'
|
implementation 'org.jsoup:jsoup:1.11.3'
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,13 @@ data class GalleryInfo(
|
|||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
open class Reader(val title: String, val galleryInfo: List<GalleryInfo>)
|
data class Reader(val code: Code, val title: String, val galleryInfo: List<GalleryInfo>) {
|
||||||
|
enum class Code {
|
||||||
|
HITOMI,
|
||||||
|
HIYOBI,
|
||||||
|
SORALA
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Set header `Referer` to reader url to avoid 403 error
|
//Set header `Referer` to reader url to avoid 403 error
|
||||||
fun getReader(galleryID: Int) : Reader {
|
fun getReader(galleryID: Int) : Reader {
|
||||||
@@ -40,5 +46,5 @@ fun getReader(galleryID: Int) : Reader {
|
|||||||
|
|
||||||
val doc = Jsoup.connect(readerUrl).get()
|
val doc = Jsoup.connect(readerUrl).get()
|
||||||
|
|
||||||
return Reader(doc.title(), getGalleryInfo(galleryID))
|
return Reader(Reader.Code.HITOMI, doc.title(), getGalleryInfo(galleryID))
|
||||||
}
|
}
|
||||||
@@ -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) =
|
fun createImgList(galleryID: Int, reader: Reader) =
|
||||||
|
|||||||
Reference in New Issue
Block a user