-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PBE-5514] Pick attachment files without the need for permissions (#5380
) * Add an option in compose to pick files without the need for read media permissions. * Finalize implementation of XML, change to linear layout instead of grid * Spotless and API dump * Fix detekt, add doc (wip) and fix style issues * Long parameter list fix * Spotless * Fix detekt style issues. * Fix detekt style issues. * Spotless * Add parameters to a new line * fix spotless * Spotless and ApiDump * (compose): change default value to false * (xml): rename to useDefaultSystemMediaPicker * clean up * clean up * align xml with compose names * move clickable the content, not the card * improve docs * spotless, api dump --------- Co-authored-by: kanat <[email protected]>
- Loading branch information
1 parent
70da8ba
commit edf3ba9
Showing
20 changed files
with
1,158 additions
and
53 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
docusaurus/docs/Android/ui/guides/pick-files-without-permissions.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
|
||
# System Media Picker | ||
|
||
Sometimes its not desirable for an app to have the `READ_MEDIA_IMAGES` and `READ_MEDIA_VIDEO` permissions. | ||
In this guide, we will explain how to set up the new `useDefaultSystemMediaPicker` parameter in both `ChatTheme` and `ChatUI`, why it is important, and how to remove permissions from the `AndroidManifest.xml` using `tools:node="remove"`. | ||
|
||
### The importance of System Media Picker | ||
|
||
The `useDefaultSystemMediaPicker` parameter allows you to use the system's default media picker instead of the custom media picker provided by the library. This can be beneficial for several reasons: | ||
- **Consistency**: Provides a consistent user experience by using the familiar system media picker. | ||
- **Permissions**: Reduces the need for additional permissions, as the system media picker handles permissions internally. | ||
- **Simplicity**: Simplifies the implementation by leveraging the built-in functionality of the system media picker. | ||
|
||
### Setting Up System Media Picker | ||
|
||
#### In Compose UI | ||
|
||
To enable the system media picker in `ChatTheme`, set the `useDefaultSystemMediaPicker` parameter to `true` when initializing the theme. | ||
|
||
```kotlin | ||
ChatTheme( | ||
useDefaultSystemMediaPicker = true | ||
) { | ||
// Your composable content | ||
} | ||
``` | ||
|
||
#### In XML-based UI | ||
|
||
There are two options for enabling usage of the system media picker in XML-based UI: `XML attributes` and `StyleTransformer`. | ||
|
||
Let's start with the `XML Attributes` option. | ||
You can enable the system media picker by setting the `streamUiMessageComposerAttachmentsPickerSystemPickerEnabled` attribute to `true` in the `MessageComposerView` XML layout. | ||
|
||
```xml | ||
<io.getstream.chat.android.ui.feature.messages.composer.MessageComposerView | ||
android:id="@+id/messageComposerView" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
app:streamUiMessageComposerAttachmentsPickerSystemPickerEnabled="true" | ||
/> | ||
``` | ||
|
||
You can also enable the system media picker using the `StyleTransformer` as shown below. | ||
|
||
```kotlin | ||
// Set the property directly in the AttachmentsPickerDialogStyle | ||
TransformStyle.attachmentsPickerStyleTransformer = StyleTransformer { defaultStyle -> | ||
defaultStyle.copy( | ||
useDefaultSystemMediaPicker = true, | ||
) | ||
} | ||
|
||
// Or set the property in the MessageComposerStyle | ||
TransformStyle.messageComposerStyleTransformer = StyleTransformer { defaultStyle -> | ||
defaultStyle.copy( | ||
attachmentsPickerDialogStyle = defaultStyle.attachmentsPickerDialogStyle.copy( | ||
useDefaultSystemMediaPicker = true, | ||
), | ||
) | ||
} | ||
``` | ||
|
||
Please be advised that setting `useDefaultSystemMediaPicker` in `MessageComposerStyle` will override the value set in `AttachmentsPickerDialogStyle`. | ||
|
||
### Removing Permissions from your Project | ||
|
||
Let's remove the permissions from the `AndroidManifest.xml`. | ||
|
||
When using the system media picker, you can remove unnecessary permissions from your `AndroidManifest.xml` to streamline your app's permission requests. | ||
Use the `tools:node="remove"` attribute to remove permissions. | ||
|
||
```xml | ||
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" tools:node="remove" /> | ||
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" tools:node="remove" /> | ||
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" tools:node="remove" /> | ||
``` | ||
|
||
By following these steps you can remove unnecessary permissions from your `AndroidManifest.xml`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.