From f01410bb1e9dae1ffe2edae324f7bbb52c3c16e0 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 13 Aug 2018 23:40:17 +0200 Subject: [PATCH] fix #911, try using Glide for image loading, if Picasso fails --- .../gallery/fragments/PhotoFragment.kt | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt index a39c630f5..e87f90478 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -16,6 +16,13 @@ import android.util.DisplayMetrics import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import com.bumptech.glide.Glide +import com.bumptech.glide.load.DataSource +import com.bumptech.glide.load.DecodeFormat +import com.bumptech.glide.load.engine.DiskCacheStrategy +import com.bumptech.glide.load.engine.GlideException +import com.bumptech.glide.request.RequestListener +import com.bumptech.glide.request.RequestOptions import com.davemorrissey.labs.subscaleview.ImageSource import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.simplemobiletools.commons.extensions.* @@ -285,12 +292,45 @@ class PhotoFragment : ViewPagerFragment() { } } - override fun onError(e: Exception) {} + override fun onError(e: Exception) { + tryLoadingWithGlide() + } }) } catch (ignored: Exception) { } } + private fun tryLoadingWithGlide() { + var targetWidth = if (ViewPagerActivity.screenWidth == 0) com.bumptech.glide.request.target.Target.SIZE_ORIGINAL else ViewPagerActivity.screenWidth + var targetHeight = if (ViewPagerActivity.screenHeight == 0) com.bumptech.glide.request.target.Target.SIZE_ORIGINAL else ViewPagerActivity.screenHeight + + if (imageOrientation == ORIENTATION_ROTATE_90) { + targetWidth = targetHeight + targetHeight = com.bumptech.glide.request.target.Target.SIZE_ORIGINAL + } + + val options = RequestOptions() + .signature(medium.path.getFileSignature()) + .format(DecodeFormat.PREFER_ARGB_8888) + .diskCacheStrategy(DiskCacheStrategy.RESOURCE) + .override(targetWidth, targetHeight) + + Glide.with(this) + .asBitmap() + .load(getPathToLoad(medium)) + .apply(options) + .listener(object : RequestListener { + override fun onLoadFailed(e: GlideException?, model: Any?, target: com.bumptech.glide.request.target.Target?, isFirstResource: Boolean): Boolean = false + + override fun onResourceReady(resource: Bitmap?, model: Any?, target: com.bumptech.glide.request.target.Target?, dataSource: DataSource?, isFirstResource: Boolean): Boolean { + if (isFragmentVisible) { + scheduleZoomableView() + } + return false + } + }).into(view.photo_view) + } + private fun openPanorama() { Intent(context, PanoramaActivity::class.java).apply { putExtra(PATH, medium.path)