Skip to content

Add generated previews for Glance widget#2

Merged
ColbyCabrera merged 17 commits intomasterfrom
feature/glance-widget-previews
Sep 11, 2025
Merged

Add generated previews for Glance widget#2
ColbyCabrera merged 17 commits intomasterfrom
feature/glance-widget-previews

Conversation

@google-labs-jules
Copy link
Copy Markdown

This change adds generated previews for the Glance widget, following the modern Android guidelines. It adds a preview for each of the 13 supported widget sizes.


PR created automatically by Jules for task 1735503644326253602

ColbyCabrera and others added 3 commits September 10, 2025 16:10
…zing and move `AlbumArtBitmapCache`

This commit refactors the `PixelPlayGlanceWidget` to enhance its layout responsiveness and code organization.

Key changes:
- **Responsive Sizing:** The widget now uses `SizeMode.Responsive` instead of `SizeMode.Exact`. A predefined set of `DpSize` values has been introduced (e.g., `ONE_BY_ONE_SIZE`, `TWO_BY_TWO_SIZE`) to support various widget configurations. The layout selection logic in `PixelPlayGlanceAppWidgetContent` has been updated to use a `when` statement based on the current `LocalSize.current` to determine the appropriate layout composable.
- **`AlbumArtBitmapCache` Relocation:** The `AlbumArtBitmapCache` object, previously a nested object within `PixelPlayGlanceWidget.Companion`, has been moved to the top level of the `PixelPlayGlanceWidget.kt` file. This change improves its accessibility, particularly for composable functions that might need to interact with the cache.
- **Layout Definitions:** The previous verbose list of layout size constants (e.g., `VERY_THIN_LAYOUT_SIZE`, `GABE_LAYOUT_SIZE`) has been replaced with a more structured set of sizes based on common grid cell configurations (e.g., 1x1, 2x1, 3x2).
- **Preview Added:** A new `@Preview` composable, `ExtraLargeWidgetLayoutPreview`, has been added to facilitate UI development and testing of the `ExtraLargeWidgetLayout`.
- **Minor UI Adjustments:** Small adjustments to padding and spacers within the `ExtraLargeWidgetLayout` for better visual spacing.
This commit applies automated code formatting to the `PixelPlayGlanceWidget.kt` file.

The changes primarily involve:
- Adjusting parameter alignment in function definitions and calls.
- Normalizing spacing around operators and modifiers.
- Adding or removing blank lines for better readability, particularly within the `WidgetUi` composable's `when` statement.
This change adds generated previews for the Glance widget, following the modern Android guidelines.

It introduces a new file, `WidgetPreviews.kt`, which contains `@Preview` composables for all 13 supported widget sizes. This allows developers to easily preview the widget in different configurations within Android Studio.

The old `previewLayout` attribute has been removed from the widget's XML definition in favor of this new, more flexible approach. The `WidgetUi` composable has been made public to be accessible from the new preview file.
@google-labs-jules
Copy link
Copy Markdown
Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll acknowledge your comments with a 👀 emoji and then get to work. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

I will automatically address your feedback. For any comments you don't want me to act on, just include (aside).



For security, I will only act on instructions from the user who triggered this task for this pull request.

@ColbyCabrera ColbyCabrera self-assigned this Sep 10, 2025
@ColbyCabrera ColbyCabrera marked this pull request as ready for review September 10, 2025 21:16
This commit introduces the `androidx.glance:glance-preview` dependency to the project.

Key changes:
- Added `glancePreview` to the `versions` section and `androidx-glance-preview` to the `libraries` section in `gradle/libs.versions.toml`.
- Included `implementation(libs.androidx.glance.preview)` in the `dependencies` block of `app/build.gradle.kts`.
- Updated the import statement in `app/src/main/java/com/theveloper/pixelplay/ui/glancewidget/WidgetPreviews.kt` from `androidx.glance.appwidget.preview.ExperimentalGlancePreviewApi` to `androidx.glance.preview.ExperimentalGlancePreviewApi` to reflect the new dependency.

This allows for the use of preview functionality for Glance widgets.
This commit refactors the Glance widget preview functionality and updates related project configurations.

Key changes:
- **Dependency Update:** Added `androidx.glance:glance-appwidget-preview:1.2.0-alpha01` as a debug implementation dependency in `app/build.gradle.kts`.
- **Preview Refactoring:**
    - The `WidgetPreviews.kt` file was significantly refactored.
    - Introduced `PixelPlayGlanceWidgetPreviewProvider` class that extends `GlanceAppWidget` to provide the widget content for previews.
    - Consolidated multiple specific-size preview functions (e.g., `OneByOneWidgetPreview`, `TwoByTwoWidgetPreview`) into a single `PixelPlayWidget_Preview` function that utilizes the new provider. This simplifies the preview setup and makes it more maintainable.
- **Inspection Profile Update:** Updated `.idea/inspectionProfiles/Project_Default.xml` to include `previewFile` option for various Glance preview inspection tools. This likely enhances how the IDE lints and validates Glance preview code.
- **Minor UI Tweak:** In `PixelPlayGlanceWidget.kt`, the vertical padding for a `Box` acting as a divider was changed from `5.dp` to `4.dp`.
This commit introduces a suite of new `@Preview` Composable functions for the `PixelPlayGlanceWidget` to visualize its appearance across various common widget sizes.

Key changes:
- **Expanded Previews:** Added previews for multiple aspect ratios and sizes, including 1x1, 1x2, 2x1, 2x2, 3x1, 3x2, 3x3, 4x2, 4x3, 4x4, 5x3, 5x4, and 5x5.
- **Preview Refactor:** The existing generic `PixelPlayWidget_Preview` has been replaced by these more specific size previews.
- **Code Formatting:** Minor code formatting adjustments were made, such as condensing `QueueItem` declarations and `WidgetUi` parameters onto single lines.
This commit refactors the `PixelPlayGlanceWidget` and its previews to improve visual spacing and component sizing.

Key changes:
- **Widget Previews:**
    - Wrapped the `PixelPlayGlanceWidget` preview in a `Box` with a light blue background for better visual separation.
- **PixelPlayGlanceWidget:**
    - Reduced padding in various `Box` layouts.
    - Adjusted the height and spacing of `AlbumArtImageGlance`, `Spacer`, `PlayPauseButtonGlance`, `PreviousButtonGlance`, and `NextButtonGlance` components across different widget sizes to optimize layout. For instance, the album art height in the vertical layout was reduced from `48.dp` to `44.dp`, and associated spacer heights were also decreased. Similar adjustments were made to button heights and album art sizes in other layouts.
This commit introduces changes to the `PixelPlayGlanceWidget`.

Key changes:
- **Corner Radius:** The background corner radius for the `OneByOneWidgetLayout` has been changed from `28.dp` to `100.dp`.
- **Debug Code Removal:** A `println(size)` statement, likely used for debugging, has been removed.
…` for smaller sizes

This commit refactors the layout of the `PixelPlayGlanceWidget` when displayed in its smaller configurations.

Key changes:
- **Album Art:** The album art is now displayed in a `Row` that takes up one-third of the available height and spans the full width. The corner radius has been changed to 16.dp.
- **Play/Pause Button:** The `PlayPauseButtonGlance` now also occupies one-third of the available height.
- **Control Buttons Row:** The `Row` containing the previous, next, and options buttons similarly takes up one-third of the height.
- **Spacers:** The vertical spacing between the album art and the play/pause button has been increased from 8.dp to 10.dp.
- **Height Calculation:** Introduced `contentHeight` and `oneThirdHeight` variables to dynamically calculate the height for the main components based on the available space, accounting for padding and spacers.
- **Removed Fixed Heights:** Removed fixed height constraints (e.g., `height(48.dp)`, `height(30.dp)`) from various components, allowing them to adapt to the calculated one-third height.
- **Debugging Output:** Added `println` statements to log `contentHeight` and `oneThirdHeight` for debugging purposes.
This commit refactors the `PixelPlayGlanceWidget` to adjust padding and layout for a more consistent appearance.

Key changes:
- Removed unused `albumArtSize` and `size` variables as they are no longer used for manual sizing.
- Reduced horizontal padding around content from `16.dp` to `12.dp` in one layout.
- Applied `defaultWeight()` to the `AlbumArtImageGlance` to allow it to proportionally fill available space.
- Reduced the `Spacer` width between the album art and play/pause button from `14.dp` to `10.dp`.
@ColbyCabrera
Copy link
Copy Markdown
Owner

/gemini review

@google-labs-jules
Copy link
Copy Markdown
Author

/gemini review

Great! I'm ready to address any feedback that comes from the review.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a great step forward in modernizing the Glance widget by adding generated previews for all supported sizes and refactoring to a responsive layout model. The code is significantly cleaner and more maintainable. I've identified a few areas for improvement, mainly related to removing leftover debugging code, unused variables, and moving a hardcoded dependency version to the version catalog for better project consistency.

Comment on lines +586 to +591
// Total available height for the three main components, accounting for padding and spacers.
val contentHeight = LocalSize.current.height - (12.dp * 2) - (8.dp * 2)
val oneThirdHeight = contentHeight / 3

println("Content Height: $contentHeight")
println("One Third Height: $oneThirdHeight")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This block of code appears to be for debugging purposes. The println statements and the associated variables contentHeight and oneThirdHeight are not used elsewhere and should be removed from the production code.

implementation(libs.androidx.glance)
implementation(libs.androidx.glance.appwidget)
implementation(libs.androidx.glance.material3)
debugImplementation("androidx.glance:glance-appwidget-preview:1.2.0-alpha01")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It's best practice to avoid hardcoding dependency versions in build scripts. Please define this dependency and its version in your gradle/libs.versions.toml file and reference it here from the version catalog. You can reuse the existing glance version reference since it matches.

For example, you could add androidx-glance-appwidget-preview = { module = "androidx.glance:glance-appwidget-preview", version.ref = "glance" } to your libs.versions.toml and then use debugImplementation(libs.androidx.glance.appwidget.preview) here.

val onPrimaryContainerColor = GlanceTheme.colors.onPrimaryContainer
val size = LocalSize.current
val albumArtSize = size.height - 32.dp
LocalSize.current
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

LocalSize.current is called here, but its value is not used. This line should be removed.

Additionally, with the removal of the text elements from this layout, the function parameters title, artist, and textColor for VeryThinWidgetLayout are now also unused and should be removed from the function signature to clean up the code. The call site at line 185 will need to be updated accordingly.

@ColbyCabrera
Copy link
Copy Markdown
Owner

Please do this app/build.gradle.kts
@@ -112,6 +113,7 @@ dependencies {
implementation(libs.androidx.glance)
implementation(libs.androidx.glance.appwidget)
implementation(libs.androidx.glance.material3)
debugImplementation("androidx.glance:glance-appwidget-preview:1.2.0-alpha01")
@gemini-code-assist gemini-code-assist bot 1 minute ago
medium

It's best practice to avoid hardcoding dependency versions in build scripts. Please define this dependency and its version in your gradle/libs.versions.toml file and reference it here from the version catalog. You can reuse the existing glance version reference since it matches.

For example, you could add androidx-glance-appwidget-preview = { module = "androidx.glance:glance-appwidget-preview", version.ref = "glance" } to your libs.versions.toml and then use debugImplementation(libs.androidx.glance.appwidget.preview) here.

@gemini-code-assist
Copy link
Copy Markdown

Thank you for your message! As an AI assistant, I'm unable to directly modify or commit changes to the pull request. My role is to provide feedback and suggestions.

To address the medium severity suggestion regarding hardcoded dependency versions, you'll need to apply the changes yourself. The best practice is to define the dependency and its version in your gradle/libs.versions.toml file and then reference it from there in app/build.gradle.kts.

Here's a reminder of the suggested changes:

  1. In gradle/libs.versions.toml, add the following under the [libraries] section (or [versions] if you prefer to define the version separately, but version.ref = "glance" is cleaner here):

    androidx-glance-appwidget-preview = { module = "androidx.glance:glance-appwidget-preview", version.ref = "glance" }
  2. In app/build.gradle.kts, change the line:

    debugImplementation("androidx.glance:glance-appwidget-preview:1.2.0-alpha01")

    to:

    debugImplementation(libs.androidx.glance.appwidget.preview)

This approach centralizes your dependency versions, making them easier to manage and update across your project. Please let me know if you have any other questions!

@google-labs-jules
Copy link
Copy Markdown
Author

Please do this app/build.gradle.kts
@@ -112,6 +113,7 @@ dependencies {
implementation(libs.androidx.glance)
implementation(libs.androidx.glance.appwidget)
implementation(libs.androidx.glance.material3)
debugImplementation("androidx.glance:glance-appwidget-preview:1.2.0-alpha01")
@gemini-code-assist gemini-code-assist bot 1 minute ago
medium

It's best practice to avoid hardcoding dependency versions in build scripts. Please define this dependency and its version in your gradle/libs.versions.toml file and reference it here from the version catalog. You can reuse the existing glance version reference since it matches.

For example, you could add androidx-glance-appwidget-preview = { module = "androidx.glance:glance-appwidget-preview", version.ref = "glance" } to your libs.versions.toml and then use debugImplementation(libs.androidx.glance.appwidget.preview) here.

Thank you for the feedback. I have updated the build script to use the version catalog for the Glance preview dependency.

google-labs-jules bot and others added 4 commits September 11, 2025 05:06
This change updates the build script to use the version catalog for the Glance preview dependency, following best practices.
This commit removes the `contentHeight` and `oneThirdHeight` variables from `PixelPlayGlanceWidget.kt`. These variables and their associated `println` statements, used for calculating and debugging component heights, are no longer utilized in the codebase.
…eviews' into feature/glance-widget-previews"

This reverts commit bae12cc, reversing
changes made to d27b13e.
@ColbyCabrera ColbyCabrera merged commit e0ce856 into master Sep 11, 2025
@ColbyCabrera ColbyCabrera deleted the feature/glance-widget-previews branch September 11, 2025 15:45
ColbyCabrera pushed a commit that referenced this pull request Dec 12, 2025
…b-actions

Add GitHub Actions workflow to build APK
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.

2 participants