Fixed image broken after download finishes

This commit is contained in:
tom5079
2019-08-28 09:21:36 +09:00
parent 27a8694938
commit e664efefe9
3 changed files with 16 additions and 11 deletions

View File

@@ -32,8 +32,12 @@ import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
import xyz.quaver.pupil.BuildConfig
import xyz.quaver.pupil.R
import xyz.quaver.pupil.util.getCachedGallery
import java.io.File
class ReaderAdapter(private val glide: RequestManager, private val images: List<String>) : RecyclerView.Adapter<ReaderAdapter.ViewHolder>() {
class ReaderAdapter(private val glide: RequestManager,
private val galleryID: Int,
private val images: List<String>) : RecyclerView.Adapter<ReaderAdapter.ViewHolder>() {
var isFullScreen = false
private var prev : Drawable? = null
@@ -52,7 +56,7 @@ class ReaderAdapter(private val glide: RequestManager, private val images: List<
holder.view as ImageView
glide
.load(images[position])
.load(File(getCachedGallery(holder.view.context, galleryID), images[position]))
.dontTransform()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)

View File

@@ -330,7 +330,7 @@ class ReaderActivity : AppCompatActivity() {
private fun initView() {
with(reader_recyclerview) {
adapter = ReaderAdapter(Glide.with(this@ReaderActivity), images)
adapter = ReaderAdapter(Glide.with(this@ReaderActivity), galleryID, images)
addOnScrollListener(object: RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {

View File

@@ -63,16 +63,17 @@ class GalleryDownloader(
field = true
notificationManager.notify(galleryID, notificationBuilder.build())
val data = File(getDownloadDirectory(this), galleryID.toString())
val cache = File(cacheDir, "imageCache/$galleryID")
if (reader?.isActive == false && downloadJob?.isActive != true) {
val data = File(getDownloadDirectory(this), galleryID.toString())
val cache = File(cacheDir, "imageCache/$galleryID")
if (File(cache, "images").exists() && !data.exists()) {
cache.copyRecursively(data, true)
cache.deleteRecursively()
}
if (File(cache, "images").exists() && !data.exists()) {
cache.copyRecursively(data, true)
cache.deleteRecursively()
}
if (reader?.isActive == false && downloadJob?.isActive != true)
field = false
}
downloads.add(galleryID)
} else {
@@ -223,7 +224,7 @@ class GalleryDownloader(
notificationManager.notify(galleryID, notificationBuilder.build())
}
cache.absolutePath
"images/$name.$ext"
}
}.forEach {
list.add(it.await())