Image loading fixed
This commit is contained in:
@@ -20,7 +20,7 @@ android {
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 29
|
||||
versionCode 43
|
||||
versionName "4.7-beta1"
|
||||
versionName "4.7-beta2"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
multiDexEnabled true
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
|
||||
@@ -1 +1 @@
|
||||
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":43,"versionName":"4.7-beta1","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
|
||||
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":43,"versionName":"4.7-beta2","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
|
||||
@@ -122,6 +122,8 @@ class ReaderAdapter(private val context: Context,
|
||||
val progress = DownloadWorker.getInstance(context).progress[galleryID]?.get(position)
|
||||
|
||||
if (progress?.isInfinite() == true && images != null) {
|
||||
holder.view.reader_item_progressbar.visibility = View.GONE
|
||||
|
||||
glide
|
||||
.load(images)
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
|
||||
@@ -961,7 +961,9 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
Mode.DOWNLOAD -> {
|
||||
val downloads = getDownloadDirectory(this@MainActivity).listFiles()?.filter { file ->
|
||||
file.isDirectory && (file.name.toIntOrNull() != null) && File(file, ".metadata").exists()
|
||||
file.isDirectory && file.name.toIntOrNull() != null
|
||||
}?.sortedByDescending {
|
||||
it.lastModified()
|
||||
}?.map {
|
||||
it.name.toInt()
|
||||
} ?: emptyList()
|
||||
|
||||
@@ -21,6 +21,7 @@ package xyz.quaver.pupil.util.download
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.util.Base64
|
||||
import android.util.SparseArray
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.crashlytics.android.Crashlytics
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -38,9 +39,25 @@ import xyz.quaver.pupil.util.json
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.net.URL
|
||||
import java.util.concurrent.locks.Lock
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
|
||||
class Cache(context: Context) : ContextWrapper(context) {
|
||||
|
||||
private val locks = SparseArray<Lock>()
|
||||
private fun lock(galleryID: Int) {
|
||||
synchronized(locks) {
|
||||
if (locks.indexOfKey(galleryID) < 0)
|
||||
locks.put(galleryID, ReentrantLock())
|
||||
}
|
||||
|
||||
locks[galleryID].lock()
|
||||
}
|
||||
|
||||
private fun unlock(galleryID: Int) {
|
||||
locks[galleryID]?.unlock()
|
||||
}
|
||||
|
||||
private val preference = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
|
||||
// Search in this order
|
||||
@@ -217,13 +234,16 @@ class Cache(context: Context) : ContextWrapper(context) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
fun putImage(galleryID: Int, index: Int, ext: String, data: InputStream) {
|
||||
val cache = File(getCachedGallery(galleryID), "%05d.$ext".format(index)).also {
|
||||
if (!it.exists())
|
||||
it.createNewFile()
|
||||
}
|
||||
|
||||
data.copyTo(FileOutputStream(cache))
|
||||
data.use {
|
||||
it.copyTo(FileOutputStream(cache))
|
||||
}
|
||||
}
|
||||
|
||||
fun moveToDownload(galleryID: Int) {
|
||||
@@ -233,7 +253,7 @@ class Cache(context: Context) : ContextWrapper(context) {
|
||||
}
|
||||
val download = File(getDownloadDirectory(this), galleryID.toString())
|
||||
|
||||
cache.copyRecursively(download, true)
|
||||
cache.copyRecursively(download, true) { _, _ -> OnErrorAction.SKIP }
|
||||
cache.deleteRecursively()
|
||||
}
|
||||
|
||||
|
||||
@@ -37,13 +37,14 @@ import okio.*
|
||||
import xyz.quaver.Code
|
||||
import xyz.quaver.hitomi.Reader
|
||||
import xyz.quaver.hitomi.getReferer
|
||||
import xyz.quaver.hitomi.urlFromUrlFromHash
|
||||
import xyz.quaver.hitomi.imageUrlFromImage
|
||||
import xyz.quaver.hiyobi.cookie
|
||||
import xyz.quaver.hiyobi.createImgList
|
||||
import xyz.quaver.hiyobi.user_agent
|
||||
import xyz.quaver.proxy
|
||||
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
|
||||
@@ -215,10 +216,10 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont
|
||||
when (reader.code) {
|
||||
Code.HITOMI -> {
|
||||
url(
|
||||
urlFromUrlFromHash(
|
||||
imageUrlFromImage(
|
||||
galleryID,
|
||||
reader.galleryInfo.files[index],
|
||||
if (lowQuality) "webp" else null
|
||||
lowQuality
|
||||
)
|
||||
)
|
||||
addHeader("Referer", getReferer(galleryID))
|
||||
@@ -256,7 +257,7 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont
|
||||
val cache = Cache(this@DownloadWorker).getImages(galleryID)
|
||||
|
||||
progress.put(galleryID, reader.galleryInfo.files.indices.map { index ->
|
||||
if (cache?.getOrNull(index) != null)
|
||||
if (cache?.firstOrNull { it?.nameWithoutExtension?.toIntOrNull() == index } != null)
|
||||
Float.POSITIVE_INFINITY
|
||||
else
|
||||
0F
|
||||
@@ -308,9 +309,9 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont
|
||||
override fun onResponse(call: Call, response: Response) {
|
||||
Log.i("PUPILD", "OK ${call.request().tag()}")
|
||||
|
||||
try {
|
||||
val ext = call.request().url().encodedPath().split('.').last()
|
||||
|
||||
try {
|
||||
response.body().use {
|
||||
Cache(this@DownloadWorker).putImage(galleryID, i, ext, it.byteStream())
|
||||
}
|
||||
@@ -332,6 +333,7 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont
|
||||
|
||||
Log.i("PUPILD", "SUCCESS ${call.request().tag()}")
|
||||
} catch (e: Exception) {
|
||||
File(Cache(this@DownloadWorker).getCachedGallery(galleryID), "%05d.$ext".format(i)).delete()
|
||||
Log.i("PUPILD", "FAIL ON OK ${call.request().tag()} (${e.message})")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,11 @@
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:maxHeight="5000dp"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
android:background="@drawable/reader_item_boundary">
|
||||
|
||||
<LinearLayout
|
||||
|
||||
Reference in New Issue
Block a user