-
Notifications
You must be signed in to change notification settings - Fork 59
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
Conversation
Signed-off-by: Lentumunai-Mark <[email protected]>
… load-Binary-Images
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Signed-off-by: Lentumunai-Mark <[email protected]>
@@ -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()), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
fun String.base64toBitmap(offset: Int = 0): Bitmap { | ||
val decodedBytes = Base64.decode(this, Base64.DEFAULT) | ||
return BitmapFactory.decodeByteArray(decodedBytes, offset, decodedBytes.size) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to StringExtensions
assertEquals(83, bitmap.width) | ||
assertEquals(83, bitmap.height) |
There was a problem hiding this comment.
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()), |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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>() |
There was a problem hiding this comment.
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.
fun String.base64toBitmap(offset: Int = 0): Bitmap { | ||
val decodedBytes = Base64.decode(this, Base64.DEFAULT) | ||
return BitmapFactory.decodeByteArray(decodedBytes, offset, decodedBytes.size) | ||
} |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
closing this in favor of #3242 |
IMPORTANT: Where possible all PRs must be linked to a Github issue
Related to this issue
Engineer Checklist
strings.xml
file./gradlew spotlessApply
and./gradlew spotlessCheck
to check my code follows the project's style guideCode Reviewer Checklist
strings.xml
file