Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode base64 data for images and provide bitmap data for remote image types #3202

Closed
wants to merge 12 commits into from

Conversation

Lentumunai-Mark
Copy link
Contributor

@Lentumunai-Mark Lentumunai-Mark commented Apr 18, 2024

IMPORTANT: Where possible all PRs must be linked to a Github issue

Related to this issue

Engineer Checklist

  • I have written Unit tests for any new feature(s) and edge cases for bug fixes
  • I have added any strings visible on UI components to the strings.xml file
  • I have updated the CHANGELOG.md file for any notable changes to the codebase
  • I have run ./gradlew spotlessApply and ./gradlew spotlessCheck to check my code follows the project's style guide
  • I have built and run the FHIRCore app to verify my change fixes the issue and/or does not break the app
  • I have checked that this PR does NOT introduce breaking changes that require an update to Content and/or Configs? If it does add a sample here or a link to exactly what changes need to be made to the content.

Code Reviewer Checklist

  • I have verified Unit tests have been written for any new feature(s) and edge cases
  • I have verified any strings visible on UI components are in the strings.xml file
  • I have verifed the CHANGELOG.md file has any notable changes to the codebase
  • I have verified the solution has been implemented in a configurable and generic way for reuseable components
  • I have built and run the FHIRCore app to verify the change fixes the issue and/or does not break the app

Copy link

codecov bot commented Apr 18, 2024

Codecov Report

Attention: Patch coverage is 6.25000% with 45 lines in your changes are missing coverage. Please review.

Project coverage is 30.0%. Comparing base (ac82739) to head (0730d1d).
Report is 38 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##              main   #3202     +/-   ##
=========================================
+ Coverage     29.6%   30.0%   +0.3%     
- Complexity     658     672     +14     
=========================================
  Files          239     240      +1     
  Lines        11204   11302     +98     
  Branches      1948    1971     +23     
=========================================
+ Hits          3323    3397     +74     
- Misses        7447    7462     +15     
- Partials       434     443      +9     
Flag Coverage Δ
geowidget 47.2% <ø> (ø)
quest 5.6% <0.0%> (+0.2%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
.../fhircore/engine/util/extension/BitmapExtension.kt 75.0% <100.0%> (+15.0%) ⬆️
...ister/fhircore/quest/ui/shared/components/Image.kt 0.0% <0.0%> (ø)
...ster/fhircore/quest/ui/profile/ProfileViewModel.kt 7.9% <0.0%> (-0.6%) ⬇️
...fhircore/quest/util/extensions/LoadRemoteImages.kt 0.0% <0.0%> (ø)

... and 6 files with indirect coverage changes

@@ -183,8 +182,8 @@ fun ClickableImageIcon(
.fillMaxSize(0.9f),
bitmap = imageConfig.decodedBitmap!!.asImageBitmap(),
contentDescription = null,
contentScale = ContentScale.Crop,
colorFilter = ColorFilter.tint(tint ?: imageProperties.imageConfig?.color.parseColor()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we removing this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lentumunai-Mark Removing the color filter might interfere with the configuration of the icon color.

.interpolate(computedValuesMap)
.extractLogicalIdUuid()
runBlocking {
withTimeout(2000) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need the timeout? Let's move the delay amount to a constant if we keep this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The delay should not be required.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor the implementation to remove the timeout

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run blocking will block the operation on the current thread which is okay if this is run on Dispatcher.IO context.

@Lentumunai-Mark Lentumunai-Mark requested a review from ellykits May 3, 2024 09:36
Comment on lines +35 to +38
fun String.base64toBitmap(offset: Int = 0): Bitmap {
val decodedBytes = Base64.decode(this, Base64.DEFAULT)
return BitmapFactory.decodeByteArray(decodedBytes, offset, decodedBytes.size)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to StringExtensions

Comment on lines +40 to +41
assertEquals(83, bitmap.width)
assertEquals(83, bitmap.height)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make other assertions alongside the width & height?

@@ -183,8 +182,8 @@ fun ClickableImageIcon(
.fillMaxSize(0.9f),
bitmap = imageConfig.decodedBitmap!!.asImageBitmap(),
contentDescription = null,
contentScale = ContentScale.Crop,
colorFilter = ColorFilter.tint(tint ?: imageProperties.imageConfig?.color.parseColor()),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lentumunai-Mark Removing the color filter might interfere with the configuration of the icon color.

.interpolate(computedValuesMap)
.extractLogicalIdUuid()
runBlocking {
withTimeout(2000) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The delay should not be required.

imageProps.imageConfig?.decodedBitmap =
binary.data
.decodeToString()
.tryDecodeJson<ImageConfiguration>()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be decoded to Binary resource, the new data class used for data serialization (ImageConfiguration) is not needed.

Comment on lines +35 to +38
fun String.base64toBitmap(offset: Int = 0): Bitmap {
val decodedBytes = Base64.decode(this, Base64.DEFAULT)
return BitmapFactory.decodeByteArray(decodedBytes, offset, decodedBytes.size)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you re-use this functionality

  viewModelScope.launch(dispatcherProvider.io()) {
          registerRepository.loadResource<Binary>(resourceId.extractLogicalIdUuid())?.let { binary ->
            it.menuIconConfig!!.decodedBitmap = binary.data.decodeToBitmap()
          }
        }

The extension will no longer be necessary. Where resourceId is the image configuration reference.

registerRepository: RegisterRepository,
computedValuesMap: Map<String, Any>,
) {
fun loadIcons(view: ViewProperties) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert this to ViewPropertiesExtension (rename the class too)
fun ViewProperties.loadIcons()

.interpolate(computedValuesMap)
.extractLogicalIdUuid()
runBlocking {
withTimeout(2000) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run blocking will block the operation on the current thread which is okay if this is run on Dispatcher.IO context.

@Lentumunai-Mark
Copy link
Contributor Author

closing this in favor of #3242

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants