Skip to content

Commit

Permalink
Merge branch 'include-image-decode-stack-widget' into feature/eusm_de…
Browse files Browse the repository at this point in the history
…velop
  • Loading branch information
dubdabasoduba committed Jul 1, 2024
2 parents c43097f + 9a8a2ae commit 62249f4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

Expand Down Expand Up @@ -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<Binary>(resourceId)?.let { binary ->
imageProps.imageConfig?.decodedBitmap = binary.data.decodeToBitmap()
try {
val resourceId =
imageProps.imageConfig
?.reference
?.interpolate(computedValuesMap)
?.extractLogicalIdUuid()

if (resourceId != null) {
registerRepository.loadResource<Binary>(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}")
}
}
}
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,4 +734,18 @@ class ConfigExtensionsTest : RobolectricTest() {
)
assertNotNull(imageProperties.imageConfig?.decodedBitmap)
}

@Test
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
loadRemoteImagesBitmaps(
listOf(columnProperties.children[0]),
computedValuesMap = emptyMap(),
registerRepository = registerRepository,
)

assertNotNull("Bitmap should be decoded and set correctly")
}
}

0 comments on commit 62249f4

Please sign in to comment.