From ccdeb5b5c0a7a9fc5d9ef935bbc0f31fdb1b6668 Mon Sep 17 00:00:00 2001 From: Lentumunai-Mark Date: Mon, 1 Jul 2024 11:18:29 +0300 Subject: [PATCH 1/2] Include stack widget when decoding images and handle null binary exceptions. Signed-off-by: Lentumunai-Mark --- .../quest/util/extensions/ConfigExtensions.kt | 31 ++++++++++++++----- .../util/extensions/ConfigExtensionsTest.kt | 14 +++++++++ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/util/extensions/ConfigExtensions.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/util/extensions/ConfigExtensions.kt index cbd941e486..f04e20a391 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/util/extensions/ConfigExtensions.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/util/extensions/ConfigExtensions.kt @@ -36,6 +36,7 @@ import org.smartregister.fhircore.engine.configuration.view.ColumnProperties import org.smartregister.fhircore.engine.configuration.view.ImageProperties import org.smartregister.fhircore.engine.configuration.view.ListProperties import org.smartregister.fhircore.engine.configuration.view.RowProperties +import org.smartregister.fhircore.engine.configuration.view.StackViewProperties import org.smartregister.fhircore.engine.configuration.view.ViewProperties import org.smartregister.fhircore.engine.configuration.workflow.ActionTrigger import org.smartregister.fhircore.engine.configuration.workflow.ApplicationWorkflow @@ -58,6 +59,7 @@ import org.smartregister.fhircore.quest.navigation.MainNavigationScreen import org.smartregister.fhircore.quest.navigation.NavigationArg import org.smartregister.fhircore.quest.ui.shared.QuestionnaireHandler import org.smartregister.p2p.utils.startP2PScreen +import timber.log.Timber const val PRACTITIONER_ID = "practitionerId" @@ -271,13 +273,24 @@ suspend fun loadRemoteImagesBitmaps( !imageProps.imageConfig?.reference.isNullOrEmpty() && imageProps.imageConfig?.type == ICON_TYPE_REMOTE ) { - val resourceId = - imageProps.imageConfig!! - .reference!! - .interpolate(computedValuesMap) - .extractLogicalIdUuid() - registerRepository.loadResource(resourceId)?.let { binary -> - imageProps.imageConfig?.decodedBitmap = binary.data.decodeToBitmap() + try { + val resourceId = + imageProps.imageConfig + ?.reference + ?.interpolate(computedValuesMap) + ?.extractLogicalIdUuid() + + if (resourceId != null) { + registerRepository.loadResource(resourceId)?.let { binary -> + imageProps.imageConfig?.decodedBitmap = binary.data.decodeToBitmap() + } + } else { + Timber.e("Failed to decode image: Resource ID is null.") + } + } catch (nullPointerException: NullPointerException) { + Timber.e("Failed to decode image due to a null value: ${nullPointerException.message}") + } catch (exception: Exception) { + Timber.e("Failed to decode image with error: ${exception.message}") } } } @@ -297,6 +310,10 @@ suspend fun loadRemoteImagesBitmaps( val list = this as ListProperties list.registerCard.views.forEach { it.loadIcons() } } + ViewType.STACK -> { + val stack = this as StackViewProperties + stack.children.forEach { it.loadIcons() } + } else -> { // Handle any other view types if needed } diff --git a/android/quest/src/test/java/org/smartregister/fhircore/quest/util/extensions/ConfigExtensionsTest.kt b/android/quest/src/test/java/org/smartregister/fhircore/quest/util/extensions/ConfigExtensionsTest.kt index a53b9d8f22..9d5e8cac80 100644 --- a/android/quest/src/test/java/org/smartregister/fhircore/quest/util/extensions/ConfigExtensionsTest.kt +++ b/android/quest/src/test/java/org/smartregister/fhircore/quest/util/extensions/ConfigExtensionsTest.kt @@ -734,4 +734,18 @@ class ConfigExtensionsTest : RobolectricTest() { ) assertNotNull(imageProperties.imageConfig?.decodedBitmap) } + + @Test + fun testImageBitmapUpdatedCorrectlyGivenRowProperty(): Unit = runBlocking { + val cardViewProperties = profileConfiguration.views[0] as CardViewProperties + val listViewProperties = cardViewProperties.content[0] as ListProperties + val columnProperties = listViewProperties.registerCard.views[0] as ColumnProperties + loadRemoteImagesBitmaps( + listOf(columnProperties.children[0]), + computedValuesMap = emptyMap(), + registerRepository = registerRepository, + ) + + assertNotNull("Bitmap should be decoded and set correctly") + } } From a0fea8c48d10f9fc7c8c6dc6236f011d7cef52cc Mon Sep 17 00:00:00 2001 From: Lentumunai-Mark Date: Mon, 1 Jul 2024 11:26:29 +0300 Subject: [PATCH 2/2] Update test name to match the description. Signed-off-by: Lentumunai-Mark --- .../fhircore/quest/util/extensions/ConfigExtensionsTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/quest/src/test/java/org/smartregister/fhircore/quest/util/extensions/ConfigExtensionsTest.kt b/android/quest/src/test/java/org/smartregister/fhircore/quest/util/extensions/ConfigExtensionsTest.kt index 9d5e8cac80..4cbcfa69fe 100644 --- a/android/quest/src/test/java/org/smartregister/fhircore/quest/util/extensions/ConfigExtensionsTest.kt +++ b/android/quest/src/test/java/org/smartregister/fhircore/quest/util/extensions/ConfigExtensionsTest.kt @@ -736,7 +736,7 @@ class ConfigExtensionsTest : RobolectricTest() { } @Test - fun testImageBitmapUpdatedCorrectlyGivenRowProperty(): Unit = runBlocking { + fun testNullCasesUpdatedCorrectlyGivenRowProperty(): Unit = runBlocking { val cardViewProperties = profileConfiguration.views[0] as CardViewProperties val listViewProperties = cardViewProperties.content[0] as ListProperties val columnProperties = listViewProperties.registerCard.views[0] as ColumnProperties