skip memory cache at loading thumbnails after rotation

This commit is contained in:
tibbi 2019-01-29 15:11:11 +01:00
parent 56bc2b6af1
commit f34ae01115
2 changed files with 15 additions and 9 deletions

View File

@ -43,6 +43,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
private val viewType = config.getFolderViewType(if (config.showAll) SHOW_ALL else path) private val viewType = config.getFolderViewType(if (config.showAll) SHOW_ALL else path)
private val isListViewType = viewType == VIEW_TYPE_LIST private val isListViewType = viewType == VIEW_TYPE_LIST
private var visibleItemPaths = ArrayList<String>() private var visibleItemPaths = ArrayList<String>()
private var rotatedImagePaths = ArrayList<String>()
private var loadImageInstantly = false private var loadImageInstantly = false
private var delayHandler = Handler(Looper.getMainLooper()) private var delayHandler = Handler(Looper.getMainLooper())
private var currentMediaHash = media.hashCode() private var currentMediaHash = media.hashCode()
@ -280,7 +281,9 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
Thread { Thread {
val paths = getSelectedPaths().filter { it.isImageFast() } val paths = getSelectedPaths().filter { it.isImageFast() }
var fileCnt = paths.size var fileCnt = paths.size
rotatedImagePaths.clear()
paths.forEach { paths.forEach {
rotatedImagePaths.add(it)
activity.saveRotatedImageToFile(it, it, degrees, true) { activity.saveRotatedImageToFile(it, it, degrees, true) {
fileCnt-- fileCnt--
if (fileCnt == 0) { if (fileCnt == 0) {
@ -460,14 +463,14 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
} }
if (loadImageInstantly) { if (loadImageInstantly) {
activity.loadImage(medium.type, path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails) activity.loadImage(medium.type, path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails, rotatedImagePaths)
} else { } else {
medium_thumbnail.setImageDrawable(null) medium_thumbnail.setImageDrawable(null)
medium_thumbnail.isHorizontalScrolling = scrollHorizontally medium_thumbnail.isHorizontalScrolling = scrollHorizontally
delayHandler.postDelayed({ delayHandler.postDelayed({
val isVisible = visibleItemPaths.contains(medium.path) val isVisible = visibleItemPaths.contains(medium.path)
if (isVisible) { if (isVisible) {
activity.loadImage(medium.type, path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails) activity.loadImage(medium.type, path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails, rotatedImagePaths)
} }
}, IMAGE_LOAD_DELAY) }, IMAGE_LOAD_DELAY)
} }

View File

@ -387,13 +387,14 @@ fun Context.getFolderNameFromPath(path: String): String {
} }
} }
fun Context.loadImage(type: Int, path: String, target: MySquareImageView, horizontalScroll: Boolean, animateGifs: Boolean, cropThumbnails: Boolean) { fun Context.loadImage(type: Int, path: String, target: MySquareImageView, horizontalScroll: Boolean, animateGifs: Boolean, cropThumbnails: Boolean,
skipMemoryCacheAtPaths: ArrayList<String>? = null) {
target.isHorizontalScrolling = horizontalScroll target.isHorizontalScrolling = horizontalScroll
if (type == TYPE_IMAGES || type == TYPE_VIDEOS || type == TYPE_RAWS) { if (type == TYPE_IMAGES || type == TYPE_VIDEOS || type == TYPE_RAWS) {
if (type == TYPE_IMAGES && path.isPng()) { if (type == TYPE_IMAGES && path.isPng()) {
loadPng(path, target, cropThumbnails) loadPng(path, target, cropThumbnails, skipMemoryCacheAtPaths)
} else { } else {
loadJpg(path, target, cropThumbnails) loadJpg(path, target, cropThumbnails, skipMemoryCacheAtPaths)
} }
} else if (type == TYPE_GIFS) { } else if (type == TYPE_GIFS) {
try { 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 target.scaleType = if (cropThumbnails) ImageView.ScaleType.CENTER_CROP else ImageView.ScaleType.FIT_CENTER
} catch (e: Exception) { } catch (e: Exception) {
loadJpg(path, target, cropThumbnails) loadJpg(path, target, cropThumbnails, skipMemoryCacheAtPaths)
} catch (e: OutOfMemoryError) { } catch (e: OutOfMemoryError) {
loadJpg(path, target, cropThumbnails) loadJpg(path, target, cropThumbnails, skipMemoryCacheAtPaths)
} }
} else if (type == TYPE_SVGS) { } else if (type == TYPE_SVGS) {
loadSVG(path, target, cropThumbnails) 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<String>? = null) {
val options = RequestOptions() val options = RequestOptions()
.signature(path.getFileSignature()) .signature(path.getFileSignature())
.skipMemoryCache(skipMemoryCacheAtPaths?.contains(path) == true)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE) .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.format(DecodeFormat.PREFER_ARGB_8888) .format(DecodeFormat.PREFER_ARGB_8888)
@ -449,9 +451,10 @@ fun Context.loadPng(path: String, target: MySquareImageView, cropThumbnails: Boo
builder.apply(options).into(target) 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<String>? = null) {
val options = RequestOptions() val options = RequestOptions()
.signature(path.getFileSignature()) .signature(path.getFileSignature())
.skipMemoryCache(skipMemoryCacheAtPaths?.contains(path) == true)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE) .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
val builder = Glide.with(applicationContext) val builder = Glide.with(applicationContext)