Skip to content

Commit

Permalink
Merge pull request #75 from tom5079/dev
Browse files Browse the repository at this point in the history
Version 4.17
  • Loading branch information
tom5079 authored Jun 14, 2020
2 parents 3198c6c + 2720e44 commit bbe2994
Show file tree
Hide file tree
Showing 22 changed files with 101 additions and 40 deletions.
15 changes: 7 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ android {
applicationId "xyz.quaver.pupil"
minSdkVersion 16
targetSdkVersion 29
versionCode 51
versionName "4.15"
versionCode 52
versionName "4.17"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
Expand Down Expand Up @@ -54,20 +54,19 @@ dependencies {

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.14.0"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.preference:preference:1.1.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation "androidx.biometric:biometric:1.0.1"
implementation 'androidx.multidex:multidex:2.0.1'
implementation "com.daimajia.swipelayout:library:1.2.0@aar"
implementation 'com.google.android.material:material:1.2.0-alpha05'
implementation 'com.google.firebase:firebase-core:17.2.3'
implementation 'com.google.firebase:firebase-perf:19.0.5'
implementation 'com.google.android.material:material:1.3.0-alpha01'
implementation 'com.google.firebase:firebase-core:17.4.3'
implementation 'com.google.firebase:firebase-perf:19.0.7'
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'
Expand Down
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":51,"versionName":"4.15","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release","dirName":""},"path":"app-release.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":52,"versionName":"4.17","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release","dirName":""},"path":"app-release.apk","properties":{}}]
7 changes: 7 additions & 0 deletions app/src/main/java/xyz/quaver/pupil/Pupil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ class Pupil : MultiDexApplication() {
preference.edit().remove("dl_location").apply()
}

if (!preference.getBoolean("low_quality_reset", false)) {
preference.edit()
.putBoolean("low_quality", true)
.putBoolean("low_quality_reset", true)
.apply()
}

histories = Histories(File(ContextCompat.getDataDir(this), "histories.json"))
favorites = Histories(File(ContextCompat.getDataDir(this), "favorites.json"))

Expand Down
25 changes: 24 additions & 1 deletion app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import io.fabric.sdk.android.Fabric
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.activity_main_content.*
import kotlinx.coroutines.*
import kotlinx.serialization.list
import kotlinx.serialization.builtins.list
import xyz.quaver.hitomi.GalleryBlock
import xyz.quaver.hitomi.doSearch
import xyz.quaver.hitomi.getGalleryIDsFromNozomi
Expand Down Expand Up @@ -367,6 +367,29 @@ class MainActivity : AppCompatActivity() {
}
}

with(main_fab_random) {
setImageResource(R.drawable.shuffle_variant)
setOnClickListener {
runBlocking {
withTimeoutOrNull(100) {
galleryIDs?.await()
}
}.let {
if (it?.isEmpty() == false) {
val galleryID = it.random()

val intent = Intent(this@MainActivity, ReaderActivity::class.java).apply {
putExtra("galleryID", galleryID)
}

startActivity(intent)

histories.add(galleryID)
}
}
}
}

with(main_fab_id) {
setImageResource(R.drawable.numeric)
setOnClickListener {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/xyz/quaver/pupil/ui/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceManager
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.settings_activity.*
import kotlinx.serialization.list
import kotlinx.serialization.serializer
import kotlinx.serialization.builtins.list
import kotlinx.serialization.builtins.serializer
import net.rdrei.android.dirchooser.DirectoryChooserActivity
import xyz.quaver.pupil.Pupil
import xyz.quaver.pupil.R
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/xyz/quaver/pupil/util/download/Cache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import android.util.SparseArray
import androidx.preference.PreferenceManager
import com.crashlytics.android.Crashlytics
import kotlinx.coroutines.*
import kotlinx.io.InputStream
import xyz.quaver.Code
import xyz.quaver.hitomi.GalleryBlock
import xyz.quaver.hitomi.Reader
Expand All @@ -35,10 +34,11 @@ import xyz.quaver.pupil.util.getCachedGallery
import xyz.quaver.pupil.util.getDownloadDirectory
import xyz.quaver.pupil.util.isParentOf
import xyz.quaver.pupil.util.json
import java.io.BufferedInputStream
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.net.URL
import java.util.concurrent.Executors
import java.util.concurrent.locks.Lock
import java.util.concurrent.locks.ReentrantLock

Expand Down Expand Up @@ -245,7 +245,7 @@ class Cache(context: Context) : ContextWrapper(context) {
it.createNewFile()
}

data.use {
BufferedInputStream(data).use {
it.copyTo(FileOutputStream(cache))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ import xyz.quaver.pupil.R
import xyz.quaver.pupil.ui.ReaderActivity
import java.io.File
import java.io.IOException
import java.util.concurrent.Executors
import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.TimeUnit

@UseExperimental(ExperimentalCoroutinesApi::class)
@OptIn(ExperimentalCoroutinesApi::class)
class DownloadWorker private constructor(context: Context) : ContextWrapper(context) {

private val preferences : SharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
Expand Down Expand Up @@ -164,7 +163,10 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont
.connectTimeout(0, TimeUnit.SECONDS)
.addInterceptor(interceptor)
.readTimeout(0, TimeUnit.SECONDS)
.dispatcher(Dispatcher(Executors.newFixedThreadPool(4)))
.dispatcher(Dispatcher().apply {
maxRequests = 4
maxRequestsPerHost = 4
})
.proxy(proxy)
.build()

Expand Down Expand Up @@ -222,7 +224,7 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont
imageUrlFromImage(
galleryID,
reader.galleryInfo.files[index],
lowQuality
!lowQuality
)
)
addHeader("Referer", getReferer(galleryID))
Expand All @@ -240,6 +242,8 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont
}.build()

client.newCall(request).enqueue(callback)

Log.i("PUPILD", "DOWNLOADING ($galleryID, $index) from ${request.url()}")
}

private fun download(galleryID: Int) = CoroutineScope(Dispatchers.IO).launch {
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/xyz/quaver/pupil/util/history.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@

package xyz.quaver.pupil.util

import kotlinx.serialization.list
import kotlinx.serialization.serializer
import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.list
import kotlinx.serialization.builtins.serializer
import java.io.File

class Histories(private val file: File) : ArrayList<Int>() {

val serializer = Int.serializer().list
val serializer: KSerializer<List<Int>> = Int.serializer().list

init {
if (!file.exists())
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/xyz/quaver/pupil/util/lock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import android.content.Context
import android.content.ContextWrapper
import androidx.core.content.ContextCompat
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration
import kotlinx.serialization.list
import kotlinx.serialization.builtins.list
import java.io.File
import java.security.MessageDigest

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/xyz/quaver/pupil/util/misc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import android.annotation.SuppressLint
import java.util.*
import kotlin.collections.ArrayList

@UseExperimental(ExperimentalStdlibApi::class)
@OptIn(ExperimentalStdlibApi::class)
fun String.wordCapitalize() : String {
val result = ArrayList<String>()

Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/shuffle_variant.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- drawable/shuffle_variant.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#fff" android:pathData="M17,3L22.25,7.5L17,12L22.25,16.5L17,21V18H14.26L11.44,15.18L13.56,13.06L15.5,15H17V12L17,9H15.5L6.5,18H2V15H5.26L14.26,6H17V3M2,6H6.5L9.32,8.82L7.2,10.94L5.26,9H2V6Z" />
</vector>
7 changes: 7 additions & 0 deletions app/src/main/res/layout/activity_main_content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@
app:fab_label="@string/main_jump_title"
app:fab_size="mini"/>

<com.github.clans.fab.FloatingActionButton
android:id="@+id/main_fab_random"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fab_label="@string/main_fab_random"
app:fab_size="mini"/>

<com.github.clans.fab.FloatingActionButton
android:id="@+id/main_fab_id"
android:layout_width="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,5 @@
<string name="import_old_galleries_folder_not_readable">フォルダを読めません</string>
<string name="import_old_galleries_notification">旧ギャラリーインポート中…</string>
<string name="import_old_galleries_notification_done">インポート完了</string>
<string name="main_fab_random">ランダムギャラリーを開く</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,5 @@
<string name="import_old_galleries_folder_not_readable">폴더를 읽을 수 없습니다</string>
<string name="import_old_galleries_notification">이전 버전 갤러리 가져오는 중…</string>
<string name="import_old_galleries_notification_done">가져오기 완료</string>
<string name="main_fab_random">무작위 갤러리 열기</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<string name="main_jump_message">Current page: %1$d\nMaximum page: %2$d</string>
<string name="main_open_gallery_by_id">Open Gallery by ID</string>
<string name="reader_failed_to_find_gallery">Failed to open gallery</string>
<string name="main_fab_random">Open a random gallery</string>
<string name="main_fab_cancel">Cancel all downloads</string>

<string name="main_move">Move to page %1$d</string>
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
<SwitchPreferenceCompat
app:key="low_quality"
app:title="@string/settings_low_quality"
app:summary="@string/settings_low_quality_summary"/>
app:summary="@string/settings_low_quality_summary"
app:defaultValue="true"/>

</PreferenceCategory>

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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.61'
ext.kotlin_version = '1.3.72'
repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.android.tools.build:gradle:3.6.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"
Expand Down
2 changes: 1 addition & 1 deletion libpupil/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.3.3'
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.14.0"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0"
implementation 'org.jsoup:jsoup:1.12.1'
testImplementation 'junit:junit:4.13'
}
Expand Down
10 changes: 10 additions & 0 deletions libpupil/src/main/java/xyz/quaver/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,20 @@

package xyz.quaver

import kotlinx.serialization.UnstableDefault
import kotlinx.serialization.json.Json
import java.net.Proxy

var proxy = Proxy.NO_PROXY

@OptIn(UnstableDefault::class)
var json = Json {
isLenient = true
ignoreUnknownKeys = true
serializeSpecialFloatingPointValues = true
useArrayPolymorphism = true
}

fun availableInHiyobi(galleryID: Int) : Boolean {
return try {
xyz.quaver.hiyobi.getReader(galleryID)
Expand Down
4 changes: 2 additions & 2 deletions libpupil/src/main/java/xyz/quaver/hitomi/common.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

package xyz.quaver.hitomi

import kotlinx.serialization.json.Json
import xyz.quaver.json
import xyz.quaver.proxy
import java.net.URL

const val protocol = "https:"

@Suppress("EXPERIMENTAL_API_USAGE")
fun getGalleryInfo(galleryID: Int) =
Json.nonstrict.parse(
json.parse(
GalleryInfo.serializer(),
URL("$protocol//$domain/galleries/$galleryID.js").openConnection(proxy).getInputStream().use {
it.reader().readText()
Expand Down
8 changes: 4 additions & 4 deletions libpupil/src/main/java/xyz/quaver/hitomi/search.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fun sha256(data: ByteArray) : ByteArray {
return MessageDigest.getInstance("SHA-256").digest(data)
}

@UseExperimental(ExperimentalUnsignedTypes::class)
@OptIn(ExperimentalUnsignedTypes::class)
fun hashTerm(term: String) : UByteArray {
return sha256(term.toByteArray()).toUByteArray().sliceArray(0 until 4)
}
Expand Down Expand Up @@ -258,9 +258,9 @@ fun getURLAtRange(url: String, range: LongRange) : ByteArray? {
}
}

@UseExperimental(ExperimentalUnsignedTypes::class)
@OptIn(ExperimentalUnsignedTypes::class)
data class Node(val keys: List<UByteArray>, val datas: List<Pair<Long, Int>>, val subNodeAddresses: List<Long>)
@UseExperimental(ExperimentalUnsignedTypes::class)
@OptIn(ExperimentalUnsignedTypes::class)
fun decodeNode(data: ByteArray) : Node {
val buffer = ByteBuffer
.wrap(data)
Expand Down Expand Up @@ -302,7 +302,7 @@ fun decodeNode(data: ByteArray) : Node {
return Node(keys, datas, subNodeAddresses)
}

@UseExperimental(ExperimentalUnsignedTypes::class)
@OptIn(ExperimentalUnsignedTypes::class)
fun bSearch(field: String, key: UByteArray, node: Node) : Pair<Long, Int>? {
fun compareArrayBuffers(dv1: UByteArray, dv2: UByteArray) : Int {
val top = Math.min(dv1.size, dv2.size)
Expand Down
Loading

0 comments on commit bbe2994

Please sign in to comment.