@@ -384,7 +384,7 @@ abstract class CryptoImplDecorator(
384
384
385
385
val diskCache = cryptoFile.cloudFile.cloud?.type()?.let { getLruCacheFor(it) }
386
386
val cacheKey = generateCacheKey(ciphertextFile)
387
- val genThumbnail = isGenerateThumbnailsEnabled (diskCache, cryptoFile.name)
387
+ val genThumbnail = isThumbnailGenerationAvailable (diskCache, cryptoFile.name)
388
388
389
389
val thumbnailWriter = PipedOutputStream ()
390
390
val thumbnailReader = PipedInputStream (thumbnailWriter)
@@ -471,11 +471,30 @@ abstract class CryptoImplDecorator(
471
471
return String .format(" %s-%d" , cloudFile.cloud?.id() ? : " common" , cloudFile.path.hashCode())
472
472
}
473
473
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
479
498
}
480
499
481
500
private fun storeThumbnail (cache : DiskLruCache ? , cacheKey : String , thumbnailBitmap : Bitmap ) {
@@ -493,7 +512,7 @@ abstract class CryptoImplDecorator(
493
512
thumbnailFile.delete()
494
513
}
495
514
496
- protected fun isImageMediaType (filename : String ): Boolean {
515
+ private fun isImageMediaType (filename : String ): Boolean {
497
516
return (mimeTypes.fromFilename(filename) ? : MimeType .WILDCARD_MIME_TYPE ).mediatype == " image"
498
517
}
499
518
0 commit comments