@@ -109,37 +109,34 @@ class GalleryImageGenerationJob(private val user: User, private val storageManag
109109 }
110110 }
111111
112- private suspend fun getBitmap (file : OCFile , onNewThumbnail : () -> Unit ): Bitmap ? =
113- withContext(Dispatchers .IO ) {
114- val cacheKey = ThumbnailsCacheManager .PREFIX_RESIZED_IMAGE + file.remoteId
115-
116- val cached = ThumbnailsCacheManager .getBitmapFromDiskCache(cacheKey)
117- if (cached != null && ! file.isUpdateThumbnailNeeded) {
118- return @withContext applyVideoOverlayIfNeeded(file, cached)
119- }
120-
121- onNewThumbnail()
112+ private suspend fun getBitmap (file : OCFile , onNewThumbnail : () -> Unit ): Bitmap ? = withContext(Dispatchers .IO ) {
113+ val cacheKey = ThumbnailsCacheManager .PREFIX_RESIZED_IMAGE + file.remoteId
122114
123- val local = decodeLocalThumbnail(file)
124- if (local != null ) {
125- ThumbnailsCacheManager .addBitmapToCache(cacheKey, local)
126- return @withContext applyVideoOverlayIfNeeded(file, local)
127- }
115+ val cached = ThumbnailsCacheManager .getBitmapFromDiskCache(cacheKey)
116+ if (cached != null && ! file.isUpdateThumbnailNeeded) {
117+ return @withContext applyVideoOverlayIfNeeded(file, cached)
118+ }
128119
129- val remote = semaphore.withPermit { fetchFromServer(file) }
130- if (remote != null ) {
131- return @withContext applyVideoOverlayIfNeeded(file, remote)
132- }
120+ onNewThumbnail()
133121
134- null
122+ val local = decodeLocalThumbnail(file)
123+ if (local != null ) {
124+ ThumbnailsCacheManager .addBitmapToCache(cacheKey, local)
125+ return @withContext applyVideoOverlayIfNeeded(file, local)
135126 }
136127
137- private fun decodeLocalThumbnail (file : OCFile ): Bitmap ? {
138- return if (MimeTypeUtil .isVideo(file)) {
139- createVideoThumbnail(file.storagePath)
140- } else {
141- createImageThumbnail(file)
128+ val remote = semaphore.withPermit { fetchFromServer(file) }
129+ if (remote != null ) {
130+ return @withContext applyVideoOverlayIfNeeded(file, remote)
142131 }
132+
133+ null
134+ }
135+
136+ private fun decodeLocalThumbnail (file : OCFile ): Bitmap ? = if (MimeTypeUtil .isVideo(file)) {
137+ createVideoThumbnail(file.storagePath)
138+ } else {
139+ createImageThumbnail(file)
143140 }
144141
145142 private fun createImageThumbnail (file : OCFile ): Bitmap ? {
@@ -180,26 +177,22 @@ class GalleryImageGenerationJob(private val user: User, private val storageManag
180177 }
181178 }
182179
183- private suspend fun fetchFromServer (file : OCFile ): Bitmap ? {
184- return try {
185- val client = withContext(Dispatchers .IO ) {
186- OwnCloudClientManagerFactory .getDefaultSingleton()
187- .getClientFor(user.toOwnCloudAccount(), MainApp .getAppContext())
188- }
189- ThumbnailsCacheManager .setClient(client)
190- ThumbnailsCacheManager .doResizedImageInBackground(file, storageManager)
191- } catch (t: Throwable ) {
192- Log_OC .e(TAG , " Server fetch failed for $file " , t)
193- null
180+ private suspend fun fetchFromServer (file : OCFile ): Bitmap ? = try {
181+ val client = withContext(Dispatchers .IO ) {
182+ OwnCloudClientManagerFactory .getDefaultSingleton()
183+ .getClientFor(user.toOwnCloudAccount(), MainApp .getAppContext())
194184 }
185+ ThumbnailsCacheManager .setClient(client)
186+ ThumbnailsCacheManager .doResizedImageInBackground(file, storageManager)
187+ } catch (t: Throwable ) {
188+ Log_OC .e(TAG , " Server fetch failed for $file " , t)
189+ null
195190 }
196191
197- private fun applyVideoOverlayIfNeeded (file : OCFile , bitmap : Bitmap ): Bitmap {
198- return if (MimeTypeUtil .isVideo(file)) {
199- ThumbnailsCacheManager .addVideoOverlay(bitmap, MainApp .getAppContext())
200- } else {
201- bitmap
202- }
192+ private fun applyVideoOverlayIfNeeded (file : OCFile , bitmap : Bitmap ): Bitmap = if (MimeTypeUtil .isVideo(file)) {
193+ ThumbnailsCacheManager .addVideoOverlay(bitmap, MainApp .getAppContext())
194+ } else {
195+ bitmap
203196 }
204197
205198 private suspend fun setThumbnail (
0 commit comments