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 Oct 2, 2020
2 parents 60e8b18 + 38c0399 commit 54a5cd2
Show file tree
Hide file tree
Showing 24 changed files with 402 additions and 141 deletions.
7 changes: 4 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ android {
minSdkVersion 16
targetSdkVersion 30
versionCode 61
versionName "5.1.1-hotfix3"
versionName "5.1.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
Expand Down Expand Up @@ -90,6 +90,7 @@ dependencies {
implementation "androidx.constraintlayout:constraintlayout:2.0.1"
implementation "androidx.gridlayout:gridlayout:1.0.0"
implementation "androidx.biometric:biometric:1.0.1"
implementation "androidx.work:work-runtime-ktx:2.4.0"

implementation "com.daimajia.swipelayout:library:1.2.0@aar"

Expand Down Expand Up @@ -125,8 +126,8 @@ dependencies {
implementation "ru.noties.markwon:core:3.1.0"

implementation "xyz.quaver:libpupil:1.7.2"
implementation "xyz.quaver:documentfilex:0.2.15"
implementation "xyz.quaver:floatingsearchview:1.0.5"
implementation "xyz.quaver:documentfilex:0.3"
implementation "xyz.quaver:floatingsearchview:1.0.7"

testImplementation "junit:junit:4.13"
androidTestImplementation "androidx.test.ext:junit:1.1.2"
Expand Down
2 changes: 1 addition & 1 deletion app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"filters": [],
"properties": [],
"versionCode": 61,
"versionName": "5.1.1-hotfix3",
"versionName": "5.1.2",
"enabled": true,
"outputFile": "app-release.apk"
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/xyz/quaver/pupil/Pupil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ class Pupil : Application() {
Preferences.remove("download_folder")
}

if (!Preferences["reset_secure", false]) {
Preferences["security_mode"] = false
Preferences["reset_secure"] = true
}

histories = SavedSet(File(ContextCompat.getDataDir(this), "histories.json"), 0)
favorites = SavedSet(File(ContextCompat.getDataDir(this), "favorites.json"), 0)
favoriteTags = SavedSet(File(ContextCompat.getDataDir(this), "favorites_tags.json"), Tag.parse(""))
Expand Down
104 changes: 60 additions & 44 deletions app/src/main/java/xyz/quaver/pupil/adapters/GalleryBlockAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ import com.daimajia.swipe.interfaces.SwipeAdapterInterface
import com.github.piasy.biv.loader.ImageLoader
import kotlinx.android.synthetic.main.item_galleryblock.view.*
import kotlinx.coroutines.*
import xyz.quaver.hitomi.getGallery
import xyz.quaver.hitomi.getReader
import xyz.quaver.io.util.getChild
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
import xyz.quaver.pupil.util.Preferences
import xyz.quaver.pupil.util.downloader.Cache
import xyz.quaver.pupil.util.downloader.DownloadManager
Expand All @@ -57,13 +57,22 @@ class GalleryBlockAdapter(private val galleries: List<Int>) : RecyclerSwipeAdapt
PREV
}

var update = true
var updateAll = true
var thin: Boolean = Preferences["thin"]

inner class GalleryViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
var updateJob: Job? = null
private var galleryID: Int = 0

private fun updateProgress(context: Context, galleryID: Int) {
init {
CoroutineScope(Dispatchers.Main).launch {
while (updateAll) {
updateProgress(view.context)
delay(1000)
}
}
}

private fun updateProgress(context: Context) {
val cache = Cache.getInstance(context, galleryID)

CoroutineScope(Dispatchers.Main).launch {
Expand Down Expand Up @@ -116,9 +125,13 @@ class GalleryBlockAdapter(private val galleries: List<Int>) : RecyclerSwipeAdapt
}

fun bind(galleryID: Int) {
this.galleryID = galleryID

val cache = Cache.getInstance(view.context, galleryID)

val galleryBlock = cache.metadata.galleryBlock ?: return
val galleryBlock = runBlocking {
cache.getGalleryBlock()
} ?: return

with(view) {
val resources = context.resources
Expand Down Expand Up @@ -162,21 +175,30 @@ class GalleryBlockAdapter(private val galleries: List<Int>) : RecyclerSwipeAdapt
}
}

if (updateJob == null)
updateJob = CoroutineScope(Dispatchers.Main).launch {
while (update) {
updateProgress(context, galleryID)
delay(1000)
}
}

galleryblock_title.text = galleryBlock.title
with(galleryblock_artist) {
text = artists.joinToString(", ") { it.wordCapitalize() }
text = artists.joinToString { it.wordCapitalize() }
visibility = when {
artists.isNotEmpty() -> View.VISIBLE
else -> View.GONE
}

CoroutineScope(Dispatchers.IO).launch {
val gallery = runCatching {
getGallery(galleryID)
}.getOrNull()

if (gallery?.groups?.isNotEmpty() != true)
return@launch

launch(Dispatchers.Main) {
text = context.getString(
R.string.galleryblock_artist_with_group,
artists.joinToString { it.wordCapitalize() },
gallery.groups.joinToString { it.wordCapitalize() }
)
}
}
}
with(galleryblock_series) {
text =
Expand All @@ -198,27 +220,32 @@ class GalleryBlockAdapter(private val galleries: List<Int>) : RecyclerSwipeAdapt
}
}

galleryblock_tag_group.removeAllViews()
CoroutineScope(Dispatchers.Default).launch {
galleryBlock.relatedTags.sortedBy {
val tag = Tag.parse(it)
with(galleryblock_tag_group) {
onClickListener = {
onChipClickedHandler.forEach { callback ->
callback.invoke(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)
callback.invoke((view as TagChip).tag)
}
tags.clear()
tags.addAll(
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 {
Tag.parse(it)
}
}.let { launch(Dispatchers.Main) { it.forEach { galleryblock_tag_group.addView(it) } } }
)

refresh()
}

galleryblock_id.text = galleryBlock.id.toString()
Expand Down Expand Up @@ -262,8 +289,6 @@ class GalleryBlockAdapter(private val galleries: List<Int>) : RecyclerSwipeAdapt

// Make some views invisible to make it thinner
if (thin) {
galleryblock_language.visibility = View.GONE
galleryblock_type.visibility = View.GONE
galleryblock_tag_group.visibility = View.GONE
}
}
Expand Down Expand Up @@ -358,15 +383,6 @@ class GalleryBlockAdapter(private val galleries: List<Int>) : RecyclerSwipeAdapt
}
}

override fun onViewDetachedFromWindow(holder: RecyclerView.ViewHolder) {
super.onViewDetachedFromWindow(holder)

if (holder is GalleryViewHolder) {
holder.updateJob?.cancel()
holder.updateJob = null
}
}

override fun getItemCount() =
galleries.size +
(if (showNext) 1 else 0) +
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/xyz/quaver/pupil/adapters/ReaderAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ class ReaderAdapter(

class ViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
fun clear() {
view.image.ssiv?.recycle()
view.image.mainView.let {
when (it) {
is SubsamplingScaleImageView ->
it.recycle()
is SimpleDraweeView ->
it.controller = null
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ 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.cleanCache
import xyz.quaver.pupil.util.downloader.Cache
import xyz.quaver.pupil.util.downloader.DownloadManager
import xyz.quaver.pupil.util.ellipsize
Expand Down Expand Up @@ -295,6 +296,8 @@ class DownloadService : Service() {
}

fun download(galleryID: Int, priority: Boolean = false, startId: Int? = null): Job = CoroutineScope(Dispatchers.IO).launch {
cleanCache(this@DownloadService)

if (progress.containsKey(galleryID))
cancel(galleryID)

Expand Down
29 changes: 21 additions & 8 deletions app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.text.InputType
import android.text.util.Linkify
import android.view.KeyEvent
import android.view.MenuItem
import android.view.MotionEvent
Expand All @@ -31,6 +32,7 @@ import android.widget.*
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatDelegate
import androidx.cardview.widget.CardView
import androidx.core.text.util.LinkifyCompat
import androidx.core.view.GravityCompat
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.navigation.NavigationView
Expand Down Expand Up @@ -58,6 +60,7 @@ import xyz.quaver.pupil.util.checkUpdate
import xyz.quaver.pupil.util.downloader.Cache
import xyz.quaver.pupil.util.downloader.DownloadManager
import xyz.quaver.pupil.util.restore
import java.util.regex.Pattern
import kotlin.math.abs
import kotlin.math.ceil
import kotlin.math.min
Expand Down Expand Up @@ -122,8 +125,6 @@ class MainActivity :

checkUpdate(this)



initView()
}

Expand All @@ -146,7 +147,7 @@ class MainActivity :
override fun onDestroy() {
super.onDestroy()

(main_recyclerview?.adapter as? GalleryBlockAdapter)?.update = false
(main_recyclerview?.adapter as? GalleryBlockAdapter)?.updateAll = false
}

override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
Expand Down Expand Up @@ -204,6 +205,8 @@ class MainActivity :
}
)

Linkify.addLinks(main_noresult, Pattern.compile(getString(R.string.https_text)), null, null, { _, _ -> getString(R.string.https) })

//NavigationView
main_nav_view.setNavigationItemSelectedListener(this)

Expand Down Expand Up @@ -284,12 +287,22 @@ class MainActivity :
setTitle(R.string.main_open_gallery_by_id)

setPositiveButton(android.R.string.ok) { _, _ ->
val galleryID = editText.text.toString().toIntOrNull() ?: return@setPositiveButton
val intent = Intent(this@MainActivity, ReaderActivity::class.java).apply {
putExtra("galleryID", galleryID)
}
val galleryID = editText.text.toString().toIntOrNull() ?: return@setPositiveButton

GalleryDialog(this@MainActivity, galleryID).apply {
onChipClickedHandler.add {
runOnUiThread {
query = it.toQuery()
currentPage = 0

startActivity(intent)
cancelFetch()
clearGalleries()
fetchGalleries(query, sortMode)
loadBlocks()
}
dismiss()
}
}.show()
}
}.show()
}
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/xyz/quaver/pupil/ui/dialog/GalleryDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import xyz.quaver.hitomi.Gallery
import xyz.quaver.hitomi.getGallery
import xyz.quaver.pupil.BuildConfig
import xyz.quaver.pupil.R
import xyz.quaver.pupil.adapters.GalleryBlockAdapter
import xyz.quaver.pupil.adapters.ThumbnailPageAdapter
Expand All @@ -54,6 +53,8 @@ import xyz.quaver.pupil.ui.view.TagChip
import xyz.quaver.pupil.util.ItemClickSupport
import xyz.quaver.pupil.util.downloader.Cache
import xyz.quaver.pupil.util.wordCapitalize
import java.util.*
import kotlin.collections.ArrayList

class GalleryDialog(context: Context, private val galleryID: Int) : AlertDialog(context) {

Expand Down Expand Up @@ -113,7 +114,12 @@ class GalleryDialog(context: Context, private val galleryID: Int) : AlertDialog(
addRelated(gallery)
}
} catch (e: Exception) {
Snackbar.make(gallery_layout, R.string.unable_to_connect, Snackbar.LENGTH_INDEFINITE).show()
Snackbar.make(gallery_layout, R.string.unable_to_connect, Snackbar.LENGTH_INDEFINITE).apply {
if (Locale.getDefault().language == "ko")
setAction(context.getText(R.string.https_text)) {
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(context.getString(R.string.https))))
}
}.show()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import xyz.quaver.io.util.deleteRecursively
import xyz.quaver.pupil.R
import xyz.quaver.pupil.histories
import xyz.quaver.pupil.util.byteToString
import xyz.quaver.pupil.util.downloader.Cache
import xyz.quaver.pupil.util.downloader.DownloadManager
import java.io.File

Expand Down Expand Up @@ -61,6 +62,8 @@ class ManageStorageFragment : PreferenceFragmentCompat(), Preference.OnPreferenc
if (dir.exists())
dir.deleteRecursively()

Cache.instances.clear()

summary = context.getString(R.string.settings_storage_usage, byteToString(0))
CoroutineScope(Dispatchers.IO).launch {
var size = 0L
Expand Down
Loading

0 comments on commit 54a5cd2

Please sign in to comment.