Skip to content

Commit 361fc34

Browse files
committed
perf: simplify
Signed-off-by: alperozturk <[email protected]>
1 parent 24d63ca commit 361fc34

File tree

2 files changed

+25
-34
lines changed

2 files changed

+25
-34
lines changed

app/src/main/java/com/nextcloud/client/jobs/gallery/GalleryImageGenerationJob.kt

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ import kotlinx.coroutines.sync.Semaphore
3232
import kotlinx.coroutines.sync.withPermit
3333
import 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,

app/src/main/java/com/owncloud/android/ui/adapter/GalleryRowHolder.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import com.owncloud.android.databinding.GalleryRowBinding
2626
import com.owncloud.android.datamodel.FileDataStorageManager
2727
import com.owncloud.android.datamodel.GalleryRow
2828
import com.owncloud.android.datamodel.OCFile
29-
import com.owncloud.android.datamodel.ThumbnailsCacheManager
3029
import com.owncloud.android.lib.resources.files.model.ImageDimension
3130
import com.owncloud.android.utils.BitmapUtils
3231
import com.owncloud.android.utils.DisplayUtils

0 commit comments

Comments
 (0)