From a727964be56580671b384de63eb92e2a65f887d2 Mon Sep 17 00:00:00 2001 From: Oussama Hassine Date: Wed, 20 Sep 2023 14:08:30 +0200 Subject: [PATCH 1/3] chore: enable penalty death on stric mode --- .../com/wire/android/WireApplication.kt | 39 ++++++++++--------- .../imagepreview/BulletHoleImagePreview.kt | 25 +++++++++++- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/app/src/main/kotlin/com/wire/android/WireApplication.kt b/app/src/main/kotlin/com/wire/android/WireApplication.kt index e2c6a524662..5da7df6a04f 100644 --- a/app/src/main/kotlin/com/wire/android/WireApplication.kt +++ b/app/src/main/kotlin/com/wire/android/WireApplication.kt @@ -106,24 +106,24 @@ class WireApplication : Application(), Configuration.Provider { } private fun enableStrictMode() { - if (!BuildConfig.DEBUG) return - - StrictMode.setThreadPolicy( - StrictMode.ThreadPolicy.Builder() - .detectDiskReads() - .detectDiskWrites() - .penaltyLog() - // .penaltyDeath() TODO: add it later after fixing reported violations - .build() - ) - StrictMode.setVmPolicy( - StrictMode.VmPolicy.Builder() - .detectLeakedSqlLiteObjects() - .detectLeakedClosableObjects() - .penaltyLog() - // .penaltyDeath() TODO: add it later after fixing reported violations - .build() - ) + if (BuildConfig.DEBUG) { + StrictMode.setThreadPolicy( + StrictMode.ThreadPolicy.Builder() + .detectDiskReads() + .detectDiskWrites() + .penaltyLog() + .penaltyDeath() + .build() + ) + StrictMode.setVmPolicy( + StrictMode.VmPolicy.Builder() + .detectLeakedSqlLiteObjects() + .detectLeakedClosableObjects() + .penaltyLog() + // .penaltyDeath() TODO: add it later after fixing reported violations + .build() + ) + } } private fun initializeApplicationLoggingFrameworks() { @@ -199,7 +199,8 @@ class WireApplication : Application(), Configuration.Provider { TRIM_MEMORY_UNKNOWN(-1); companion object { - fun byLevel(value: Int) = values().firstOrNull { it.level == value } ?: TRIM_MEMORY_UNKNOWN + fun byLevel(value: Int) = + values().firstOrNull { it.level == value } ?: TRIM_MEMORY_UNKNOWN } } } diff --git a/app/src/main/kotlin/com/wire/android/ui/common/imagepreview/BulletHoleImagePreview.kt b/app/src/main/kotlin/com/wire/android/ui/common/imagepreview/BulletHoleImagePreview.kt index 898c34d8f10..7d1190cc50d 100644 --- a/app/src/main/kotlin/com/wire/android/ui/common/imagepreview/BulletHoleImagePreview.kt +++ b/app/src/main/kotlin/com/wire/android/ui/common/imagepreview/BulletHoleImagePreview.kt @@ -20,6 +20,7 @@ package com.wire.android.ui.common.imagepreview +import android.graphics.Bitmap import android.net.Uri import androidx.compose.foundation.Image import androidx.compose.foundation.background @@ -29,6 +30,9 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable +import androidx.compose.runtime.State +import androidx.compose.runtime.produceState +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Size import androidx.compose.ui.geometry.toRect @@ -44,6 +48,19 @@ import androidx.constraintlayout.compose.ConstraintLayout import coil.compose.rememberAsyncImagePainter import com.wire.android.ui.common.dimensions import com.wire.android.util.toBitmap +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch + +@Composable +private fun loadBiMap(imageUri: Uri): State { + val coroutineScope = rememberCoroutineScope() + val context = LocalContext.current + return produceState(initialValue = null, imageUri) { + coroutineScope.launch(Dispatchers.IO) { + value = imageUri.toBitmap(context) + } + } +} @Composable fun BulletHoleImagePreview( @@ -67,7 +84,7 @@ fun BulletHoleImagePreview( } ) { Image( - painter = rememberAsyncImagePainter(imageUri.toBitmap(LocalContext.current)), + painter = rememberAsyncImagePainter(loadBiMap(imageUri).value), contentScale = ContentScale.Crop, contentDescription = contentDescription, modifier = Modifier.fillMaxSize(), @@ -97,7 +114,11 @@ fun BulletHoleImagePreview( @Suppress("MagicNumber") class BulletHoleShape : Shape { - override fun createOutline(size: Size, layoutDirection: LayoutDirection, density: Density): Outline { + override fun createOutline( + size: Size, + layoutDirection: LayoutDirection, + density: Density + ): Outline { return Outline.Generic( drawBulletHolePath(size) ) From 9f5935e342bc599173d4a6b0a59e998cfa0e3240 Mon Sep 17 00:00:00 2001 From: Oussama Hassine Date: Wed, 20 Sep 2023 14:36:36 +0200 Subject: [PATCH 2/3] Update app/src/main/kotlin/com/wire/android/ui/common/imagepreview/BulletHoleImagePreview.kt Co-authored-by: Alexandre Ferris --- .../android/ui/common/imagepreview/BulletHoleImagePreview.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/wire/android/ui/common/imagepreview/BulletHoleImagePreview.kt b/app/src/main/kotlin/com/wire/android/ui/common/imagepreview/BulletHoleImagePreview.kt index 7d1190cc50d..287dec8e53a 100644 --- a/app/src/main/kotlin/com/wire/android/ui/common/imagepreview/BulletHoleImagePreview.kt +++ b/app/src/main/kotlin/com/wire/android/ui/common/imagepreview/BulletHoleImagePreview.kt @@ -52,7 +52,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @Composable -private fun loadBiMap(imageUri: Uri): State { +private fun loadBitMap(imageUri: Uri): State { val coroutineScope = rememberCoroutineScope() val context = LocalContext.current return produceState(initialValue = null, imageUri) { From 44574c3e2be921bb022ebcc27fff1e97356475da Mon Sep 17 00:00:00 2001 From: Oussama Hassine Date: Wed, 20 Sep 2023 14:37:10 +0200 Subject: [PATCH 3/3] chore: typo --- .../android/ui/common/imagepreview/BulletHoleImagePreview.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/wire/android/ui/common/imagepreview/BulletHoleImagePreview.kt b/app/src/main/kotlin/com/wire/android/ui/common/imagepreview/BulletHoleImagePreview.kt index 287dec8e53a..f9c7a23e620 100644 --- a/app/src/main/kotlin/com/wire/android/ui/common/imagepreview/BulletHoleImagePreview.kt +++ b/app/src/main/kotlin/com/wire/android/ui/common/imagepreview/BulletHoleImagePreview.kt @@ -84,7 +84,7 @@ fun BulletHoleImagePreview( } ) { Image( - painter = rememberAsyncImagePainter(loadBiMap(imageUri).value), + painter = rememberAsyncImagePainter(loadBitMap(imageUri).value), contentScale = ContentScale.Crop, contentDescription = contentDescription, modifier = Modifier.fillMaxSize(),