cache thumbnails by timestamp signature

This commit is contained in:
tibbi 2016-10-06 22:25:07 +02:00
parent bd2a39dbb8
commit f635173b1f
3 changed files with 13 additions and 9 deletions

View file

@ -10,6 +10,7 @@ import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.signature.StringSignature;
import com.simplemobiletools.gallery.R;
import com.simplemobiletools.gallery.models.Directory;
@ -44,12 +45,13 @@ public class DirectoryAdapter extends BaseAdapter {
viewHolder.dirName.setText(dir.getName());
viewHolder.photoCnt.setText(String.valueOf(dir.getMediaCnt()));
final String tmb = dir.getThumbnail();
final StringSignature timestampSignature = new StringSignature(String.valueOf(dir.getTimestamp()));
if (tmb.endsWith(".gif")) {
Glide.with(mContext).load(tmb).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).placeholder(R.color.tmb_background)
.centerCrop().crossFade().into(viewHolder.dirThumbnail);
Glide.with(mContext).load(tmb).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature)
.placeholder(R.color.tmb_background).centerCrop().crossFade().into(viewHolder.dirThumbnail);
} else {
Glide.with(mContext).load(tmb).diskCacheStrategy(DiskCacheStrategy.NONE).placeholder(R.color.tmb_background)
.centerCrop().crossFade().into(viewHolder.dirThumbnail);
Glide.with(mContext).load(tmb).diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature)
.placeholder(R.color.tmb_background).centerCrop().crossFade().into(viewHolder.dirThumbnail);
}
return convertView;

View file

@ -9,6 +9,7 @@ import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.signature.StringSignature;
import com.simplemobiletools.gallery.R;
import com.simplemobiletools.gallery.models.Medium;
@ -47,11 +48,12 @@ public class MediaAdapter extends BaseAdapter {
}
final String path = medium.getPath();
final StringSignature timestampSignature = new StringSignature(String.valueOf(medium.getTimestamp()));
if (medium.isGif()) {
Glide.with(mContext).load(path).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).into(viewHolder.photoThumbnail);
Glide.with(mContext).load(path).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature).into(viewHolder.photoThumbnail);
} else {
Glide.with(mContext).load(path).diskCacheStrategy(DiskCacheStrategy.NONE).placeholder(R.color.tmb_background)
.centerCrop().crossFade().into(viewHolder.photoThumbnail);
Glide.with(mContext).load(path).diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature)
.placeholder(R.color.tmb_background).centerCrop().crossFade().into(viewHolder.photoThumbnail);
}
return convertView;

View file

@ -62,7 +62,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
var out: FileOutputStream? = null
try {
out = FileOutputStream(file)
result.bitmap.compress(getFileExtension(file), 100, out)
result.bitmap.compress(getCompressionFormat(file), 100, out)
setResult(Activity.RESULT_OK, intent)
} catch (e: Exception) {
Log.e(TAG, "Crop compressing failed $e")
@ -83,7 +83,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
}
}
private fun getFileExtension(file: File): Bitmap.CompressFormat {
private fun getCompressionFormat(file: File): Bitmap.CompressFormat {
return when (file.extension) {
"png" -> Bitmap.CompressFormat.PNG
"webp" -> Bitmap.CompressFormat.WEBP