Skip to content

Commit

Permalink
Adds extension function to enable addIdToImageMapping() to support dr…
Browse files Browse the repository at this point in the history
…awables (#1164)
  • Loading branch information
ithinkihaveacat authored Sep 3, 2024
1 parent ff1b22a commit 77ab745
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
package com.example.wear.tiles.messaging

import android.content.Context
import androidx.annotation.DrawableRes
import androidx.wear.protolayout.DeviceParametersBuilders
import androidx.wear.protolayout.ModifiersBuilders
import androidx.wear.protolayout.ResourceBuilders
import androidx.wear.protolayout.ResourceBuilders.Resources
import androidx.wear.protolayout.material.Button
import androidx.wear.protolayout.material.ButtonColors
Expand All @@ -32,7 +34,6 @@ import com.example.wear.tiles.R
import com.example.wear.tiles.golden.resources
import com.example.wear.tiles.tools.MultiRoundDevicesPreviews
import com.example.wear.tiles.tools.emptyClickable
import com.google.android.horologist.tiles.images.drawableResToImageResource

/**
* Layout definition for the Messaging Tile.
Expand All @@ -58,7 +59,8 @@ internal fun messagingTileLayout(
}
.addButtonContent(searchLayout(context, emptyClickable))
.build()
).setPrimaryChipContent(
)
.setPrimaryChipContent(
CompactChip.Builder(
context,
context.getString(R.string.tile_messaging_create_new),
Expand Down Expand Up @@ -104,15 +106,15 @@ private fun messagingTilePreview(context: Context): TilePreviewData {
onTileResourceRequest = resources {
addIdToImageMapping(
state.contacts[1].imageResourceId(),
drawableResToImageResource(R.drawable.ali)
R.drawable.ali
)
addIdToImageMapping(
state.contacts[2].imageResourceId(),
drawableResToImageResource(R.drawable.taylor)
R.drawable.taylor
)
addIdToImageMapping(
MessagingTileRenderer.ID_IC_SEARCH,
drawableResToImageResource(R.drawable.ic_search_24)
R.drawable.ic_search_24
)
},
onTileRequest = { request ->
Expand Down Expand Up @@ -147,7 +149,7 @@ private fun contactWithImagePreview(context: Context): TilePreviewData {
onTileResourceRequest = {
Resources.Builder().addIdToImageMapping(
"${MessagingTileRenderer.ID_CONTACT_PREFIX}${contact.id}",
drawableResToImageResource(R.drawable.ali)
R.drawable.ali
).build()
},
onTileRequest = {
Expand All @@ -162,11 +164,24 @@ private fun searchButtonPreview(context: Context) = TilePreviewData(
onTileResourceRequest = {
Resources.Builder().addIdToImageMapping(
MessagingTileRenderer.ID_IC_SEARCH,
drawableResToImageResource(R.drawable.ic_search_24)
R.drawable.ic_search_24
).build()
},
onTileRequest = {
TilePreviewHelper.singleTimelineEntryTileBuilder(
searchLayout(context, emptyClickable)
).build()
})

fun Resources.Builder.addIdToImageMapping(
id: String,
@DrawableRes resId: Int
): Resources.Builder = addIdToImageMapping(
id, ResourceBuilders.ImageResource.Builder()
.setAndroidResourceByResId(
ResourceBuilders.AndroidImageResourceByResId.Builder()
.setResourceId(resId)
.build()
)
.build()
)
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MessagingTileRenderer(context: Context) :
/* id = */
ID_IC_SEARCH,
/* image = */
drawableResToImageResource(R.drawable.ic_search_24)
R.drawable.ic_search_24
)
}

Expand Down

0 comments on commit 77ab745

Please sign in to comment.