Skip to content

Commit 812f971

Browse files
committed
use correct placeholder and image size
Signed-off-by: alperozturk <[email protected]>
1 parent a73ebf8 commit 812f971

File tree

4 files changed

+42
-46
lines changed

4 files changed

+42
-46
lines changed

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import com.owncloud.android.datamodel.OCFile
2020
import com.owncloud.android.datamodel.ThumbnailsCacheManager
2121
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
2222
import com.owncloud.android.lib.common.utils.Log_OC
23-
import com.owncloud.android.lib.resources.files.model.ImageDimension
2423
import com.owncloud.android.utils.MimeTypeUtil
2524
import kotlinx.coroutines.Dispatchers
2625
import kotlinx.coroutines.sync.Semaphore
@@ -129,23 +128,11 @@ class GalleryImageGenerationJob(private val user: User, private val storageManag
129128
}
130129

131130
imageView.setImageBitmap(bitmap)
132-
imageView.invalidate()
131+
// imageView.invalidate()
133132
listener.onSuccess()
134133
}
135134

136135
private fun getThumbnailFromCache(file: OCFile, thumbnail: Bitmap, key: String): Bitmap {
137-
val size = ThumbnailsCacheManager.getThumbnailDimension().toFloat()
138-
139-
val imageDimension = file.imageDimension
140-
if (imageDimension == null || imageDimension.width != size || imageDimension.height != size) {
141-
val newDimension = ImageDimension(
142-
thumbnail.getWidth().toFloat(),
143-
thumbnail.getHeight().toFloat()
144-
)
145-
file.imageDimension = newDimension
146-
storageManager.saveFile(file)
147-
}
148-
149136
var result = thumbnail
150137
if (MimeTypeUtil.isVideo(file)) {
151138
result = ThumbnailsCacheManager.addVideoOverlay(thumbnail, MainApp.getAppContext())

app/src/main/java/com/nextcloud/utils/OCFileUtils.kt

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,41 @@ object OCFileUtils {
2727
try {
2828
Log_OC.d(TAG, "Getting image size for: ${ocFile.fileName}")
2929

30-
if (!ocFile.exists()) {
31-
ocFile.imageDimension?.width?.let { w ->
32-
ocFile.imageDimension?.height?.let { h ->
33-
Log_OC.d(TAG, "Image dimensions are used width: $w and height: $h")
34-
return w.toInt() to h.toInt()
35-
}
36-
}
37-
38-
Log_OC.d(TAG, "Default size is used: $defaultThumbnailSize")
39-
val size = defaultThumbnailSize.toInt().coerceAtLeast(1)
40-
return size to size
30+
val widthFromDimension = ocFile.imageDimension?.width
31+
val heightFromDimension = ocFile.imageDimension?.height
32+
if (widthFromDimension != null && heightFromDimension != null) {
33+
val width = widthFromDimension.toInt()
34+
val height = heightFromDimension.toInt()
35+
Log_OC.d(TAG, "Image dimensions are used, width: $width, height: $height")
36+
return width to height
4137
}
4238

43-
val exif = ExifInterface(ocFile.storagePath)
44-
val width = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0)
45-
val height = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0)
39+
return if (ocFile.exists()) {
40+
val exif = ExifInterface(ocFile.storagePath)
41+
val width = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0)
42+
val height = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0)
4643

47-
if (width > 0 && height > 0) {
48-
Log_OC.d(TAG, "Exif used width: $width and height: $height")
49-
return width to height
50-
}
44+
if (width > 0 && height > 0) {
45+
Log_OC.d(TAG, "Exif used width: $width and height: $height")
46+
width to height
47+
}
5148

52-
val (bitmapWidth, bitmapHeight) = BitmapUtils.getImageResolution(ocFile.storagePath)
53-
.let { it[0] to it[1] }
49+
val (bitmapWidth, bitmapHeight) = BitmapUtils.getImageResolution(ocFile.storagePath)
50+
.let { it[0] to it[1] }
5451

55-
if (bitmapWidth > 0 && bitmapHeight > 0) {
56-
Log_OC.d(TAG, "BitmapUtils.getImageResolution used width: $bitmapWidth and height: $bitmapHeight")
57-
return bitmapWidth to bitmapHeight
58-
}
52+
if (bitmapWidth > 0 && bitmapHeight > 0) {
53+
Log_OC.d(TAG, "BitmapUtils.getImageResolution used width: $bitmapWidth and height: $bitmapHeight")
54+
bitmapWidth to bitmapHeight
55+
}
5956

60-
val fallback = defaultThumbnailSize.toInt().coerceAtLeast(1)
61-
Log_OC.d(TAG, "Default size used width: $fallback and height: $fallback")
62-
return fallback to fallback
57+
val fallback = defaultThumbnailSize.toInt().coerceAtLeast(1)
58+
Log_OC.d(TAG, "Default size used width: $fallback and height: $fallback")
59+
fallback to fallback
60+
} else {
61+
Log_OC.d(TAG, "Default size is used: $defaultThumbnailSize")
62+
val size = defaultThumbnailSize.toInt().coerceAtLeast(1)
63+
size to size
64+
}
6365
} finally {
6466
Log_OC.d(TAG, "-----------------------------")
6567
}

app/src/main/java/com/nextcloud/utils/extensions/OCFileExtensions.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,9 @@ fun List<OCFile>.limitToPersonalFiles(userId: String): List<OCFile> = filter { f
3131
ownerId == userId && !file.isSharedWithMe && !file.mounted()
3232
} == true
3333
}
34+
35+
fun OCFile.mediaSize(defaultThumbnailSize: Float): Pair<Int, Int> {
36+
val width = (imageDimension?.width?.toInt() ?: defaultThumbnailSize.toInt())
37+
val height = (imageDimension?.height?.toInt() ?: defaultThumbnailSize.toInt())
38+
return width to height
39+
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.elyeproj.loaderviewlibrary.LoaderImageView
2020
import com.nextcloud.android.common.ui.theme.utils.ColorRole
2121
import com.nextcloud.utils.OCFileUtils
2222
import com.nextcloud.utils.extensions.makeRounded
23+
import com.nextcloud.utils.extensions.mediaSize
2324
import com.nextcloud.utils.extensions.setVisibleIf
2425
import com.owncloud.android.R
2526
import com.owncloud.android.databinding.GalleryRowBinding
@@ -101,21 +102,21 @@ class GalleryRowHolder(
101102
}
102103
}
103104

105+
val mediaSize = file.mediaSize(defaultThumbnailSize)
106+
val (width, height) = mediaSize
107+
104108
val shimmer = LoaderImageView(context).apply {
105109
setImageResource(R.drawable.background)
106110
resetLoader()
107-
invalidate()
111+
layoutParams = FrameLayout.LayoutParams(width, height)
108112
}
109113

110-
// FIXME using max height for row calculation is not always producing correct row ratio
111-
112-
// FIXME check from webdav --- image dimension must be available there thus no need to use default size
113-
val mediaSize = defaultThumbnailSize.toInt() to defaultThumbnailSize.toInt()
114114
val drawable = OCFileUtils.getMediaPlaceholder(file, mediaSize)
115115
val rowCellImageView = ImageView(context).apply {
116116
setImageDrawable(drawable)
117117
adjustViewBounds = true
118118
scaleType = ImageView.ScaleType.FIT_XY
119+
layoutParams = FrameLayout.LayoutParams(width, height)
119120
}
120121

121122
return FrameLayout(context).apply {

0 commit comments

Comments
 (0)