-
Notifications
You must be signed in to change notification settings - Fork 109
Feat: enable sharing images with other apps #151
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 @chikoski, 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 enables sharing media files attached to chat messages with other apps using copy & paste and drag & drop. It adds a FileProvider to handle URI sharing, modifies the ChatRepository to save attached media items and handle URI permissions, and updates the UI to support drag and drop and context menus for copying media. The changes primarily focus on enabling the sharing functionality and updating the UI components to support it.
Highlights
- FileProvider Integration: Adds a FileProvider to AndroidManifest.xml and a shared_paths.xml file to define URI sharing paths, enabling secure sharing of files with other apps.
- Media Sharing: Enables sharing of media files (images and videos) attached to chat messages with other apps via copy & paste and drag & drop.
- URI Permission Handling: Modifies ChatRepository to handle URI permissions for shared media, ensuring that other apps can access the media files.
- UI Updates: Updates the ChatScreen UI to include context menus for copying media and drag and drop support for media items.
Changelog
Click here to see the changelog
- app/src/main/AndroidManifest.xml
- Added a FileProvider to enable sharing files with other apps.
- app/src/main/java/com/google/android/samples/socialite/repository/ChatRepository.kt
- Added functions to save attached media items and handle URI permissions.
- Modified the saveAttachedMediaItem function to first try taking persistable URI permission, and if that fails, save the media item to the app's files directory.
- Added logic to determine the file extension based on the MIME type.
- Refactored the chatbot enable logic to use strict boolean comparison.
- app/src/main/java/com/google/android/samples/socialite/ui/chat/ChatMessage.kt
- Added properties to check if the attached content is video or image.
- app/src/main/java/com/google/android/samples/socialite/ui/chat/ChatScreen.kt
- Removed unused imports and extracted scrollWithKeyboards to component package.
- Removed MessageBubble and VideoMessagePreview composables, moving their logic to MessageBubble component.
- app/src/main/java/com/google/android/samples/socialite/ui/chat/ChatViewModel.kt
- Added logic to MediaItem data class to determine file extension based on MIME type.
- app/src/main/java/com/google/android/samples/socialite/ui/chat/component/ClipData.kt
- Created a new composable function to create ClipData from ChatMessage for sharing.
- app/src/main/java/com/google/android/samples/socialite/ui/chat/component/ContextMenuArea.kt
- Created a new composable function to create a context menu for chat messages.
- app/src/main/java/com/google/android/samples/socialite/ui/chat/component/Draggable.kt
- Created a new modifier function to make media items draggable.
- app/src/main/java/com/google/android/samples/socialite/ui/chat/component/MessageBubble.kt
- Created a new composable function to display message bubbles with media attachments and context menu options.
- app/src/main/java/com/google/android/samples/socialite/ui/chat/component/Scroll.kt
- Created a new modifier function to handle scrolling with keyboard.
- app/src/main/java/com/google/android/samples/socialite/ui/components/ClipData.kt
- Created a utility function to create ClipData from a URI.
- app/src/main/java/com/google/android/samples/socialite/ui/components/ContextMenuArea.kt
- Created a composable function to display a context menu on right-click or long-press.
- app/src/main/java/com/google/android/samples/socialite/ui/components/ContextMenuItem.kt
- Created a composable function to remember context menu items for copying media items.
- app/src/main/java/com/google/android/samples/socialite/ui/home/timeline/component/ClipData.kt
- Created a new composable function to create ClipData from TimelineMediaItem for sharing.
- app/src/main/java/com/google/android/samples/socialite/ui/home/timeline/component/ContextMenuArea.kt
- Created a new composable function to create a context menu for timeline media items.
- app/src/main/java/com/google/android/samples/socialite/ui/home/timeline/component/Draggable.kt
- Created a new modifier function to make timeline media items draggable.
- app/src/main/java/com/google/android/samples/socialite/ui/home/timeline/component/TimelineGrid.kt
- Removed TimelineGridItem composable, moving its logic to TimelineGridItem component.
- app/src/main/java/com/google/android/samples/socialite/ui/home/timeline/component/TimelineGridItem.kt
- Created a new composable function to display timeline grid items with media attachments and context menu options.
- app/src/main/java/com/google/android/samples/socialite/ui/home/timeline/component/TimelineVerticalPager.kt
- Added combinedClickable modifier to TimelinePage to handle click and long click events.
- Refactored TimelineVerticalPager to separate UI logic into TimelinePage and MediaItem composables.
- app/src/main/java/com/google/android/samples/socialite/ui/photopicker/PhotoPickerViewModel.kt
- Added permission request for persistable URI access.
- app/src/main/res/values/strings.xml
- Added a string resource for the 'Copy' action.
- app/src/main/res/xml/shared_paths.xml
- Created a new XML file to define shared paths for the FileProvider.
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 file provider's grace,
Shares media across the space,
Drag and drop's delight,
Images take flight,
In app-sharing's embrace.
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
This pull request introduces a valuable feature: enabling users to share media files from chat messages with other applications through copy & paste and drag & drop. The implementation involves adding a FileProvider
, refining media saving logic in ChatRepository
, and significant UI refactoring for better modularity by introducing new components for context menus, drag-and-drop, and message bubbles.
Overall, the changes are well-structured and the new functionalities are thoughtfully implemented. The refactoring of UI components into their own files greatly improves code organization. There are a couple of potential null pointer issues that need addressing, as detailed in the comments.
Summary of Findings
- Potential NullPointerException in ChatRepository: In
ChatRepository.trySaveAttachedMediaItem
,createdUri!!
could lead to a NullPointerException ifappContext.contentResolver.openInputStream
returns null, ascreatedUri
would remain null. - Potential NullPointerException in ClipData utility: In
ui.components.ClipData.kt
,mediaItem.path!!
might cause a crash if the URI's path is null, which can happen for certain URI schemes. - Copyright Year: Many new files have the copyright year set to 2025. This should be updated to the current year (2023 or 2024 depending on when the work was done). (Severity: low, not commented inline)
- Modifier Usage: In
app/src/main/java/com/google/android/samples/socialite/ui/chat/component/MessageBubble.kt
(line 165),Modifier.Companion.size
is used. The preferred way isModifier.size
. (Severity: low, not commented inline) - Debug Logging: A
Log.d
statement is present inapp/src/main/java/com/google/android/samples/socialite/ui/components/ContextMenuArea.kt
. Consider removing this for release builds or using a logging library that handles build configurations. (Severity: low, not commented inline)
Merge Readiness
The pull request is a significant step forward in functionality. However, there are a couple of issues, including one high-severity potential NullPointerException
, that should be addressed before merging. Once these are resolved, the PR should be in good shape. As an AI, I am not authorized to approve pull requests; please ensure other reviewers approve these changes before merging.
This pull request enables sharing the media files attached to the chat messages with other apps by the following means:
Note: the media files attached from the chat bot can NOT be shared with other apps right now.