@@ -32,10 +32,7 @@ import kotlinx.coroutines.sync.Semaphore
3232import kotlinx.coroutines.sync.withPermit
3333import kotlinx.coroutines.withContext
3434
35- class GalleryImageGenerationJob (
36- private val user : User ,
37- private val storageManager : FileDataStorageManager
38- ) {
35+ class GalleryImageGenerationJob (private val user : User , private val storageManager : FileDataStorageManager ) {
3936 companion object {
4037 private const val TAG = " GalleryImageGenerationJob"
4138 private val semaphore = Semaphore (
@@ -80,11 +77,7 @@ class GalleryImageGenerationJob(
8077 }
8178 }
8279
83- private fun getPlaceholder (
84- file : OCFile ,
85- width : Int ,
86- viewThemeUtils : ViewThemeUtils
87- ): BitmapDrawable {
80+ private fun getPlaceholder (file : OCFile , width : Int , viewThemeUtils : ViewThemeUtils ): BitmapDrawable {
8881 val context = MainApp .getAppContext()
8982
9083 val placeholder = MimeTypeUtil .getFileTypeIcon(
@@ -111,35 +104,34 @@ class GalleryImageGenerationJob(
111104 width : Int ,
112105 viewThemeUtils : ViewThemeUtils ,
113106 onThumbnailGeneration : () -> Unit
114- ): Bitmap ? =
115- withContext(Dispatchers .IO ) {
116- if (file.remoteId == null && ! file.isPreviewAvailable) {
117- Log_OC .w(TAG , " file has no remoteId and no preview" )
118- return @withContext null
119- }
107+ ): Bitmap ? = withContext(Dispatchers .IO ) {
108+ if (file.remoteId == null && ! file.isPreviewAvailable) {
109+ Log_OC .w(TAG , " file has no remoteId and no preview" )
110+ return @withContext null
111+ }
120112
121- val key = file.remoteId
122- val cachedThumbnail = ThumbnailsCacheManager .getBitmapFromDiskCache(
123- ThumbnailsCacheManager .PREFIX_RESIZED_IMAGE + file.remoteId
124- )
125- if (cachedThumbnail != null && ! file.isUpdateThumbnailNeeded) {
126- Log_OC .d(TAG , " cached thumbnail is used for: ${file.fileName} " )
127- return @withContext getThumbnailFromCache(file, cachedThumbnail, key)
128- }
113+ val key = file.remoteId
114+ val cachedThumbnail = ThumbnailsCacheManager .getBitmapFromDiskCache(
115+ ThumbnailsCacheManager .PREFIX_RESIZED_IMAGE + file.remoteId
116+ )
117+ if (cachedThumbnail != null && ! file.isUpdateThumbnailNeeded) {
118+ Log_OC .d(TAG , " cached thumbnail is used for: ${file.fileName} " )
119+ return @withContext getThumbnailFromCache(file, cachedThumbnail, key)
120+ }
129121
130- Log_OC .d(TAG , " generating new thumbnail for: ${file.fileName} " )
122+ Log_OC .d(TAG , " generating new thumbnail for: ${file.fileName} " )
131123
132- // only add placeholder if new thumbnail will be generated because cached image will appear so quickly
133- withContext(Dispatchers .Main ) {
134- val placeholderDrawable = getPlaceholder(file, width, viewThemeUtils)
135- imageView.setImageDrawable(placeholderDrawable)
136- }
124+ // only add placeholder if new thumbnail will be generated because cached image will appear so quickly
125+ withContext(Dispatchers .Main ) {
126+ val placeholderDrawable = getPlaceholder(file, width, viewThemeUtils)
127+ imageView.setImageDrawable(placeholderDrawable)
128+ }
137129
138- onThumbnailGeneration()
139- semaphore.withPermit {
140- return @withContext getThumbnailFromServerAndAddToCache(file, cachedThumbnail)
141- }
130+ onThumbnailGeneration()
131+ semaphore.withPermit {
132+ return @withContext getThumbnailFromServerAndAddToCache(file, cachedThumbnail)
142133 }
134+ }
143135
144136 private suspend fun setThumbnail (
145137 bitmap : Bitmap ,
0 commit comments