diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt index 611685d23..db7c6058d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt @@ -464,7 +464,7 @@ class PhotoFragment : ViewPagerFragment() { val minTileDpi = if (showHighestQuality) -1 else getMinTileDpi() val bitmapDecoder = object : DecoderFactory { - override fun make() = PicassoDecoder(mMedium.path, Picasso.get(), rotation) + override fun make() = MyGlideImageDecoder(rotation, mScreenWidth, mScreenHeight) } val regionDecoder = object : DecoderFactory { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MyGlideImageDecoder.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MyGlideImageDecoder.kt new file mode 100644 index 000000000..dde41e841 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MyGlideImageDecoder.kt @@ -0,0 +1,29 @@ +package com.simplemobiletools.gallery.pro.helpers + +import android.content.Context +import android.graphics.Bitmap +import android.net.Uri +import com.bumptech.glide.Glide +import com.bumptech.glide.load.DecodeFormat +import com.bumptech.glide.load.engine.DiskCacheStrategy +import com.bumptech.glide.request.RequestOptions +import com.davemorrissey.labs.subscaleview.ImageDecoder + +class MyGlideImageDecoder(val degrees: Int, val width: Int, val height: Int) : ImageDecoder { + + override fun decode(context: Context, uri: Uri): Bitmap { + val options = RequestOptions() + .format(DecodeFormat.PREFER_ARGB_8888) + .diskCacheStrategy(DiskCacheStrategy.NONE) + .fitCenter() + + val builder = Glide.with(context) + .asBitmap() + .load(uri) + .apply(options) + .transform(RotateTransformation(-degrees)) + .into(width, height) + + return builder.get() + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/PicassoDecoder.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/PicassoDecoder.kt deleted file mode 100644 index 978106763..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/PicassoDecoder.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.simplemobiletools.gallery.pro.helpers - -import android.content.Context -import android.graphics.Bitmap -import android.net.Uri -import com.davemorrissey.labs.subscaleview.ImageDecoder -import com.squareup.picasso.MemoryPolicy -import com.squareup.picasso.Picasso - -class PicassoDecoder(val tag: String, val picasso: Picasso, val degrees: Int) : ImageDecoder { - - override fun decode(context: Context, uri: Uri): Bitmap { - return picasso - .load(uri) - .tag(tag) - .config(Bitmap.Config.ARGB_8888) - .memoryPolicy(MemoryPolicy.NO_CACHE) - .rotate(-degrees.toFloat()) - .get() - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/RotateTransformation.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/RotateTransformation.kt new file mode 100644 index 000000000..9fb0fd127 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/RotateTransformation.kt @@ -0,0 +1,17 @@ +package com.simplemobiletools.gallery.pro.helpers + +import android.graphics.Bitmap +import android.graphics.Matrix +import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool +import com.bumptech.glide.load.resource.bitmap.BitmapTransformation +import java.security.MessageDigest + +class RotateTransformation(var degrees: Int) : BitmapTransformation() { + override fun updateDiskCacheKey(messageDigest: MessageDigest) {} + + override fun transform(pool: BitmapPool, toTransform: Bitmap, outWidth: Int, outHeight: Int): Bitmap { + val matrix = Matrix() + matrix.postRotate(degrees.toFloat()) + return Bitmap.createBitmap(toTransform, 0, 0, toTransform.width, toTransform.height, matrix, true) + } +}