From 569ce03f80b4f07e286ebf11a0a68762442a9761 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 7 Jul 2016 15:02:11 +0200 Subject: [PATCH] improve GIF support --- .../gallery/adapters/DirectoryAdapter.java | 10 ++++++++-- .../gallery/adapters/MediaAdapter.java | 7 ++++++- .../gallery/fragments/PhotoFragment.java | 7 ++++++- .../com/simplemobiletools/gallery/models/Medium.java | 4 ++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/gallery/adapters/DirectoryAdapter.java b/app/src/main/java/com/simplemobiletools/gallery/adapters/DirectoryAdapter.java index 06b7a5924..12f3be237 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/adapters/DirectoryAdapter.java +++ b/app/src/main/java/com/simplemobiletools/gallery/adapters/DirectoryAdapter.java @@ -9,6 +9,7 @@ import android.widget.ImageView; import android.widget.TextView; import com.bumptech.glide.Glide; +import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.simplemobiletools.gallery.R; import com.simplemobiletools.gallery.models.Directory; @@ -42,8 +43,13 @@ public class DirectoryAdapter extends BaseAdapter { final Directory dir = mDirs.get(position); viewHolder.dirName.setText(dir.getName()); viewHolder.photoCnt.setText(String.valueOf(dir.getMediaCnt())); - Glide.with(mContext).load(dir.getThumbnail()).placeholder(R.color.tmb_background).centerCrop().crossFade() - .into(viewHolder.dirThumbnail); + final String tmb = dir.getThumbnail(); + if (tmb.endsWith(".gif")) { + Glide.with(mContext).load(tmb).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).placeholder(R.color.tmb_background) + .centerCrop().crossFade().into(viewHolder.dirThumbnail); + } else { + Glide.with(mContext).load(tmb).placeholder(R.color.tmb_background).centerCrop().crossFade().into(viewHolder.dirThumbnail); + } return convertView; } diff --git a/app/src/main/java/com/simplemobiletools/gallery/adapters/MediaAdapter.java b/app/src/main/java/com/simplemobiletools/gallery/adapters/MediaAdapter.java index 5e7603e84..7a28d8e25 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/adapters/MediaAdapter.java +++ b/app/src/main/java/com/simplemobiletools/gallery/adapters/MediaAdapter.java @@ -8,6 +8,7 @@ import android.widget.BaseAdapter; import android.widget.ImageView; import com.bumptech.glide.Glide; +import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.simplemobiletools.gallery.R; import com.simplemobiletools.gallery.models.Medium; @@ -46,7 +47,11 @@ public class MediaAdapter extends BaseAdapter { } final String path = medium.getPath(); - Glide.with(mContext).load(path).placeholder(R.color.tmb_background).centerCrop().crossFade().into(viewHolder.photoThumbnail); + if (medium.isGif()) { + Glide.with(mContext).load(path).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).into(viewHolder.photoThumbnail); + } else { + Glide.with(mContext).load(path).placeholder(R.color.tmb_background).centerCrop().crossFade().into(viewHolder.photoThumbnail); + } return convertView; } diff --git a/app/src/main/java/com/simplemobiletools/gallery/fragments/PhotoFragment.java b/app/src/main/java/com/simplemobiletools/gallery/fragments/PhotoFragment.java index 706678de4..132b45d82 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/fragments/PhotoFragment.java +++ b/app/src/main/java/com/simplemobiletools/gallery/fragments/PhotoFragment.java @@ -7,6 +7,7 @@ import android.view.View; import android.view.ViewGroup; import com.bumptech.glide.Glide; +import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.request.animation.ViewPropertyAnimation; import com.simplemobiletools.gallery.Constants; import com.simplemobiletools.gallery.R; @@ -26,7 +27,11 @@ public class PhotoFragment extends ViewPagerFragment implements PhotoViewAttache return view; final PhotoView photoView = (PhotoView) view.findViewById(R.id.photo_view); - Glide.with(getContext()).load(medium.getPath()).asBitmap().thumbnail(0.2f).animate(fadeInAnimator).into(photoView); + if (medium.isGif()) { + Glide.with(getContext()).load(medium.getPath()).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).into(photoView); + } else { + Glide.with(getContext()).load(medium.getPath()).asBitmap().thumbnail(0.2f).animate(fadeInAnimator).into(photoView); + } new PhotoViewAttacher(photoView).setOnPhotoTapListener(this); return view; diff --git a/app/src/main/java/com/simplemobiletools/gallery/models/Medium.java b/app/src/main/java/com/simplemobiletools/gallery/models/Medium.java index 3855959cf..d875ce946 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/models/Medium.java +++ b/app/src/main/java/com/simplemobiletools/gallery/models/Medium.java @@ -26,6 +26,10 @@ public class Medium implements Serializable, Comparable { return timestamp; } + public boolean isGif() { + return getPath().endsWith(".gif"); + } + @Override public int compareTo(Object object) { final Medium medium = (Medium) object;