add cache signatures to thumbnails

This commit is contained in:
tibbi 2017-04-03 18:35:09 +02:00
parent 152a56c32b
commit 94258a57fa

View file

@ -13,6 +13,7 @@ import android.view.ViewConfiguration
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.load.DecodeFormat import com.bumptech.glide.load.DecodeFormat
import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.signature.StringSignature
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.gallery.BuildConfig import com.simplemobiletools.gallery.BuildConfig
@ -185,6 +186,7 @@ fun SimpleActivity.removeNoMedia(path: String, callback: () -> Unit) {
} }
} }
fun Activity.getFileSignature(path: String) = StringSignature(File(path).lastModified().toString())
fun Activity.loadImage(path: String, target: MySquareImageView) { fun Activity.loadImage(path: String, target: MySquareImageView) {
if (path.isImageFast() || path.isVideoFast()) { if (path.isImageFast() || path.isVideoFast()) {
if (path.isPng()) { if (path.isPng()) {
@ -205,6 +207,7 @@ fun Activity.loadPng(path: String, target: MySquareImageView) {
val builder = Glide.with(this) val builder = Glide.with(this)
.load(path) .load(path)
.asBitmap() .asBitmap()
.signature(getFileSignature(path))
.diskCacheStrategy(DiskCacheStrategy.RESULT) .diskCacheStrategy(DiskCacheStrategy.RESULT)
.format(DecodeFormat.PREFER_ARGB_8888) .format(DecodeFormat.PREFER_ARGB_8888)
@ -215,6 +218,7 @@ fun Activity.loadPng(path: String, target: MySquareImageView) {
fun Activity.loadJpg(path: String, target: MySquareImageView) { fun Activity.loadJpg(path: String, target: MySquareImageView) {
val builder = Glide.with(this) val builder = Glide.with(this)
.load(path) .load(path)
.signature(getFileSignature(path))
.diskCacheStrategy(DiskCacheStrategy.RESULT) .diskCacheStrategy(DiskCacheStrategy.RESULT)
.crossFade() .crossFade()
@ -226,6 +230,7 @@ fun Activity.loadAnimatedGif(path: String, target: MySquareImageView) {
val builder = Glide.with(this) val builder = Glide.with(this)
.load(path) .load(path)
.asGif() .asGif()
.signature(getFileSignature(path))
.diskCacheStrategy(DiskCacheStrategy.SOURCE) .diskCacheStrategy(DiskCacheStrategy.SOURCE)
.crossFade() .crossFade()
@ -237,6 +242,7 @@ fun Activity.loadStaticGif(path: String, target: MySquareImageView) {
val builder = Glide.with(this) val builder = Glide.with(this)
.load(path) .load(path)
.asBitmap() .asBitmap()
.signature(getFileSignature(path))
.diskCacheStrategy(DiskCacheStrategy.SOURCE) .diskCacheStrategy(DiskCacheStrategy.SOURCE)
if (config.cropThumbnails) builder.centerCrop() else builder.fitCenter() if (config.cropThumbnails) builder.centerCrop() else builder.fitCenter()