@@ -10,6 +10,7 @@ import androidx.glance.GlanceModifier
10
10
import androidx.glance.GlanceTheme
11
11
import androidx.glance.Image
12
12
import androidx.glance.ImageProvider
13
+ import androidx.glance.LocalContext
13
14
import androidx.glance.LocalSize
14
15
import androidx.glance.action.clickable
15
16
import androidx.glance.appwidget.components.CircleIconButton
@@ -22,6 +23,8 @@ import androidx.glance.layout.fillMaxSize
22
23
import androidx.glance.layout.fillMaxWidth
23
24
import androidx.glance.layout.padding
24
25
import androidx.glance.layout.wrapContentHeight
26
+ import androidx.glance.preview.ExperimentalGlancePreviewApi
27
+ import androidx.glance.preview.Preview
25
28
import androidx.glance.text.FontWeight
26
29
import androidx.glance.text.Text
27
30
import androidx.glance.text.TextStyle
@@ -36,6 +39,9 @@ import com.example.platform.ui.appwidgets.glance.layout.collections.layout.Image
36
39
import com.example.platform.ui.appwidgets.glance.layout.collections.layout.ImageGridLayoutSize.Medium
37
40
import com.example.platform.ui.appwidgets.glance.layout.collections.layout.ImageGridLayoutSize.Small
38
41
import com.example.platform.ui.appwidgets.glance.layout.utils.ActionUtils
42
+ import com.example.platform.ui.appwidgets.glance.layout.utils.LargeWidgetPreview
43
+ import com.example.platform.ui.appwidgets.glance.layout.utils.MediumWidgetPreview
44
+ import com.example.platform.ui.appwidgets.glance.layout.utils.SmallWidgetPreview
39
45
40
46
/* *
41
47
* A layout focused on presenting a grid of images (with optional title and supporting text). The
@@ -295,4 +301,105 @@ private object ImageGridLayoutDimensions {
295
301
else -> 1
296
302
}
297
303
}
304
+ }
305
+
306
+ /* *
307
+ * Preview sizes for the widget covering the width based breakpoints of the image grid layout.
308
+ *
309
+ * This allows verifying updates across multiple breakpoints.
310
+ */
311
+ @OptIn(ExperimentalGlancePreviewApi ::class )
312
+ @Preview(widthDp = 319 , heightDp = 200 )
313
+ @Preview(widthDp = 321 , heightDp = 200 )
314
+ @Preview(widthDp = 518 , heightDp = 200 )
315
+ @Preview(widthDp = 520 , heightDp = 200 )
316
+ private annotation class ImageGridBreakpointPreviews
317
+
318
+ /* *
319
+ * Previews for the image grid layout with both title and supporting text below the image
320
+ *
321
+ * First we look at the previews at defined breakpoints, tweaking them as necessary. In addition,
322
+ * the previews at standard sizes allows us to quickly verify updates across min / max and common
323
+ * widget sizes without needing to run the app or manually place the widget.
324
+ */
325
+ @ImageGridBreakpointPreviews
326
+ @SmallWidgetPreview
327
+ @MediumWidgetPreview
328
+ @LargeWidgetPreview
329
+ @Composable
330
+ private fun ImageTextGridLayoutPreview () {
331
+ val context = LocalContext .current
332
+
333
+ ImageGridLayout (
334
+ title = context.getString(R .string.sample_image_grid_app_widget_name),
335
+ titleIconRes = R .drawable.sample_grid_icon,
336
+ titleBarActionIconRes = R .drawable.sample_refresh_icon,
337
+ titleBarActionIconContentDescription = context.getString(
338
+ R .string.sample_refresh_icon_button_label
339
+ ),
340
+ titleBarAction = {},
341
+ items = listOf (
342
+ ImageGridItemData (
343
+ key = " 0" ,
344
+ image = null , // placeholder
345
+ imageContentDescription = " A single water droplet rests in a budding red pansy." ,
346
+ title = " A single water droplet rests in a budding red pansy." ,
347
+ supportingText = " 193 views"
348
+ ),
349
+ ImageGridItemData (
350
+ key = " 1" ,
351
+ image = null , // placeholder
352
+ imageContentDescription = " A single water droplet rests in a budding red pansy." ,
353
+ title = " A single water droplet rests in a budding red pansy." ,
354
+ supportingText = " 193 views"
355
+ ),
356
+ ImageGridItemData (
357
+ key = " 2" ,
358
+ image = null , // placeholder
359
+ imageContentDescription = " Green plant, sky and flowers" ,
360
+ title = " Green plant, sky and flowers" ,
361
+ supportingText = " 99,467 views"
362
+ ),
363
+ ImageGridItemData (
364
+ key = " 3" ,
365
+ image = null , // placeholder
366
+ imageContentDescription = " A snow-shoer walking up Strelapass" ,
367
+ title = " A snow-shoer walking up Strelapass" ,
368
+ supportingText = " 3,033 views"
369
+ )
370
+ )
371
+ )
372
+ }
373
+
374
+ /* *
375
+ * Previews for the image grid layout with only images
376
+ *
377
+ * First we look at the previews at defined breakpoints, tweaking them as necessary. In addition,
378
+ * the previews at standard sizes allows us to quickly verify updates across min / max and common
379
+ * widget sizes without needing to run the app or manually place the widget.
380
+ */
381
+ @ImageGridBreakpointPreviews
382
+ @SmallWidgetPreview
383
+ @MediumWidgetPreview
384
+ @LargeWidgetPreview
385
+ @Composable
386
+ private fun ImageOnlyGridLayoutPreview () {
387
+ val context = LocalContext .current
388
+
389
+ ImageGridLayout (
390
+ title = context.getString(R .string.sample_image_grid_app_widget_name),
391
+ titleIconRes = R .drawable.sample_grid_icon,
392
+ titleBarActionIconRes = R .drawable.sample_refresh_icon,
393
+ titleBarActionIconContentDescription = context.getString(
394
+ R .string.sample_refresh_icon_button_label
395
+ ),
396
+ titleBarAction = {},
397
+ items = (0 .. 5 ).map { index ->
398
+ ImageGridItemData (
399
+ key = " $index " ,
400
+ image = null , // placeholder
401
+ imageContentDescription = null ,
402
+ )
403
+ }
404
+ )
298
405
}
0 commit comments