-
Notifications
You must be signed in to change notification settings - Fork 584
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
Migrate to Jetpack Tile previews #1162
Conversation
The description doesn't match the PR
When it clearly is. |
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.
Nice
addIdToImageMapping( | ||
state.contacts[1].imageResourceId(), | ||
bitmapToImageResource( | ||
BitmapFactory.decodeResource(context.resources, R.drawable.ali) |
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.
Using drawableResToImageResource
seems like an improvement.
You could consider inlining it if you want to minimise horologist usage here.
public fun drawableResToImageResource(
@DrawableRes id: Int,
): ImageResource =
ImageResource.Builder()
.setAndroidResourceByResId(
AndroidImageResourceByResId.Builder()
.setResourceId(id)
.build(),
)
.build()
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.
I was considering an extension function to enable addIdToImageMapping()
to take a DrawableRes or ImageResource:
fun ResourceBuilders.Resources.Builder.addIdToImageMapping(
id: String,
@DrawableRes resId: Int
): ResourceBuilders.Resources.Builder = addIdToImageMapping(
id, ResourceBuilders.ImageResource.Builder()
.setAndroidResourceByResId(
ResourceBuilders.AndroidImageResourceByResId.Builder()
.setResourceId(resId)
.build()
)
.build()
)
Not sure whether this is idiomatic (versus the function approach) or whether it should be called addIdToResourceMapping()
, etc. so was leaving it for a future PR.
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.
Added enhanced addIdToImageMapping()
in #1164.
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.
Great!
This is a mostly mechanical change however there is one meaningful difference: previously the
ImageResource
passed toonTileResourceRequest()
was passed throughbitmapToImageResource()
, where theBitmap
was extracted from the context viaBitmapFactory.decodeResource()
. I think this was mostly to demonstrate how to process a rawBitmap
.However, with the new preview library, it's not possible to access the context (I think?), so we bypass this transformation step and instead generate the
ImageResource
viadrawableResToImageResource()
(which takes a resource id).I think this is fine since the main point is to generate a preview rather than transform images from one format to another (the previews themselves are identical) but others may disagree!
Before ("compose"):
Before ("Wear tile services"):
After: