improve gif loading

This commit is contained in:
tibbi 2017-03-16 21:07:49 +01:00
parent 858d66e728
commit a6622ef9e3
4 changed files with 30 additions and 14 deletions

View File

@ -333,7 +333,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
val timestampSignature = StringSignature(directory.date_modified.toString()) val timestampSignature = StringSignature(directory.date_modified.toString())
if (tmb.isGif()) { if (tmb.isGif()) {
if (animateGifs) { if (animateGifs) {
Glide.with(activity).load(tmb).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature) Glide.with(activity).load(tmb).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).signature(timestampSignature)
.placeholder(backgroundColor).centerCrop().crossFade().into(dir_thumbnail) .placeholder(backgroundColor).centerCrop().crossFade().into(dir_thumbnail)
} else { } else {
Glide.with(activity).load(tmb).asBitmap().diskCacheStrategy(DiskCacheStrategy.RESULT).signature(timestampSignature) Glide.with(activity).load(tmb).asBitmap().diskCacheStrategy(DiskCacheStrategy.RESULT).signature(timestampSignature)

View File

@ -251,7 +251,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
val timestampSignature = StringSignature(medium.date_modified.toString()) val timestampSignature = StringSignature(medium.date_modified.toString())
if (medium.isGif()) { if (medium.isGif()) {
if (animateGifs) { if (animateGifs) {
Glide.with(activity).load(path).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature) Glide.with(activity).load(path).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).signature(timestampSignature)
.placeholder(backgroundColor).centerCrop().crossFade().into(medium_thumbnail) .placeholder(backgroundColor).centerCrop().crossFade().into(medium_thumbnail)
} else { } else {
Glide.with(activity).load(path).asBitmap().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature) Glide.with(activity).load(path).asBitmap().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature)

View File

@ -12,6 +12,7 @@ import android.view.ViewGroup
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.simplemobiletools.commons.extensions.beGone
import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.extensions.getRealPathFromURI import com.simplemobiletools.gallery.extensions.getRealPathFromURI
@ -19,7 +20,7 @@ import com.simplemobiletools.gallery.helpers.GlideRotateTransformation
import com.simplemobiletools.gallery.helpers.MEDIUM import com.simplemobiletools.gallery.helpers.MEDIUM
import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.Medium
import it.sephiroth.android.library.exif2.ExifInterface import it.sephiroth.android.library.exif2.ExifInterface
import uk.co.senab.photoview.PhotoView import kotlinx.android.synthetic.main.pager_photo_item.view.*
import uk.co.senab.photoview.PhotoViewAttacher import uk.co.senab.photoview.PhotoViewAttacher
import java.io.File import java.io.File
import java.io.FileOutputStream import java.io.FileOutputStream
@ -27,11 +28,11 @@ import java.io.IOException
class PhotoFragment : ViewPagerFragment() { class PhotoFragment : ViewPagerFragment() {
lateinit var medium: Medium lateinit var medium: Medium
lateinit var view: PhotoView lateinit var view: ViewGroup
private var isFragmentVisible = false private var isFragmentVisible = false
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
view = inflater.inflate(R.layout.pager_photo_item, container, false) as PhotoView view = inflater.inflate(R.layout.pager_photo_item, container, false) as ViewGroup
medium = arguments.getSerializable(MEDIUM) as Medium medium = arguments.getSerializable(MEDIUM) as Medium
@ -70,7 +71,8 @@ class PhotoFragment : ViewPagerFragment() {
} }
} }
view.setOnPhotoTapListener(object : PhotoViewAttacher.OnPhotoTapListener { view.gif_holder.setOnClickListener { photoClicked() }
view.photo_view.setOnPhotoTapListener(object : PhotoViewAttacher.OnPhotoTapListener {
override fun onPhotoTap(view: View?, x: Float, y: Float) { override fun onPhotoTap(view: View?, x: Float, y: Float) {
photoClicked() photoClicked()
} }
@ -115,11 +117,13 @@ class PhotoFragment : ViewPagerFragment() {
private fun loadImage() { private fun loadImage() {
if (medium.isGif()) { if (medium.isGif()) {
view.photo_view.beGone()
Glide.with(this) Glide.with(this)
.load(medium.path) .load(medium.path)
.asGif() .asGif()
.diskCacheStrategy(DiskCacheStrategy.NONE) .crossFade()
.into(view) .diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(view.gif_holder)
} else { } else {
loadBitmap() loadBitmap()
} }
@ -131,9 +135,9 @@ class PhotoFragment : ViewPagerFragment() {
.asBitmap() .asBitmap()
.transform(GlideRotateTransformation(context, degrees)) .transform(GlideRotateTransformation(context, degrees))
.format(if (medium.isPng()) DecodeFormat.PREFER_ARGB_8888 else DecodeFormat.PREFER_RGB_565) .format(if (medium.isPng()) DecodeFormat.PREFER_ARGB_8888 else DecodeFormat.PREFER_RGB_565)
.thumbnail(0.3f) .thumbnail(0.2f)
.diskCacheStrategy(DiskCacheStrategy.NONE) .diskCacheStrategy(DiskCacheStrategy.NONE)
.into(view) .into(view.photo_view)
} }
fun rotateImageViewBy(degrees: Float) { fun rotateImageViewBy(degrees: Float) {
@ -142,7 +146,8 @@ class PhotoFragment : ViewPagerFragment() {
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
Glide.clear(view) Glide.clear(view.photo_view)
Glide.clear(view.gif_holder)
} }
override fun onConfigurationChanged(newConfig: Configuration?) { override fun onConfigurationChanged(newConfig: Configuration?) {

View File

@ -1,6 +1,17 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<uk.co.senab.photoview.PhotoView <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/photo_view" android:id="@+id/photo_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"/> android:layout_height="match_parent">
<ImageView
android:id="@+id/gif_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<uk.co.senab.photoview.PhotoView
android:id="@+id/photo_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>