mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 14:37:59 +01:00
cache thumbnails by timestamp signature
This commit is contained in:
parent
bd2a39dbb8
commit
f635173b1f
3 changed files with 13 additions and 9 deletions
|
@ -10,6 +10,7 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||||
|
import com.bumptech.glide.signature.StringSignature;
|
||||||
import com.simplemobiletools.gallery.R;
|
import com.simplemobiletools.gallery.R;
|
||||||
import com.simplemobiletools.gallery.models.Directory;
|
import com.simplemobiletools.gallery.models.Directory;
|
||||||
|
|
||||||
|
@ -44,12 +45,13 @@ public class DirectoryAdapter extends BaseAdapter {
|
||||||
viewHolder.dirName.setText(dir.getName());
|
viewHolder.dirName.setText(dir.getName());
|
||||||
viewHolder.photoCnt.setText(String.valueOf(dir.getMediaCnt()));
|
viewHolder.photoCnt.setText(String.valueOf(dir.getMediaCnt()));
|
||||||
final String tmb = dir.getThumbnail();
|
final String tmb = dir.getThumbnail();
|
||||||
|
final StringSignature timestampSignature = new StringSignature(String.valueOf(dir.getTimestamp()));
|
||||||
if (tmb.endsWith(".gif")) {
|
if (tmb.endsWith(".gif")) {
|
||||||
Glide.with(mContext).load(tmb).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).placeholder(R.color.tmb_background)
|
Glide.with(mContext).load(tmb).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature)
|
||||||
.centerCrop().crossFade().into(viewHolder.dirThumbnail);
|
.placeholder(R.color.tmb_background).centerCrop().crossFade().into(viewHolder.dirThumbnail);
|
||||||
} else {
|
} else {
|
||||||
Glide.with(mContext).load(tmb).diskCacheStrategy(DiskCacheStrategy.NONE).placeholder(R.color.tmb_background)
|
Glide.with(mContext).load(tmb).diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature)
|
||||||
.centerCrop().crossFade().into(viewHolder.dirThumbnail);
|
.placeholder(R.color.tmb_background).centerCrop().crossFade().into(viewHolder.dirThumbnail);
|
||||||
}
|
}
|
||||||
|
|
||||||
return convertView;
|
return convertView;
|
||||||
|
|
|
@ -9,6 +9,7 @@ import android.widget.ImageView;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||||
|
import com.bumptech.glide.signature.StringSignature;
|
||||||
import com.simplemobiletools.gallery.R;
|
import com.simplemobiletools.gallery.R;
|
||||||
import com.simplemobiletools.gallery.models.Medium;
|
import com.simplemobiletools.gallery.models.Medium;
|
||||||
|
|
||||||
|
@ -47,11 +48,12 @@ public class MediaAdapter extends BaseAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
final String path = medium.getPath();
|
final String path = medium.getPath();
|
||||||
|
final StringSignature timestampSignature = new StringSignature(String.valueOf(medium.getTimestamp()));
|
||||||
if (medium.isGif()) {
|
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 {
|
} else {
|
||||||
Glide.with(mContext).load(path).diskCacheStrategy(DiskCacheStrategy.NONE).placeholder(R.color.tmb_background)
|
Glide.with(mContext).load(path).diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature)
|
||||||
.centerCrop().crossFade().into(viewHolder.photoThumbnail);
|
.placeholder(R.color.tmb_background).centerCrop().crossFade().into(viewHolder.photoThumbnail);
|
||||||
}
|
}
|
||||||
|
|
||||||
return convertView;
|
return convertView;
|
||||||
|
|
|
@ -62,7 +62,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
var out: FileOutputStream? = null
|
var out: FileOutputStream? = null
|
||||||
try {
|
try {
|
||||||
out = FileOutputStream(file)
|
out = FileOutputStream(file)
|
||||||
result.bitmap.compress(getFileExtension(file), 100, out)
|
result.bitmap.compress(getCompressionFormat(file), 100, out)
|
||||||
setResult(Activity.RESULT_OK, intent)
|
setResult(Activity.RESULT_OK, intent)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Crop compressing failed $e")
|
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) {
|
return when (file.extension) {
|
||||||
"png" -> Bitmap.CompressFormat.PNG
|
"png" -> Bitmap.CompressFormat.PNG
|
||||||
"webp" -> Bitmap.CompressFormat.WEBP
|
"webp" -> Bitmap.CompressFormat.WEBP
|
||||||
|
|
Loading…
Reference in a new issue