From f34ae011156ea37e9b6887106cddd491840de42a Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 29 Jan 2019 15:11:11 +0100 Subject: [PATCH] skip memory cache at loading thumbnails after rotation --- .../gallery/pro/adapters/MediaAdapter.kt | 7 +++++-- .../gallery/pro/extensions/Context.kt | 17 ++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt index d103b748a..f92a5d01b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/MediaAdapter.kt @@ -43,6 +43,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList() + private var rotatedImagePaths = ArrayList() private var loadImageInstantly = false private var delayHandler = Handler(Looper.getMainLooper()) private var currentMediaHash = media.hashCode() @@ -280,7 +281,9 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList? = null) { target.isHorizontalScrolling = horizontalScroll if (type == TYPE_IMAGES || type == TYPE_VIDEOS || type == TYPE_RAWS) { if (type == TYPE_IMAGES && path.isPng()) { - loadPng(path, target, cropThumbnails) + loadPng(path, target, cropThumbnails, skipMemoryCacheAtPaths) } else { - loadJpg(path, target, cropThumbnails) + loadJpg(path, target, cropThumbnails, skipMemoryCacheAtPaths) } } else if (type == TYPE_GIFS) { try { @@ -407,9 +408,9 @@ fun Context.loadImage(type: Int, path: String, target: MySquareImageView, horizo target.scaleType = if (cropThumbnails) ImageView.ScaleType.CENTER_CROP else ImageView.ScaleType.FIT_CENTER } catch (e: Exception) { - loadJpg(path, target, cropThumbnails) + loadJpg(path, target, cropThumbnails, skipMemoryCacheAtPaths) } catch (e: OutOfMemoryError) { - loadJpg(path, target, cropThumbnails) + loadJpg(path, target, cropThumbnails, skipMemoryCacheAtPaths) } } else if (type == TYPE_SVGS) { loadSVG(path, target, cropThumbnails) @@ -435,9 +436,10 @@ fun Context.getPathLocation(path: String): Int { } } -fun Context.loadPng(path: String, target: MySquareImageView, cropThumbnails: Boolean) { +fun Context.loadPng(path: String, target: MySquareImageView, cropThumbnails: Boolean, skipMemoryCacheAtPaths: ArrayList? = null) { val options = RequestOptions() .signature(path.getFileSignature()) + .skipMemoryCache(skipMemoryCacheAtPaths?.contains(path) == true) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) .format(DecodeFormat.PREFER_ARGB_8888) @@ -449,9 +451,10 @@ fun Context.loadPng(path: String, target: MySquareImageView, cropThumbnails: Boo builder.apply(options).into(target) } -fun Context.loadJpg(path: String, target: MySquareImageView, cropThumbnails: Boolean) { +fun Context.loadJpg(path: String, target: MySquareImageView, cropThumbnails: Boolean, skipMemoryCacheAtPaths: ArrayList? = null) { val options = RequestOptions() .signature(path.getFileSignature()) + .skipMemoryCache(skipMemoryCacheAtPaths?.contains(path) == true) .diskCacheStrategy(DiskCacheStrategy.RESOURCE) val builder = Glide.with(applicationContext)