Skip to content

Add ProgressStyle notification sample #296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alabiaga
Copy link
Member

Add the User Interface Progress Style sample that simulates a checkout order experience; tracking that order with ProgressStyle notifications.

Copy link

@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.

Hello @alabiaga, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request adds a new sample demonstrating the use of ProgressStyle notifications to simulate a checkout order experience. It includes a new module (live-updates) with the necessary code, resources, and configurations. The sample showcases how to track an order's progress using notifications with visual progress indicators.

Highlights

  • New Module: live-updates: A new module samples/user-interface/live-updates is added, containing the implementation for the ProgressStyle notification sample.
  • LiveUpdateActivity: Introduces LiveUpdateActivity which uses Compose to display a UI with a button that triggers the simulated checkout process and associated notifications.
  • SnackbarNotificationManager: Implements SnackbarNotificationManager to handle the creation and display of notifications with ProgressStyle to represent different stages of the order.
  • Gradle Updates: Updates app/build.gradle.kts to include the new live-updates module as a dependency and upgrades gradle/libs.versions.toml to update AGP version and add material3 dependency.

Changelog

Click here to see the changelog
  • app/build.gradle.kts
    • Updated compileSdk and targetSdk to 36.
    • Updated minSdk to 26.
    • Added implementation dependency for :samples:user-interface:live-updates.
  • app/src/main/java/com/example/platform/app/ApiSurface.kt
    • Added UserInterfaceLiveUpdatesApiSurface to define the API surface for the new sample.
    • Added UserInterfaceLiveUpdatesApiSurface to the API_SURFACES list.
  • app/src/main/java/com/example/platform/app/SampleDemo.kt
    • Imported LiveUpdateActivity.
    • Added ActivitySampleDemo for the live updates sample, including its name, description, documentation link, API surface, and content.
  • gradle/libs.versions.toml
    • Updated agp version from "8.8.1" to "8.9.1".
    • Added material3Android version and dependency.
    • Added compose plugin alias.
  • gradle/wrapper/gradle-wrapper.properties
    • Updated distributionUrl to gradle-8.11.1-bin.zip.
  • samples/user-interface/live-updates/build.gradle.kts
    • Created new build.gradle.kts file for the live-updates module, including plugins, android configuration, and dependencies.
  • samples/user-interface/live-updates/src/main/AndroidManifest.xml
    • Created new AndroidManifest.xml file for the live-updates module, declaring the LiveUpdateActivity and requesting the POST_NOTIFICATIONS permission.
  • samples/user-interface/live-updates/src/main/java/com/example/platform/ui/live_updates/LiveUpdateActivity.kt
    • Created new LiveUpdateActivity.kt file, implementing the UI using Compose, requesting notification permissions, and triggering the checkout simulation.
  • samples/user-interface/live-updates/src/main/java/com/example/platform/ui/live_updates/SnackbarNotificationManager.kt
    • Created new SnackbarNotificationManager.kt file, handling the creation and display of notifications with ProgressStyle to simulate order tracking.
  • samples/user-interface/live-updates/src/main/res/drawable/ic_launcher_background.xml
    • Created new ic_launcher_background.xml file.
  • samples/user-interface/live-updates/src/main/res/drawable/ic_launcher_foreground.xml
    • Created new ic_launcher_foreground.xml file.
  • samples/user-interface/live-updates/src/main/res/values/colors.xml
    • Created new colors.xml file.
  • samples/user-interface/live-updates/src/main/res/values/strings.xml
    • Created new strings.xml file, defining strings for the UI and notification messages.
  • samples/user-interface/live-updates/src/main/res/values/themes.xml
    • Created new themes.xml file, defining the theme for the live-updates module.
  • settings.gradle.kts
    • Included the new module ':samples:user-interface:live-updates'.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A progress bar's gentle climb,
A visual march through space and time,
From zero to done,
A task has begun,
Success in its linear rhyme.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@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 introduces a new UI sample demonstrating the use of ProgressStyle notifications for tracking an order. The code is well-structured and implements the feature as described. However, there are a few areas that could be improved for better clarity and maintainability.

Summary of Findings

  • SDK Version Check for Notification Channel: The createNotificationChannel method should be called only when the SDK version is greater than or equal to Android O to avoid issues on older devices.
  • Backward Compatibility for Notifications: Consider using NotificationCompat.Builder instead of Notification.Builder for backward compatibility to ensure that the notifications are displayed correctly on older devices.
  • Asynchronous Task Handling: Consider using CoroutineScope instead of Handler for posting delayed notifications to provide a more Kotlin-idiomatic way of handling asynchronous tasks and avoid potential memory leaks.

Merge Readiness

The pull request is almost ready for merging. However, it's recommended to address the identified issues, especially the SDK version check for notification channel creation, before merging. I am unable to directly approve this pull request, and other reviewers should review and approve this code before merging.

notificationManager = notifManager
val channel = NotificationChannel(CHANNEL_ID, CHANNEL_NAME, IMPORTANCE_DEFAULT)
appContext = context
notificationManager?.createNotificationChannel(channel)

Choose a reason for hiding this comment

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

high

The createNotificationChannel method should be called only when the SDK version is greater than or equal to Android O. Consider adding a version check to avoid issues on older devices.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            notificationManager?.createNotificationChannel(channel)
        }

Comment on lines +30 to +31
minSdk = 26
targetSdk = 36

Choose a reason for hiding this comment

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

medium

Consider using a variable for the minSdk and targetSdk versions to ensure consistency across the project. This can be defined in gradle/libs.versions.toml and referenced here.

.fillMaxSize()
.padding(10.dp, 100.dp),
) {
Text(stringResource( R.string.live_update_summary_text))

Choose a reason for hiding this comment

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

medium

Consider extracting the string resource being used here into the strings.xml file. This promotes better maintainability and localization.

Comment on lines +67 to +70
onCheckout()
scope.launch {
snackbarHostState.showSnackbar("Order placed")
}

Choose a reason for hiding this comment

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

medium

It might be better to move the snackbarHostState.showSnackbar call into the onCheckout function or a separate function called from onCheckout to keep the UI logic separate from the notification logic. This would improve the separation of concerns.

Comment on lines +190 to +193
var notificationBuilder = Notification.Builder(appContext, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setOngoing(true)
.setColorized(true)

Choose a reason for hiding this comment

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

medium

Consider using NotificationCompat.Builder instead of Notification.Builder for backward compatibility. This will ensure that the notifications are displayed correctly on older devices.

Comment on lines +221 to +225
for (state in OrderState.entries) {
val notification = state.buildNotification().build()
Handler(Looper.getMainLooper()).postDelayed({
notificationManager.notify(NOTIFICATION_ID, notification)
}, state.delay)

Choose a reason for hiding this comment

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

medium

Consider using CoroutineScope instead of Handler for posting delayed notifications. This would provide a more Kotlin-idiomatic way of handling asynchronous tasks and avoid potential memory leaks.

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