Skip to content

Commit

Permalink
Merge branch 'dev' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
tom5079 committed Sep 26, 2020
2 parents 9984334 + a973cdf commit 44e3d16
Show file tree
Hide file tree
Showing 31 changed files with 338 additions and 460 deletions.
5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ android {
applicationId "xyz.quaver.pupil"
minSdkVersion 16
targetSdkVersion 30
versionCode 59
versionName "5.0.3-hotfix2"
versionCode 60
versionName "5.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
Expand Down Expand Up @@ -64,7 +64,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9"
//implementation "org.jetbrains.kotlinx:kotlinx-serialization-core:1.0.0-RC"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.0-RC2"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation "androidx.activity:activity-ktx:1.2.0-alpha08"
implementation 'androidx.fragment:fragment-ktx:1.3.0-alpha08'
Expand All @@ -80,7 +80,6 @@ dependencies {
implementation 'com.google.firebase:firebase-perf:19.0.8'
implementation 'com.google.android.gms:play-services-oss-licenses:17.0.0'
implementation 'com.google.android.gms:play-services-mlkit-face-detection:16.1.1'
implementation 'com.github.arimorty:floatingsearchview:2.1.1'
implementation 'com.github.clans:fab:1.6.4'
//implementation 'com.quiph.ui:recyclerviewfastscroller:0.2.1'
//noinspection GradleDependency
Expand All @@ -89,6 +88,9 @@ dependencies {
implementation ("com.github.bumptech.glide:okhttp3-integration:4.11.0") {
transitive = false
}
implementation ("com.github.bumptech.glide:recyclerview-integration:4.11.0") {
transitive = false
}
implementation 'com.github.bumptech.glide:annotations:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
kapt 'com.github.bumptech.glide:compiler:4.11.0'
Expand All @@ -106,6 +108,7 @@ dependencies {
exclude group: 'org.jetbrains.kotlinx', module: 'kotlinx-serialization-core-jvm'
}
implementation "xyz.quaver:documentfilex:0.2.15"
implementation "xyz.quaver:floatingsearchview:1.0.4"
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test:rules:1.3.0'
Expand Down
Binary file removed app/libs/kotlinx-serialization-core-1.0.0-RC.jar
Binary file not shown.
Binary file modified app/libs/recyclerviewfastscroller-release.aar
Binary file not shown.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"properties": [],
"versionCode": 59,
"versionName": "5.0.3-hotfix2",
"versionCode": 60,
"versionName": "5.1",
"enabled": true,
"outputFile": "app-release.apk"
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
android:theme="@style/AppTheme"
android:networkSecurityConfig="@xml/network_security_config"
tools:replace="android:theme"
android:largeHeap="true"
tools:ignore="UnusedAttribute">

<meta-data
Expand Down
26 changes: 19 additions & 7 deletions app/src/main/java/xyz/quaver/pupil/adapters/GalleryBlockAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ package xyz.quaver.pupil.adapters

import android.content.Context
import android.graphics.drawable.Drawable
import android.util.Log
import android.util.SparseBooleanArray
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.cardview.widget.CardView
import androidx.core.view.children
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.CircularProgressDrawable
import androidx.vectordrawable.graphics.drawable.Animatable2Compat
Expand All @@ -49,6 +49,7 @@ import xyz.quaver.hitomi.getReader
import xyz.quaver.io.util.getChild
import xyz.quaver.pupil.BuildConfig
import xyz.quaver.pupil.R
import xyz.quaver.pupil.favoriteTags
import xyz.quaver.pupil.favorites
import xyz.quaver.pupil.types.Tag
import xyz.quaver.pupil.ui.view.TagChip
Expand All @@ -70,7 +71,7 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri

val timer = Timer()

var isThin = false
var thin: Boolean = Preferences["thin"]

inner class GalleryViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
var timerTask: TimerTask? = null
Expand All @@ -88,15 +89,15 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri
with(view.galleryblock_progressbar) {
val imageList = cache.metadata.imageList!!

progress = imageList.filterNotNull().size
progress = imageList.count { it != null }
max = imageList.size

with(view.galleryblock_progressbar_layout) {
if (visibility == View.GONE)
visibility = View.VISIBLE
}

if (progress == max) {
if (!imageList.contains(null)) {
val downloadManager = DownloadManager.getInstance(context)

if (completeFlag.get(galleryID, false)) {
Expand Down Expand Up @@ -143,7 +144,7 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri
val artists = galleryBlock.artists
val series = galleryBlock.series

if (isThin)
if (thin)
galleryblock_thumbnail.layoutParams.width = context.resources.getDimensionPixelSize(
R.dimen.galleryblock_thumbnail_thin
)
Expand Down Expand Up @@ -223,7 +224,18 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri

galleryblock_tag_group.removeAllViews()
CoroutineScope(Dispatchers.Default).launch {
galleryBlock.relatedTags.map {
galleryBlock.relatedTags.sortedBy {
val tag = Tag.parse(it)

if (favoriteTags.contains(tag))
-1
else
when(Tag.parse(it).area) {
"female" -> 0
"male" -> 1
else -> 2
}
}.map {
TagChip(context, Tag.parse(it)).apply {
setOnClickListener { view ->
for (callback in onChipClickedHandler)
Expand Down Expand Up @@ -273,7 +285,7 @@ class GalleryBlockAdapter(private val glide: RequestManager, private val galleri


// Make some views invisible to make it thinner
if (isThin) {
if (thin) {
galleryblock_language.visibility = View.GONE
galleryblock_type.visibility = View.GONE
galleryblock_tag_group.visibility = View.GONE
Expand Down
54 changes: 30 additions & 24 deletions app/src/main/java/xyz/quaver/pupil/services/DownloadService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ import xyz.quaver.pupil.R
import xyz.quaver.pupil.client
import xyz.quaver.pupil.interceptors
import xyz.quaver.pupil.ui.ReaderActivity
import xyz.quaver.pupil.util.Preferences
import xyz.quaver.pupil.util.downloader.Cache
import xyz.quaver.pupil.util.downloader.DownloadManager
import xyz.quaver.pupil.util.ellipsize
import xyz.quaver.pupil.util.normalizeID
import xyz.quaver.pupil.util.requestBuilders
import java.io.IOException
import kotlin.math.ceil
import kotlin.math.floor
import kotlin.math.log10
import kotlin.math.roundToInt

private typealias ProgressListener = (DownloadService.Tag, Long, Long, Boolean) -> Unit
class DownloadService : Service() {
Expand Down Expand Up @@ -218,10 +221,11 @@ class DownloadService : Service() {

kotlin.runCatching {
val image = response.also { if (it.code() != 200) throw IOException() }.body()?.use { it.bytes() } ?: throw Exception()
val padding = ceil(progress[galleryID]?.size?.let { log10(it.toFloat()) } ?: 0F).toInt()

CoroutineScope(Dispatchers.IO).launch {
kotlin.runCatching {
Cache.getInstance(this@DownloadService, galleryID).putImage(index, "$index.$ext", image)
Cache.getInstance(this@DownloadService, galleryID).putImage(index, "${index.toString().padStart(padding, '0')}.$ext", image)
}.onSuccess {
progress[galleryID]?.set(index, Float.POSITIVE_INFINITY)
notify(galleryID)
Expand Down Expand Up @@ -309,34 +313,26 @@ class DownloadService : Service() {
return@launch
}

progress.put(galleryID, MutableList(reader.galleryInfo.files.size) { 0F })

FirebaseCrashlytics.getInstance().log(
"""
GALLERYID: $galleryID
CACHE: ${cache.findFile(".metadata")}
PATTERN: ${Preferences["download_folder_name", ""]}
READER ID: ${reader.galleryInfo.id}
READER SIZE: ${reader.galleryInfo.files.size}
CACHE READER ID: ${cache.metadata.reader?.galleryInfo?.id}}
CACHE READER SIZE: ${cache.metadata.reader?.galleryInfo?.files?.size}
""".trimIndent()
)
val list = MutableList(reader.galleryInfo.files.size) { 0F }

cache.metadata.imageList?.let {
if (progress[galleryID]?.size != it.size) {
cache.metadata.imageList?.filterNotNull()?.forEach { file ->
cache.findFile(file)?.delete()
}
cache.metadata.imageList = MutableList(reader.galleryInfo.files.size) { null }
return@let
if (list.size != it.size) {
FirebaseCrashlytics.getInstance().log(
"""
GALLERYID: $galleryID
${it.size} - ${list.size}
""".trimIndent()
)
error("ImageList Size does not match")
}

it.forEachIndexed { index, image ->
progress[galleryID]?.set(index, if (image != null) Float.POSITIVE_INFINITY else 0F)
list[index] = if (image != null) Float.POSITIVE_INFINITY else 0F
}
}

progress.put(galleryID, list)

if (isCompleted(galleryID)) {
if (DownloadManager.getInstance(this@DownloadService)
.getDownloadFolder(galleryID) != null )
Expand All @@ -361,8 +357,18 @@ class DownloadService : Service() {
}
}

reader.requestBuilders.forEachIndexed { index, it ->
if (progress[galleryID]?.get(index)?.isInfinite() != true) {
reader.requestBuilders.also {
if (it.size != list.size) {
FirebaseCrashlytics.getInstance().log(
"""
GALLERYID: $galleryID
${it.size} - ${list.size}
""".trimIndent()
)
error("Requests Size does not match")
}
}.forEachIndexed { index, it ->
if (!list[index].isInfinite()) {
val request = it.tag(Tag(galleryID, index, startId)).build()
client.newCall(request).enqueue(callback)
}
Expand Down
24 changes: 8 additions & 16 deletions app/src/main/java/xyz/quaver/pupil/types/Suggestions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,28 @@

package xyz.quaver.pupil.types

import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion
import kotlinx.android.parcel.IgnoredOnParcel
import kotlinx.android.parcel.Parcelize
import xyz.quaver.floatingsearchview.suggestions.model.SearchSuggestion
import xyz.quaver.hitomi.Suggestion

@Parcelize
data class TagSuggestion(val s: String, val t: Int, val u: String, val n: String) : SearchSuggestion {
constructor(s: Suggestion) : this(s.s, s.t, s.u, s.n)

override fun getBody(): String {
return s
}
@IgnoredOnParcel
override val body = s
}

@Parcelize
class Suggestion(val str: String) : SearchSuggestion {
override fun getBody() = str
}
class Suggestion(override val body: String) : SearchSuggestion

@Parcelize
class NoResultSuggestion(val str: String) : SearchSuggestion {
override fun getBody() = str
}
class NoResultSuggestion(override val body: String) : SearchSuggestion

@Parcelize
class LoadingSuggestion(val str: String) : SearchSuggestion {
override fun getBody() = str
}
class LoadingSuggestion(override val body: String) : SearchSuggestion

@Parcelize
@Suppress("PARCELABLE_PRIMARY_CONSTRUCTOR_IS_EMPTY")
class FavoriteHistorySwitch(private val body: String) : SearchSuggestion {
override fun getBody() = body
}
class FavoriteHistorySwitch(override val body: String) : SearchSuggestion
23 changes: 9 additions & 14 deletions app/src/main/java/xyz/quaver/pupil/ui/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.content.Intent
import android.os.Bundle
import android.os.PersistableBundle
import android.view.WindowManager
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.CallSuper
import androidx.appcompat.app.AppCompatActivity
import xyz.quaver.pupil.R
Expand All @@ -34,6 +35,13 @@ open class BaseActivity : AppCompatActivity() {

private var locked: Boolean = true

private val lockLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (it.resultCode == Activity.RESULT_OK)
locked = false
else
finish()
}

@CallSuper
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, persistentState)
Expand All @@ -53,20 +61,7 @@ open class BaseActivity : AppCompatActivity() {
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)

if (locked)
startActivityForResult(Intent(this, LockActivity::class.java), R.id.request_lock.normalizeID())
}

@CallSuper
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when(requestCode) {
R.id.request_lock.normalizeID() -> {
if (resultCode == Activity.RESULT_OK)
locked = false
else
finish()
}
else -> super.onActivityResult(requestCode, resultCode, data)
}
lockLauncher.launch(Intent(this, LockActivity::class.java))
}

}
Loading

0 comments on commit 44e3d16

Please sign in to comment.