mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-29 16:08:00 +01:00
use a more advanced cache key by using size too
This commit is contained in:
parent
60e0a68c1c
commit
440aea9eb8
7 changed files with 41 additions and 23 deletions
|
@ -8,6 +8,7 @@ import android.graphics.drawable.ColorDrawable
|
|||
import android.os.Bundle
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.RemoteViews
|
||||
import com.bumptech.glide.signature.ObjectKey
|
||||
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
|
@ -167,7 +168,8 @@ class WidgetConfigureActivity : SimpleActivity() {
|
|||
val path = directoryDao.getDirectoryThumbnail(folderPath)
|
||||
if (path != null) {
|
||||
runOnUiThread {
|
||||
loadJpg(path, config_image, config.cropThumbnails, ROUNDED_CORNERS_NONE, 0)
|
||||
val signature = ObjectKey(System.currentTimeMillis().toString())
|
||||
loadJpg(path, config_image, config.cropThumbnails, ROUNDED_CORNERS_NONE, signature)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -710,7 +710,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
|
|||
else -> ROUNDED_CORNERS_BIG
|
||||
}
|
||||
|
||||
activity.loadImage(thumbnailType, directory.tmb, dir_thumbnail, scrollHorizontally, animateGifs, cropThumbnails, roundedCorners, directory.modified)
|
||||
activity.loadImage(thumbnailType, directory.tmb, dir_thumbnail, scrollHorizontally, animateGifs, cropThumbnails, roundedCorners, directory.getKey())
|
||||
}
|
||||
|
||||
dir_pin.beVisibleIf(pinnedFolders.contains(directory.path))
|
||||
|
|
|
@ -540,8 +540,9 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
|||
}
|
||||
|
||||
val roundedCorners = if (isListViewType) ROUNDED_CORNERS_SMALL else ROUNDED_CORNERS_NONE
|
||||
|
||||
if (loadImageInstantly) {
|
||||
activity.loadImage(medium.type, path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails, roundedCorners, medium.modified,
|
||||
activity.loadImage(medium.type, path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails, roundedCorners, medium.getKey(),
|
||||
rotatedImagePaths)
|
||||
} else {
|
||||
medium_thumbnail.setImageDrawable(null)
|
||||
|
@ -550,7 +551,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
|
|||
val isVisible = visibleItemPaths.contains(medium.path)
|
||||
if (isVisible) {
|
||||
activity.loadImage(medium.type, path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails, roundedCorners,
|
||||
medium.modified, rotatedImagePaths)
|
||||
medium.getKey(), rotatedImagePaths)
|
||||
}
|
||||
}, IMAGE_LOAD_DELAY)
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import com.bumptech.glide.load.resource.bitmap.CenterCrop
|
|||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
|
||||
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import com.bumptech.glide.signature.ObjectKey
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.gallery.pro.R
|
||||
|
@ -398,17 +399,17 @@ fun Context.getFolderNameFromPath(path: String): String {
|
|||
}
|
||||
|
||||
fun Context.loadImage(type: Int, path: String, target: MySquareImageView, horizontalScroll: Boolean, animateGifs: Boolean, cropThumbnails: Boolean,
|
||||
roundCorners: Int, lastModified: Long, skipMemoryCacheAtPaths: ArrayList<String>? = null) {
|
||||
roundCorners: Int, signature: ObjectKey, skipMemoryCacheAtPaths: ArrayList<String>? = null) {
|
||||
target.isHorizontalScrolling = horizontalScroll
|
||||
if (type == TYPE_IMAGES || type == TYPE_VIDEOS || type == TYPE_RAWS || type == TYPE_PORTRAITS) {
|
||||
if (type == TYPE_IMAGES && path.isPng()) {
|
||||
loadPng(path, target, cropThumbnails, roundCorners, lastModified, skipMemoryCacheAtPaths)
|
||||
loadPng(path, target, cropThumbnails, roundCorners, signature, skipMemoryCacheAtPaths)
|
||||
} else {
|
||||
loadJpg(path, target, cropThumbnails, roundCorners, lastModified, skipMemoryCacheAtPaths)
|
||||
loadJpg(path, target, cropThumbnails, roundCorners, signature, skipMemoryCacheAtPaths)
|
||||
}
|
||||
} else if (type == TYPE_GIFS) {
|
||||
if (!animateGifs) {
|
||||
loadStaticGIF(path, target, cropThumbnails, roundCorners, lastModified, skipMemoryCacheAtPaths)
|
||||
loadStaticGIF(path, target, cropThumbnails, roundCorners, signature, skipMemoryCacheAtPaths)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -419,12 +420,12 @@ 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) {
|
||||
loadStaticGIF(path, target, cropThumbnails, roundCorners, lastModified, skipMemoryCacheAtPaths)
|
||||
loadStaticGIF(path, target, cropThumbnails, roundCorners, signature, skipMemoryCacheAtPaths)
|
||||
} catch (e: OutOfMemoryError) {
|
||||
loadStaticGIF(path, target, cropThumbnails, roundCorners, lastModified, skipMemoryCacheAtPaths)
|
||||
loadStaticGIF(path, target, cropThumbnails, roundCorners, signature, skipMemoryCacheAtPaths)
|
||||
}
|
||||
} else if (type == TYPE_SVGS) {
|
||||
loadSVG(path, target, cropThumbnails, roundCorners, lastModified)
|
||||
loadSVG(path, target, cropThumbnails, roundCorners, signature)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -449,9 +450,9 @@ fun Context.getPathLocation(path: String): Int {
|
|||
}
|
||||
}
|
||||
|
||||
fun Context.loadPng(path: String, target: MySquareImageView, cropThumbnails: Boolean, roundCorners: Int, lastModified: Long, skipMemoryCacheAtPaths: ArrayList<String>? = null) {
|
||||
fun Context.loadPng(path: String, target: MySquareImageView, cropThumbnails: Boolean, roundCorners: Int, signature: ObjectKey, skipMemoryCacheAtPaths: ArrayList<String>? = null) {
|
||||
val options = RequestOptions()
|
||||
.signature(path.getFileSignature(lastModified))
|
||||
.signature(signature)
|
||||
.skipMemoryCache(skipMemoryCacheAtPaths?.contains(path) == true)
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||
.priority(Priority.LOW)
|
||||
|
@ -472,9 +473,9 @@ fun Context.loadPng(path: String, target: MySquareImageView, cropThumbnails: Boo
|
|||
builder.into(target)
|
||||
}
|
||||
|
||||
fun Context.loadJpg(path: String, target: MySquareImageView, cropThumbnails: Boolean, roundCorners: Int, lastModified: Long, skipMemoryCacheAtPaths: ArrayList<String>? = null) {
|
||||
fun Context.loadJpg(path: String, target: MySquareImageView, cropThumbnails: Boolean, roundCorners: Int, signature: ObjectKey, skipMemoryCacheAtPaths: ArrayList<String>? = null) {
|
||||
val options = RequestOptions()
|
||||
.signature(path.getFileSignature(lastModified))
|
||||
.signature(signature)
|
||||
.skipMemoryCache(skipMemoryCacheAtPaths?.contains(path) == true)
|
||||
.priority(Priority.LOW)
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||
|
@ -494,9 +495,9 @@ fun Context.loadJpg(path: String, target: MySquareImageView, cropThumbnails: Boo
|
|||
builder.into(target)
|
||||
}
|
||||
|
||||
fun Context.loadStaticGIF(path: String, target: MySquareImageView, cropThumbnails: Boolean, roundCorners: Int, lastModified: Long, skipMemoryCacheAtPaths: ArrayList<String>? = null) {
|
||||
fun Context.loadStaticGIF(path: String, target: MySquareImageView, cropThumbnails: Boolean, roundCorners: Int, signature: ObjectKey, skipMemoryCacheAtPaths: ArrayList<String>? = null) {
|
||||
val options = RequestOptions()
|
||||
.signature(path.getFileSignature(lastModified))
|
||||
.signature(signature)
|
||||
.skipMemoryCache(skipMemoryCacheAtPaths?.contains(path) == true)
|
||||
.priority(Priority.LOW)
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||
|
@ -516,10 +517,10 @@ fun Context.loadStaticGIF(path: String, target: MySquareImageView, cropThumbnail
|
|||
builder.into(target)
|
||||
}
|
||||
|
||||
fun Context.loadSVG(path: String, target: MySquareImageView, cropThumbnails: Boolean, roundCorners: Int, lastModified: Long) {
|
||||
fun Context.loadSVG(path: String, target: MySquareImageView, cropThumbnails: Boolean, roundCorners: Int, signature: ObjectKey) {
|
||||
target.scaleType = if (cropThumbnails) ImageView.ScaleType.CENTER_CROP else ImageView.ScaleType.FIT_CENTER
|
||||
|
||||
val options = RequestOptions().signature(path.getFileSignature(lastModified))
|
||||
val options = RequestOptions().signature(signature)
|
||||
var builder = Glide.with(applicationContext)
|
||||
.`as`(PictureDrawable::class.java)
|
||||
.listener(SvgSoftwareLayerSetter())
|
||||
|
|
|
@ -410,7 +410,7 @@ class PhotoFragment : ViewPagerFragment() {
|
|||
private fun loadWithGlide(path: String, addZoomableView: Boolean) {
|
||||
val priority = if (mIsFragmentVisible) Priority.IMMEDIATE else Priority.NORMAL
|
||||
val options = RequestOptions()
|
||||
.signature(getFilePathToShow().getFileSignature(mMedium.modified))
|
||||
.signature(mMedium.getKey())
|
||||
.format(DecodeFormat.PREFER_ARGB_8888)
|
||||
.priority(priority)
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||
|
@ -450,7 +450,7 @@ class PhotoFragment : ViewPagerFragment() {
|
|||
val picasso = Picasso.get()
|
||||
.load(pathToLoad)
|
||||
.centerInside()
|
||||
.stableKey(mMedium.path.getFileKey(mMedium.modified))
|
||||
.stableKey(mMedium.getSignature())
|
||||
.resize(mScreenWidth, mScreenHeight)
|
||||
|
||||
if (mCurrentRotationDegrees != 0) {
|
||||
|
@ -617,7 +617,7 @@ class PhotoFragment : ViewPagerFragment() {
|
|||
val minTileDpi = if (showHighestQuality) -1 else getMinTileDpi()
|
||||
|
||||
val bitmapDecoder = object : DecoderFactory<ImageDecoder> {
|
||||
override fun make() = MyGlideImageDecoder(rotation, mMedium.getSignature())
|
||||
override fun make() = MyGlideImageDecoder(rotation, mMedium.getKey())
|
||||
}
|
||||
|
||||
val regionDecoder = object : DecoderFactory<ImageRegionDecoder> {
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.pro.models
|
|||
|
||||
import android.content.Context
|
||||
import androidx.room.*
|
||||
import com.bumptech.glide.signature.ObjectKey
|
||||
import com.simplemobiletools.commons.extensions.formatDate
|
||||
import com.simplemobiletools.commons.extensions.formatSize
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
|
@ -39,4 +40,6 @@ data class Directory(
|
|||
fun areFavorites() = path == FAVORITES
|
||||
|
||||
fun isRecycleBin() = path == RECYCLE_BIN
|
||||
|
||||
fun getKey() = ObjectKey("$path-$modified")
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import com.simplemobiletools.commons.helpers.SORT_BY_NAME
|
|||
import com.simplemobiletools.commons.helpers.SORT_BY_PATH
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
|
||||
import com.simplemobiletools.gallery.pro.helpers.*
|
||||
import java.io.File
|
||||
import java.io.Serializable
|
||||
import java.util.*
|
||||
|
||||
|
@ -91,5 +92,15 @@ data class Medium(
|
|||
return calendar.timeInMillis.toString()
|
||||
}
|
||||
|
||||
fun getSignature() = ObjectKey("$path-$modified-$size")
|
||||
fun getSignature(): String {
|
||||
val lastModified = if (modified > 1) {
|
||||
modified
|
||||
} else {
|
||||
File(path).lastModified()
|
||||
}
|
||||
|
||||
return "$path-$lastModified-$size"
|
||||
}
|
||||
|
||||
fun getKey() = ObjectKey(getSignature())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue