-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[Compose] Upgrade MLKit Analyzer Sample to use Compose #616
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @madebymozart, 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 upgrades the MLKit Analyzer Sample to use Jetpack Compose for the UI. This involves migrating the MainActivity
from an AppCompatActivity
to a ComponentActivity
and using Compose to define the UI. The layout files are removed, and new Compose UI elements are added to display the camera preview and QR code detection results. The Gradle dependencies are updated to include Compose dependencies, CameraX Viewfinder Compose dependencies, and newer versions of other libraries. The target and compile SDK versions are also updated.
Highlights
- Compose Migration: The UI is migrated from the traditional XML layout to Jetpack Compose, enabling a more declarative and modern UI development approach.
- Dependency Updates: The pull request updates several dependencies, including CameraX, MLKit, and core Kotlin libraries, ensuring the project uses the latest features and improvements.
- CameraX Viewfinder Integration: The CameraX Viewfinder Compose library is integrated to display the camera preview within the Compose UI.
- Permission Handling: The camera permission handling is updated to work with Compose, ensuring the app requests and handles camera permissions correctly.
- QR Code Detection: The QR code detection logic is integrated with the Compose UI, displaying the detected QR code content and bounding box.
Changelog
Click here to see the changelog
- CameraX-MLKit/app/build.gradle
-
- Upgraded
compileSdk
andtargetSdk
to 35.
- Upgraded
-
- Added the
org.jetbrains.kotlin.plugin.compose
plugin.
- Added the
-
- Updated
sourceCompatibility
andtargetCompatibility
to JavaVersion.VERSION_18.
- Updated
-
- Updated
jvmTarget
to '18'.
- Updated
-
- Enabled Compose in
buildFeatures
and setkotlinCompilerExtensionVersion
to "1.5.15".
- Enabled Compose in
-
- Added dependencies for CameraX Viewfinder Compose, Lifecycle Runtime KTX, Activity Compose, Compose BOM, Compose UI, Compose Material3, and Compose UI Tooling.
-
- Updated versions of core-ktx, appcompat, constraintlayout, camera-mlkit-vision, junit, and espresso-core.
-
- Updated CameraX versions to 1.4.2.
-
- Updated ML Kit barcode scanning version to 17.3.0.
-
- Added debugImplementation for Compose UI Tooling and UI Test Manifest.
-
- CameraX-MLKit/app/src/main/AndroidManifest.xml
-
- Removed the
android:theme
attribute from the application tag.
- Removed the
-
- CameraX-MLKit/app/src/main/java/com/example/camerax_mlkit/MainActivity.kt
-
- Updated copyright year to 2023.
-
- Migrated
MainActivity
fromAppCompatActivity
toComponentActivity
.
- Migrated
-
- Used Compose to define the UI.
-
- Implemented camera permission handling using Compose.
-
- Integrated CameraX Viewfinder to display the camera preview.
-
- Implemented QR code detection using ML Kit and displayed the results in the Compose UI.
-
- Added
MainScreen
,QrCodeText
, andCameraPreview
composable functions.
- Added
-
- Used
LifecycleCameraController
for camera control.
- Used
-
- Used
MlKitAnalyzer
for barcode scanning.
- Used
-
- Added logic to display QR code content and a bounding box.
-
- Added a resolution selector to throttle the analysis.
-
- Added error handling for camera initialization.
-
- CameraX-MLKit/app/src/main/java/com/example/camerax_mlkit/QrCodeDrawable.kt
-
- Made
qrCodeViewModel
a private val in theQrCodeDrawable
class.
- Made
-
- Removed the redundant assignment of
qrCodeViewModel
.
- Removed the redundant assignment of
-
- CameraX-MLKit/app/src/main/java/com/example/camerax_mlkit/QrCodeViewModel.kt
-
- Imported
androidx.core.net.toUri
.
- Imported
-
- Used
qrContent.toUri()
instead ofUri.parse(qrContent)
to create the URI for the browser intent.
- Used
-
- CameraX-MLKit/app/src/main/java/com/example/camerax_mlkit/ui/theme/Color.kt
-
- Added color definitions for Compose themes.
-
- CameraX-MLKit/app/src/main/java/com/example/camerax_mlkit/ui/theme/Theme.kt
-
- Defined Compose themes for the application.
-
- CameraX-MLKit/app/src/main/java/com/example/camerax_mlkit/ui/theme/Type.kt
-
- Defined typography styles for Compose.
-
- CameraX-MLKit/app/src/main/res/layout/activity_main.xml
-
- Removed the layout file as the UI is now defined in Compose.
-
- CameraX-MLKit/app/src/main/res/values/themes.xml
-
- Removed the original theme and added a new theme without the action bar.
-
- build.gradle
-
- Updated Gradle plugin versions to 8.10.0.
-
- Added the
org.jetbrains.kotlin.plugin.compose
plugin with version '2.0.21'.
- Added the
-
- gradle.properties
-
- Added
android.defaults.buildfeatures.buildconfig=true
andandroid.nonFinalResIds=false
.
- Added
-
- gradle/wrapper/gradle-wrapper.properties
-
- Updated Gradle distribution URL to gradle-8.11.1-bin.zip.
-
- gradlew
-
- Updated the shebang to
#!/bin/sh
.
- Updated the shebang to
-
- Updated copyright notice.
-
- Improved POSIX shell compliance.
-
- Improved argument handling.
-
- Added xargs availability check.
-
- gradlew.bat
-
- Minor updates to conditional statements.
-
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.
Compose now paints the screen,
No XML layouts are seen.
Kotlin's gentle hand,
A modern UI stand,
Where beauty and logic convene.
Footnotes
-
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. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The pull request upgrades the MLKit Analyzer Sample to use Compose, modernizing the UI and improving the project's structure. The changes include updating dependencies, migrating the UI to Compose, and adjusting the camera implementation. Overall, the changes seem well-structured and contribute positively to the project.
Summary of Findings
- Target SDK and Compile SDK versions: The target SDK and compile SDK versions have been updated to 35. Ensure that this update is compatible with the minimum SDK version and that all new APIs are properly handled for older devices.
- CameraX Viewfinder Dependencies: The addition of CameraX viewfinder compose dependencies is a good move for integrating with Compose. Verify that these dependencies are correctly implemented and that the viewfinder is properly displayed and functioning.
- Permissions Request: The permission request logic has been moved into the composable function. Ensure that the permission request is handled correctly and that the UI updates accordingly based on the permission status.
- Lifecycle Management: The use of
LocalLifecycleOwner.current
is appropriate for managing the camera lifecycle within Compose. Ensure that the camera resources are properly released when the composable is disposed of. - Error Handling: The addition of camera error handling is a good practice. Ensure that the error message is displayed appropriately and that the user is informed about the issue.
Merge Readiness
The pull request introduces significant improvements by migrating the UI to Compose. While the changes appear to be well-structured, it's crucial to ensure that the updated dependencies and new APIs are thoroughly tested across different devices and Android versions. The permission handling and error reporting mechanisms should also be verified for robustness. I am unable to approve this pull request, and recommend that others review and approve this code before merging. I recommend that the pull request not be merged until the above points are addressed.
Fixed here: android/platform-samples#295 |
No description provided.