Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 25, 2025

This PR implements the Preview Groups functionality that enables developers to preview Jetpack Compose UI components across all devices of a selected brand, with the groups now being automatically generated by the device-generator instead of manually maintained.

What's New

Automated Generation

The Preview Groups are now generated automatically by the device-generator from the device catalog data, ensuring they stay up-to-date with the latest device specifications. The generator creates:

  • PreviewGroups.kt - Main API with methods for all 2,600+ manufacturers
  • ZebraPreviewGroup.kt - Enterprise-focused categorization for Zebra devices

PreviewGroups API

A utility class that provides programmatic access to device collections grouped by manufacturer:

import se.premex.compose.preview.groups.PreviewGroups

// Get all Zebra devices (76 devices)
val zebraDevices = PreviewGroups.getZebraDevices()

// Case-insensitive brand lookup
val devices = PreviewGroups.getDevicesForBrand("zebra")

// List supported brands
val brands = PreviewGroups.getSupportedBrands()

ZebraPreviewGroup Utility

Enterprise-focused device categorization for the 76 Zebra devices in the catalog:

import se.premex.compose.preview.groups.ZebraPreviewGroup

// Access devices by category
val handhelds = ZebraPreviewGroup.Categories.handhelds       // MC series
val touchComputers = ZebraPreviewGroup.Categories.touchComputers  // TC series  
val tablets = ZebraPreviewGroup.Categories.tablets           // ET series
val vehicleComputers = ZebraPreviewGroup.Categories.vehicleComputers // VC series

Technical Implementation

The device-generator now includes a PreviewGroupsGenerator that:

  • Processes the device catalog data to group devices by manufacturer
  • Generates efficient map-based brand lookup to avoid JVM method size limits
  • Automatically categorizes devices (e.g., Zebra devices by product series)
  • Ensures the generated code stays synchronized with the device catalog

Benefits for Enterprise Development

This is particularly valuable for teams targeting enterprise fleets, field service apps, or branded device launches. Instead of manually writing dozens of @Preview annotations, developers can now:

  1. Test comprehensively across entire device fleets with a single function call
  2. Target specific categories like handhelds vs tablets for different UI layouts
  3. Validate programmatically by iterating through device specifications
  4. Save development time by avoiding manual preview setup
  5. Stay current with automatic updates when new devices are added

Example Usage

// Before: Manual preview setup for multiple devices
@Preview(name = "Zebra MC33", device = Zebra.MC33)
@Preview(name = "Zebra TC26", device = Zebra.TC26)
@Preview(name = "Zebra TC27", device = Zebra.TC27)
// ... 73 more lines for all Zebra devices
@Composable
fun WarehouseAppPreview() { /* ... */ }

// After: Programmatic access to all devices
val allZebraDevices = PreviewGroups.getZebraDevices()
// Use for validation, testing, or selective preview generation

The implementation is fully tested with comprehensive test coverage and includes detailed documentation with usage examples. The API is designed to be extensible for future brand additions while maintaining backward compatibility with the existing device catalog system.

Fixes #22.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: warting <657973+warting@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement Preview Groups for Device Brand in Compose Preview Utils Implement Preview Groups for Device Brand in Compose Preview Utils Aug 25, 2025
Copilot finished work on behalf of warting August 25, 2025 16:48
Copilot AI requested a review from warting August 25, 2025 16:48
@warting
Copy link
Contributor

warting commented Aug 25, 2025

@copilot device-generator needs to generate the groups. update device-generator. then generate the groups. commit the changes

Co-authored-by: warting <657973+warting@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 25, 2025

@copilot device-generator needs to generate the groups. update device-generator. then generate the groups. commit the changes

Done! I've updated the device-generator to automatically generate the preview groups instead of having manually created files. The generator now:

  1. Creates a PreviewGroupsGenerator that generates both PreviewGroups.kt and ZebraPreviewGroup.kt
  2. Uses the device catalog data to automatically generate methods for all 2,668+ manufacturers
  3. Uses an efficient map-based lookup approach instead of a giant when statement to avoid JVM method size limits
  4. Generates categorized Zebra device groups (handhelds, touch computers, tablets, vehicle computers, wearables)

The implementation is now fully data-driven and will automatically update whenever new devices are added to the catalog. All tests pass and the generated code compiles successfully.

Commit: 160de8f

Copilot AI changed the title Implement Preview Groups for Device Brand in Compose Preview Utils Implement automated Preview Groups generation in device-generator Aug 25, 2025
Copilot finished work on behalf of warting August 25, 2025 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Preview Groups for Device Brand in Compose Preview Utils

2 participants