Made download simple
Bug fixed
This commit is contained in:
@@ -4,6 +4,7 @@ import android.app.AlertDialog
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.drawable.Animatable
|
||||
import android.os.Environment
|
||||
import android.util.Log
|
||||
import android.util.SparseBooleanArray
|
||||
import android.view.LayoutInflater
|
||||
@@ -31,6 +32,7 @@ import xyz.quaver.pupil.Pupil
|
||||
import xyz.quaver.pupil.R
|
||||
import xyz.quaver.pupil.types.Tag
|
||||
import xyz.quaver.pupil.util.Histories
|
||||
import xyz.quaver.pupil.util.getCachedGallery
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
@@ -57,10 +59,10 @@ class GalleryBlockAdapter(private val galleries: List<Pair<GalleryBlock, Deferre
|
||||
}
|
||||
}.toMap()
|
||||
|
||||
val (gallery: GalleryBlock, thumbnail: Deferred<String>) = item
|
||||
val (galleryBlock: GalleryBlock, thumbnail: Deferred<String>) = item
|
||||
|
||||
val artists = gallery.artists
|
||||
val series = gallery.series
|
||||
val artists = galleryBlock.artists
|
||||
val series = galleryBlock.series
|
||||
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
val cache = thumbnail.await()
|
||||
@@ -68,10 +70,7 @@ class GalleryBlockAdapter(private val galleries: List<Pair<GalleryBlock, Deferre
|
||||
if (!File(cache).exists())
|
||||
return@launch
|
||||
|
||||
val bitmap = when {
|
||||
BuildConfig.DEBUG -> Bitmap.createScaledBitmap(BitmapFactory.decodeFile(thumbnail.await()), 5, 8, true)
|
||||
else -> BitmapFactory.decodeFile(thumbnail.await())
|
||||
}
|
||||
val bitmap = BitmapFactory.decodeFile(thumbnail.await())
|
||||
|
||||
post {
|
||||
galleryblock_thumbnail.setImageBitmap(bitmap)
|
||||
@@ -79,22 +78,8 @@ class GalleryBlockAdapter(private val galleries: List<Pair<GalleryBlock, Deferre
|
||||
}
|
||||
|
||||
//Check cache
|
||||
val readerCache = {
|
||||
File(ContextCompat.getDataDir(context), "images/${gallery.id}/reader.json").let {
|
||||
when {
|
||||
it.exists() -> it
|
||||
else -> File(context.cacheDir, "imageCache/${gallery.id}/reader.json")
|
||||
}
|
||||
}
|
||||
}
|
||||
val imageCache = {
|
||||
File(ContextCompat.getDataDir(context), "images/${gallery.id}/images").let {
|
||||
when {
|
||||
it.exists() -> it
|
||||
else -> File(context.cacheDir, "imageCache/${gallery.id}/images")
|
||||
}
|
||||
}
|
||||
}
|
||||
val readerCache = { File(getCachedGallery(context, galleryBlock.id), "reader.json") }
|
||||
val imageCache = { File(getCachedGallery(context, galleryBlock.id), "images") }
|
||||
|
||||
if (readerCache.invoke().exists()) {
|
||||
val reader = Json(JsonConfiguration.Stable)
|
||||
@@ -131,7 +116,7 @@ class GalleryBlockAdapter(private val galleries: List<Pair<GalleryBlock, Deferre
|
||||
}
|
||||
|
||||
if (progress == max) {
|
||||
if (completeFlag.get(gallery.id, false)) {
|
||||
if (completeFlag.get(galleryBlock.id, false)) {
|
||||
with(view.galleryblock_progress_complete) {
|
||||
setImageResource(R.drawable.ic_progressbar)
|
||||
visibility = View.VISIBLE
|
||||
@@ -143,7 +128,7 @@ class GalleryBlockAdapter(private val galleries: List<Pair<GalleryBlock, Deferre
|
||||
visibility = View.VISIBLE
|
||||
}
|
||||
drawable?.start()
|
||||
completeFlag.put(gallery.id, true)
|
||||
completeFlag.put(galleryBlock.id, true)
|
||||
}
|
||||
} else
|
||||
view.galleryblock_progress_complete.visibility = View.INVISIBLE
|
||||
@@ -157,7 +142,7 @@ class GalleryBlockAdapter(private val galleries: List<Pair<GalleryBlock, Deferre
|
||||
refreshTasks[this@GalleryViewHolder] = refresh
|
||||
}
|
||||
|
||||
galleryblock_title.text = gallery.title
|
||||
galleryblock_title.text = galleryBlock.title
|
||||
with(galleryblock_artist) {
|
||||
text = artists.joinToString(", ") { it.wordCapitalize() }
|
||||
visibility = when {
|
||||
@@ -204,31 +189,31 @@ class GalleryBlockAdapter(private val galleries: List<Pair<GalleryBlock, Deferre
|
||||
}
|
||||
}
|
||||
with(galleryblock_type) {
|
||||
text = resources.getString(R.string.galleryblock_type, gallery.type).wordCapitalize()
|
||||
text = resources.getString(R.string.galleryblock_type, galleryBlock.type).wordCapitalize()
|
||||
setOnClickListener {
|
||||
setOnClickListener {
|
||||
for(callback in onChipClickedHandler)
|
||||
callback.invoke(Tag("type", gallery.type))
|
||||
callback.invoke(Tag("type", galleryBlock.type))
|
||||
}
|
||||
}
|
||||
}
|
||||
with(galleryblock_language) {
|
||||
text =
|
||||
resources.getString(R.string.galleryblock_language, languages[gallery.language])
|
||||
resources.getString(R.string.galleryblock_language, languages[galleryBlock.language])
|
||||
visibility = when {
|
||||
gallery.language.isNotEmpty() -> View.VISIBLE
|
||||
galleryBlock.language.isNotEmpty() -> View.VISIBLE
|
||||
else -> View.GONE
|
||||
}
|
||||
setOnClickListener {
|
||||
setOnClickListener {
|
||||
for(callback in onChipClickedHandler)
|
||||
callback.invoke(Tag("language", gallery.language))
|
||||
callback.invoke(Tag("language", galleryBlock.language))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
galleryblock_tag_group.removeAllViews()
|
||||
gallery.relatedTags.forEach {
|
||||
galleryBlock.relatedTags.forEach {
|
||||
val tag = Tag.parse(it).let { tag ->
|
||||
when {
|
||||
tag.area != null -> tag
|
||||
@@ -263,19 +248,19 @@ class GalleryBlockAdapter(private val galleries: List<Pair<GalleryBlock, Deferre
|
||||
galleryblock_tag_group.addView(chip)
|
||||
}
|
||||
|
||||
galleryblock_id.text = gallery.id.toString()
|
||||
galleryblock_id.text = galleryBlock.id.toString()
|
||||
|
||||
if (!::favorites.isInitialized)
|
||||
favorites = (context.applicationContext as Pupil).favorites
|
||||
|
||||
with(galleryblock_favorite) {
|
||||
post {
|
||||
isChecked = favorites.contains(gallery.id)
|
||||
isChecked = favorites.contains(galleryBlock.id)
|
||||
}
|
||||
setOnClickListener {
|
||||
when {
|
||||
isChecked -> favorites.add(gallery.id)
|
||||
else -> favorites.remove(gallery.id)
|
||||
isChecked -> favorites.add(galleryBlock.id)
|
||||
else -> favorites.remove(galleryBlock.id)
|
||||
}
|
||||
}
|
||||
setOnCheckedChangeListener { _, isChecked ->
|
||||
|
||||
Reference in New Issue
Block a user