-
Notifications
You must be signed in to change notification settings - Fork 202
Catch exception when attempting to load launch a PickVisualMediaRequest with no applicable activities #155
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
base: main
Are you sure you want to change the base?
Conversation
… with no applicable activities
Summary of ChangesHello @devbridie, 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! This pull request significantly improves the application's stability by addressing a potential crash point related to the media picker. By moving the media picker launch mechanism into the ViewModel and wrapping it with comprehensive error handling, the application can now gracefully manage scenarios where no compatible media picking activity is available. This change ensures a more resilient user experience, preventing unexpected application termination and providing informative feedback to the user when issues arise. Highlights
Using Gemini Code AssistThe 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 by creating a comment using either
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 Limitations & Feedback Gemini Code Assist 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. 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. Footnotes
|
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
This pull request effectively handles a potential crash when launching the media picker if no suitable activity is found. The logic is correctly moved into the CreationViewModel
and wrapped in a try-catch
block, which is a good improvement for robustness and architecture. The related changes across the UI components are consistent and clean. I have a couple of suggestions to make the implementation even better by using a more specific exception type and improving encapsulation.
fun launchImageChooser(launcher: ManagedActivityResultLauncher<PickVisualMediaRequest, Uri?>) { | ||
try { | ||
launcher.launch(PickVisualMediaRequest(PickVisualMedia.ImageOnly)) | ||
} catch (exception: Exception) { |
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.
Catching a generic Exception
is too broad and can hide other unexpected issues. Since the goal is to handle the case where no media picker activity is available, it's better to catch the more specific android.content.ActivityNotFoundException
.
} catch (exception: Exception) { | |
} catch (exception: android.content.ActivityNotFoundException) { |
} | ||
} | ||
|
||
fun displayOpenImageChooserError() { |
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.
|
||
fun launchImageChooser(launcher: ManagedActivityResultLauncher<PickVisualMediaRequest, Uri?>) { | ||
try { | ||
launcher.launch(PickVisualMediaRequest(PickVisualMedia.ImageOnly)) |
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.
Generally we've been trying to avoid starting activities from the ViewModel as the ViewModel can outlive the Fragment/Composable. Is it possible to keep this in the Composable? Also why doesn't the device have a media picker 😄
Handles an uncaught exception when attempting to launch a media picker intent with no valid target activities installed on the device.