Skip to content

Commit 06abf5b

Browse files
committed
Fix previews
1 parent 01d2c4c commit 06abf5b

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ targetWearSdk = "33"
5353
[libraries]
5454
androidx-protolayout-material3 = { module = "androidx.wear.protolayout:protolayout-material3", version.ref = "protolayout" }
5555
androidx-tiles = { module = "androidx.wear.tiles:tiles", version.ref = "tiles" }
56+
androidx-tiles-tooling = { module = "androidx.wear.tiles:tiles-tooling", version.ref = "tiles" }
5657
androidx-tiles-tooling-preview = { module = "androidx.wear.tiles:tiles-tooling-preview", version.ref = "tiles" }
5758
androidx-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "uiToolingPreview" }
5859
androidx-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "uiToolingPreview" }

wearApp/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ dependencies {
8080
implementation(libs.androidx.ui.tooling)
8181
implementation(libs.wear.ui.tooling)
8282
debugImplementation(libs.androidx.ui.tooling.preview)
83-
debugImplementation("androidx.wear.tiles:tiles-tooling:1.5.0")
83+
implementation(libs.androidx.tiles.tooling)
8484

8585
implementation(libs.okhttp)
8686
implementation(libs.loggingInterceptor)

wearApp/src/main/java/com/surrus/peopleinspace/tile/PeopleInSpaceList.kt

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,12 @@ fun peopleList(
101101
},
102102
bottomSlot = {
103103
val clickable = with(protoLayoutScope) {
104-
clickable(id = "home", pendingIntent = homeIntent(context))
104+
val pendingIntent = homeIntent(context)
105+
if (pendingIntent != null) {
106+
clickable(id = "home", pendingIntent = pendingIntent)
107+
} else {
108+
clickable(id = "home")
109+
}
105110
}
106111
textEdgeButton(
107112
onClick = clickable,
@@ -119,7 +124,12 @@ fun MaterialScope.peopleButton(
119124
context: Context
120125
): LayoutElementBuilders.LayoutElement {
121126
val clickable = with(protoLayoutScope) {
122-
clickable(id = person.name, pendingIntent = personIntent(person, context))
127+
val pendingIntent = personIntent(person, context)
128+
if (pendingIntent != null) {
129+
clickable(id = person.name, pendingIntent = pendingIntent)
130+
} else {
131+
clickable(id = person.name)
132+
}
123133
}
124134
return textButton(
125135
onClick = clickable,
@@ -160,7 +170,7 @@ internal fun namesPreview(context: Context): TilePreviewData {
160170
}
161171
}
162172

163-
private fun personIntent(person: Assignment, context: Context): PendingIntent {
173+
private fun personIntent(person: Assignment, context: Context): PendingIntent? {
164174
val sessionDetailIntent = Intent(
165175
Intent.ACTION_VIEW,
166176
(DEEPLINK_URI + "personList/{${person.name}}").toUri()
@@ -174,7 +184,7 @@ private fun personIntent(person: Assignment, context: Context): PendingIntent {
174184
)
175185
}
176186

177-
private fun homeIntent(context: Context): PendingIntent {
187+
private fun homeIntent(context: Context): PendingIntent? {
178188
val sessionDetailIntent = Intent(
179189
Intent.ACTION_VIEW,
180190
("${DEEPLINK_URI}personList").toUri()
@@ -186,4 +196,38 @@ private fun homeIntent(context: Context): PendingIntent {
186196
sessionDetailIntent,
187197
FLAG_IMMUTABLE or FLAG_UPDATE_CURRENT
188198
)
199+
}
200+
201+
@MultiRoundDevicesWithFontScalePreviews
202+
internal fun twoRowsPreview(context: Context): TilePreviewData {
203+
val contacts = Data(
204+
people = listOf(
205+
Assignment(
206+
"Apollo 11",
207+
"Neil Armstrong",
208+
"https://www.biography.com/.image/ar_1:1%2Cc_fill%2Ccs_srgb%2Cfl_progressive%2Cq_auto:good%2Cw_1200/MTc5OTk0MjgyMzk5MTE0MzYy/gettyimages-150832381.jpg"
209+
),
210+
Assignment(
211+
"Apollo 11",
212+
"Buzz Aldrin",
213+
"https://nypost.com/wp-content/uploads/sites/2/2018/06/buzz-aldrin.jpg?quality=80&strip=all"
214+
),
215+
Assignment(
216+
"Vostok 1",
217+
"Yuri Gagarin",
218+
"https://nypost.com/wp-content/uploads/sites/2/2018/06/buzz-aldrin.jpg?quality=80&strip=all"
219+
),
220+
Assignment(
221+
"Sputnik 2",
222+
"Laika",
223+
"https://nypost.com/wp-content/uploads/sites/2/2018/06/buzz-aldrin.jpg?quality=80&strip=all"
224+
)
225+
), mapOf()
226+
)
227+
return TilePreviewData {
228+
TilePreviewHelper.singleTimelineEntryTileBuilder(
229+
peopleList(context, it.deviceConfiguration, contacts, it.scope)
230+
)
231+
.build()
232+
}
189233
}

0 commit comments

Comments
 (0)