@@ -384,7 +384,7 @@ abstract class CryptoImplDecorator(
384384
385385 val diskCache = cryptoFile.cloudFile.cloud?.type()?.let { getLruCacheFor(it) }
386386 val cacheKey = generateCacheKey(ciphertextFile)
387- val genThumbnail = isGenerateThumbnailsEnabled (diskCache, cryptoFile.name)
387+ val genThumbnail = isThumbnailGenerationAvailable (diskCache, cryptoFile.name)
388388
389389 val thumbnailWriter = PipedOutputStream ()
390390 val thumbnailReader = PipedInputStream (thumbnailWriter)
@@ -471,11 +471,30 @@ abstract class CryptoImplDecorator(
471471 return String .format(" %s-%d" , cloudFile.cloud?.id() ? : " common" , cloudFile.path.hashCode())
472472 }
473473
474- private fun isGenerateThumbnailsEnabled (cache : DiskLruCache ? , fileName : String ): Boolean {
475- return sharedPreferencesHandler.useLruCache() &&
476- sharedPreferencesHandler.generateThumbnails() != ThumbnailsOption .NEVER &&
477- cache != null &&
478- isImageMediaType(fileName)
474+ private fun isThumbnailGenerationAvailable (cache : DiskLruCache ? , fileName : String ): Boolean {
475+ return isGenerateThumbnailsEnabled() && cache != null && isImageMediaType(fileName)
476+ }
477+
478+ protected fun associateThumbnailIfInCache (list : List <CryptoNode ?>): List <CryptoNode ?> {
479+ if (isGenerateThumbnailsEnabled()) {
480+ val firstCryptoFile = list.find { it is CryptoFile } ? : return list
481+ val cloudType = (firstCryptoFile as CryptoFile ).cloudFile.cloud?.type() ? : return list
482+ val diskCache = getLruCacheFor(cloudType) ? : return list
483+ list.onEach { cryptoNode ->
484+ if (cryptoNode is CryptoFile && isImageMediaType(cryptoNode.name)) {
485+ val cacheKey = generateCacheKey(cryptoNode.cloudFile)
486+ val cacheFile = diskCache[cacheKey]
487+ if (cacheFile != null ) {
488+ cryptoNode.thumbnail = cacheFile
489+ }
490+ }
491+ }
492+ }
493+ return list
494+ }
495+
496+ private fun isGenerateThumbnailsEnabled (): Boolean {
497+ return sharedPreferencesHandler.useLruCache() && sharedPreferencesHandler.generateThumbnails() != ThumbnailsOption .NEVER
479498 }
480499
481500 private fun storeThumbnail (cache : DiskLruCache ? , cacheKey : String , thumbnailBitmap : Bitmap ) {
@@ -493,7 +512,7 @@ abstract class CryptoImplDecorator(
493512 thumbnailFile.delete()
494513 }
495514
496- protected fun isImageMediaType (filename : String ): Boolean {
515+ private fun isImageMediaType (filename : String ): Boolean {
497516 return (mimeTypes.fromFilename(filename) ? : MimeType .WILDCARD_MIME_TYPE ).mediatype == " image"
498517 }
499518
0 commit comments