Skip to content

Commit 889249f

Browse files
alperozturk96backportbot[bot]
authored andcommitted
wip
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent 0ec64c9 commit 889249f

3 files changed

Lines changed: 41 additions & 40 deletions

File tree

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

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import android.graphics.drawable.BitmapDrawable
1111
import androidx.core.content.ContextCompat
1212
import androidx.core.graphics.drawable.toBitmap
1313
import androidx.core.graphics.drawable.toDrawable
14-
import androidx.exifinterface.media.ExifInterface
14+
import com.nextcloud.utils.extensions.getBitmapSize
15+
import com.nextcloud.utils.extensions.getExifSize
1516
import com.owncloud.android.MainApp
1617
import com.owncloud.android.R
1718
import com.owncloud.android.datamodel.OCFile
@@ -41,8 +42,8 @@ object OCFileUtils {
4142
// Local file
4243
val path = ocFile.storagePath
4344
if (!path.isNullOrEmpty() && ocFile.exists()) {
44-
getExifSize(path)?.let { return it }
45-
getBitmapSize(path)?.let { return it }
45+
path.getExifSize()?.let { return it }
46+
path.getBitmapSize()?.let { return it }
4647
}
4748

4849
// 3 Fallback
@@ -55,41 +56,6 @@ object OCFileUtils {
5556
return fallbackPair
5657
}
5758

58-
fun getExifSize(path: String): Pair<Int, Int>? = try {
59-
val exif = ExifInterface(path)
60-
var w = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0)
61-
var h = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0)
62-
63-
val orientation = exif.getAttributeInt(
64-
ExifInterface.TAG_ORIENTATION,
65-
ExifInterface.ORIENTATION_NORMAL
66-
)
67-
if (orientation == ExifInterface.ORIENTATION_ROTATE_90 ||
68-
orientation == ExifInterface.ORIENTATION_ROTATE_270
69-
) {
70-
val tmp = w
71-
w = h
72-
h = tmp
73-
}
74-
75-
Log_OC.d(TAG, "Using exif imageDimension: $w x $h")
76-
if (w > 0 && h > 0) w to h else null
77-
} catch (_: Exception) {
78-
null
79-
}
80-
81-
fun getBitmapSize(path: String): Pair<Int, Int>? = try {
82-
val options = android.graphics.BitmapFactory.Options().apply { inJustDecodeBounds = true }
83-
android.graphics.BitmapFactory.decodeFile(path, options)
84-
val w = options.outWidth
85-
val h = options.outHeight
86-
87-
Log_OC.d(TAG, "Using bitmap factory imageDimension: $w x $h")
88-
if (w > 0 && h > 0) w to h else null
89-
} catch (_: Exception) {
90-
null
91-
}
92-
9359
fun getMediaPlaceholder(file: OCFile, imageDimension: Pair<Int, Int>): BitmapDrawable {
9460
val context = MainApp.getAppContext()
9561

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package com.nextcloud.utils.extensions
99

10+
import androidx.exifinterface.media.ExifInterface
1011
import com.owncloud.android.datamodel.OCFile
1112
import com.owncloud.android.lib.common.utils.Log_OC
1213
import com.owncloud.android.utils.DisplayUtils
@@ -50,3 +51,38 @@ fun String.toFile(): File? {
5051

5152
return file
5253
}
54+
55+
fun String.getExifSize(): Pair<Int, Int>? = try {
56+
val exif = ExifInterface(this)
57+
var w = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0)
58+
var h = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0)
59+
60+
val orientation = exif.getAttributeInt(
61+
ExifInterface.TAG_ORIENTATION,
62+
ExifInterface.ORIENTATION_NORMAL
63+
)
64+
if (orientation == ExifInterface.ORIENTATION_ROTATE_90 ||
65+
orientation == ExifInterface.ORIENTATION_ROTATE_270
66+
) {
67+
val tmp = w
68+
w = h
69+
h = tmp
70+
}
71+
72+
Log_OC.d(TAG, "Using exif imageDimension: $w x $h")
73+
if (w > 0 && h > 0) w to h else null
74+
} catch (_: Exception) {
75+
null
76+
}
77+
78+
fun String.getBitmapSize(): Pair<Int, Int>? = try {
79+
val options = android.graphics.BitmapFactory.Options().apply { inJustDecodeBounds = true }
80+
android.graphics.BitmapFactory.decodeFile(this, options)
81+
val w = options.outWidth
82+
val h = options.outHeight
83+
84+
Log_OC.d(TAG, "Using bitmap factory imageDimension: $w x $h")
85+
if (w > 0 && h > 0) w to h else null
86+
} catch (_: Exception) {
87+
null
88+
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
package com.nextcloud.utils.extensions
99

10-
import com.nextcloud.utils.OCFileUtils
1110
import com.nextcloud.utils.TimeConstants
1211
import com.owncloud.android.lib.resources.files.model.RemoteFile
1312
import com.owncloud.android.utils.FileUtil
@@ -35,7 +34,7 @@ private fun RemoteFile.areImageDimensionsSame(path: String): Boolean {
3534
return true
3635
}
3736

38-
val localFileImageDimension = OCFileUtils.getExifSize(path) ?: OCFileUtils.getBitmapSize(path)
37+
val localFileImageDimension = path.getExifSize() ?: path.getBitmapSize()
3938
if (localFileImageDimension == null) {
4039
// can't compare local file image dimension is not determined
4140
return true

0 commit comments

Comments
 (0)