Skip to content
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

[AND-316] Configuration options for the System Attachment Picker #5654

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

VelikovPetar
Copy link
Contributor

@VelikovPetar VelikovPetar commented Feb 25, 2025

🎯 Goal

Provide a way to customise the behaviour of the "System Attachments Picker". Initially, we are exposing a way to choose between picking single/multiple visual media attachment, and to choose the allowed visual media types - image/video/image_and_video.

Compose Usage

ChatTheme(
  useDefaultSystemMediaPicker = true,
  systemAttachmentsPickerConfig = SystemAttachmentsPickerConfig(
      visualMediaAllowMultiple = true,
      visualMediaType = VisualMediaType.IMAGE,
  )
) {
  MessagesScreen(...)
}

XML Usage

<io.getstream.chat.android.ui.feature.messages.composer.MessageComposerView
        android:id="@+id/messageComposerView"
        ....
        app:streamUiMessageComposerAttachmentsPickerSystemPickerEnabled="true"
        app:streamUiMessageComposerAttachmentsPickerSystemPickerVisualMediaType="image"
        app:streamUiMessageComposerAttachmentsPickerSystemPickerVisualMediaAllowMultiple="true"
        />

🛠 Implementation details

ui-common

  • Implement new VisualMediaType enum defining the possible combinations for picking visual media
  • Implement new SystemAttachmentsPickerConfig class holding the configuration options for the "System attachments picker"

compose

  • Add a new param on the ChatTheme - systemAttachmentsPickerConfig which is read if the useDefaultSystemMediaPicker is set to true
  • Add new AttachmentsPickerTabFactories.systemAttachmentsPickerTabFactories factory method accepting a SystemAttachmentsPickerConfig
  • Adjust the AttachmentsPickerSystemTabFactory to consider the visualMediaAllowMultiple and visualMediaType params when launching the visual media picker.
  • ⚠️ Deprecate the old AttachmentsPickerTabFactories.defaultFactoriesWithoutStoragePermissions methods in favour of AttachmentsPickerTabFactories.systemAttachmentsPickerTabFactories

ui-components

  • Add new systemMediaPickerVisualMediaAllowMultiple and systemMediaPickerVisualMediaType properties on the AttachmentsPickerDialogStyle to allow customisation. (note: Here we are not using the SystemAttachmentsPickerConfig model as currently all customisation options for both the regular and system attachment pickers and using the AttachmentsPickerDialogStyle)
  • Adjust the AttachmentsPickerSystemFragment to consider the visualMediaAllowMultiple and visualMediaType params when launching the visual media picker.

🎨 UI Changes

Example where:

  • allowMultiple = true
  • type = IMAGE
Compose XML
compose.mp4
xml.mp4

🧪 Testing

  1. Apply the given patch
  2. Open either XML or Compose samples
  3. Open a channel
  4. Open the attachments picker
  5. Select Images
  6. You should now see only images (no videos), and you should be able to select multiple attachments to add to the message
  7. Play around with the allowMultiple and type parameters to test out different scenarios
Patch for XML and Compose samples
Subject: [PATCH] [AND-316] Update CHANGELOG.md.
---
Index: stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/MessagesActivity.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/MessagesActivity.kt b/stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/MessagesActivity.kt
--- a/stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/MessagesActivity.kt	(revision d38d1306df461bef6eab4acdc5514075909f804b)
+++ b/stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/MessagesActivity.kt	(date 1740490853578)
@@ -92,6 +92,8 @@
 import io.getstream.chat.android.models.Channel
 import io.getstream.chat.android.models.ReactionSortingByFirstReactionAt
 import io.getstream.chat.android.models.ReactionSortingByLastReactionAt
+import io.getstream.chat.android.ui.common.permissions.SystemAttachmentsPickerConfig
+import io.getstream.chat.android.ui.common.permissions.VisualMediaType
 import io.getstream.chat.android.ui.common.state.messages.MessageMode
 import io.getstream.chat.android.ui.common.state.messages.Reply
 import io.getstream.chat.android.ui.common.state.messages.list.DeletedMessageVisibility
@@ -173,6 +175,11 @@
                 optionVisibility = MessageOptionItemVisibility(),
             ),
             ownMessageTheme = ownMessageTheme,
+            useDefaultSystemMediaPicker = true,
+            systemAttachmentsPickerConfig = SystemAttachmentsPickerConfig(
+                visualMediaAllowMultiple = true,
+                visualMediaType = VisualMediaType.IMAGE,
+            )
         ) {
             SetupContent()
         }
Index: stream-chat-android-ui-components-sample/src/main/res/layout/fragment_chat.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/stream-chat-android-ui-components-sample/src/main/res/layout/fragment_chat.xml b/stream-chat-android-ui-components-sample/src/main/res/layout/fragment_chat.xml
--- a/stream-chat-android-ui-components-sample/src/main/res/layout/fragment_chat.xml	(revision d38d1306df461bef6eab4acdc5514075909f804b)
+++ b/stream-chat-android-ui-components-sample/src/main/res/layout/fragment_chat.xml	(date 1740491171726)
@@ -52,6 +52,9 @@
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toBottomOf="@+id/messageListView"
+        app:streamUiMessageComposerAttachmentsPickerSystemPickerEnabled="true"
+        app:streamUiMessageComposerAttachmentsPickerSystemPickerVisualMediaType="image"
+        app:streamUiMessageComposerAttachmentsPickerSystemPickerVisualMediaAllowMultiple="true"
         />
 
 </androidx.constraintlayout.widget.ConstraintLayout>

Copy link
Contributor

github-actions bot commented Feb 25, 2025

SDK Size Comparison 📏

SDK Before After Difference Status
stream-chat-android-client 3.17 MB 3.17 MB 0.00 MB 🟢
stream-chat-android-offline 3.38 MB 3.38 MB 0.00 MB 🟢
stream-chat-android-ui-components 7.87 MB 7.87 MB 0.00 MB 🟢
stream-chat-android-compose 9.86 MB 9.87 MB 0.00 MB 🟢

private val mediaPickerContract = resolveMediaPickerMode(captureImageAllowed, captureVideoAllowed)
/** Returns whether file attachments are allowed. */
@Deprecated(message = "Use config.filesAllowed instead.", level = DeprecationLevel.WARNING)
public val filesAllowed: Boolean = config.filesAllowed
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are introduced to prevent a breaking change - the previous primary constructor:

AttachmentsPickerSystemTabFactory(
     public val filesAllowed: Boolean,
     public val mediaAllowed: Boolean,
     public val captureImageAllowed: Boolean,
     public val captureVideoAllowed: Boolean,
     public val pollAllowed: Boolean,
 )

Is now deprecated in favour of:

public class AttachmentsPickerSystemTabFactory(
     public val config: SystemAttachmentsPickerConfig,
 )

So the fields are now still public but deprecated, so they can be eventually deleted.

@VelikovPetar VelikovPetar marked this pull request as ready for review February 25, 2025 14:00
@VelikovPetar VelikovPetar requested a review from a team as a code owner February 25, 2025 14:00
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
25.9% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

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.

1 participant