Skip to content

Commit 2a8a575

Browse files
JcMinarroandremion
andauthored
Feature/refactor attachments factories (#5908)
* Refactor LinkAttachmentFactory * Refactor GiphyAttachmentFactory * Refactor MediaAttachmentFactory * Fix kdocs * Fix Checkstyle * Update CHANGELOG.md * Update LinkAttachmentContent * Fix PR Feedback --------- Co-authored-by: André Mion <andremion@gmail.com>
1 parent 1775e4d commit 2a8a575

File tree

15 files changed

+574
-73
lines changed

15 files changed

+574
-73
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@
8888
- Introduce `checkIconBackgroundColor`, `checkIconTintColor`, and `contentColor` to `AttachmentPickerTheme`. [#5903](https://github.com/GetStream/stream-chat-android/pull/5903)
8989

9090
### ⚠️ Changed
91+
- Deprecate `StreamAttachmentFactories.defaultFactories()` in favor of `StreamAttachmentFactories.defaults()`. [#5908](https://github.com/GetStream/stream-chat-android/pull/5908)
92+
- Deprecate `GiphyAttachmentContent` in favor of `GiphyAttachmentContent` with the `onItemClick` lambda parameter that accepts a `GiphyAttachmentClickData`. [#5908](https://github.com/GetStream/stream-chat-android/pull/5908)
93+
- Deprecate `LinkAttachmentContent` in favor of `LinkAttachmentContent` with the `onItemClick` lambda parameter that accepts a `LinkAttachmentClickData`. [#5908](https://github.com/GetStream/stream-chat-android/pull/5908)
94+
- Deprecate `MediaAttachmentContent` in favor of `MediaAttachmentContent` with the `onItemClick` lambda parameter that accepts a `MediaAttachmentClickData`. [#5908](https://github.com/GetStream/stream-chat-android/pull/5908)
95+
- Deprecate `GiphyAttachmentFactory` constructor that accepts `onContentItemClick` in favor of the one that accepts `onItemClick` lambda parameter that accepts a `GiphyAttachmentClickData`. [#5908](https://github.com/GetStream/stream-chat-android/pull/5908)
96+
- Deprecate `LinkAttachmentFactory` constructor that accepts `onContentItemClick` in favor of the one that accepts `onItemClick` lambda parameter that accepts a `LinkAttachmentClickData`. [#5908](https://github.com/GetStream/stream-chat-android/pull/5908)
97+
- Deprecate `MediaAttachmentFactory` constructor that accepts `onContentItemClick` in favor of the one that accepts `onItemClick` lambda parameter that accepts a `MediaAttachmentClickData`. [#5908](https://github.com/GetStream/stream-chat-android/pull/5908)
98+
-
9199

92100
### ❌ Removed
93101

stream-chat-android-compose/api/stream-chat-android-compose.api

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,8 @@ public final class io/getstream/chat/android/compose/ui/attachments/StreamAttach
456456
public final fun defaultFactories (Lkotlin/jvm/functions/Function0;ILio/getstream/chat/android/ui/common/utils/GiphyInfoType;Lio/getstream/chat/android/ui/common/utils/GiphySizingMode;Landroidx/compose/ui/layout/ContentScale;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function8;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Ljava/util/List;)Ljava/util/List;
457457
public static synthetic fun defaultFactories$default (Lio/getstream/chat/android/compose/ui/attachments/StreamAttachmentFactories;Lkotlin/jvm/functions/Function0;ILio/getstream/chat/android/ui/common/utils/GiphyInfoType;Lio/getstream/chat/android/ui/common/utils/GiphySizingMode;Landroidx/compose/ui/layout/ContentScale;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function8;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Ljava/util/List;ILjava/lang/Object;)Ljava/util/List;
458458
public final fun defaultQuotedFactories ()Ljava/util/List;
459+
public final fun defaults (Lkotlin/jvm/functions/Function0;ILio/getstream/chat/android/ui/common/utils/GiphyInfoType;Lio/getstream/chat/android/ui/common/utils/GiphySizingMode;Landroidx/compose/ui/layout/ContentScale;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Ljava/util/List;)Ljava/util/List;
460+
public static synthetic fun defaults$default (Lio/getstream/chat/android/compose/ui/attachments/StreamAttachmentFactories;Lkotlin/jvm/functions/Function0;ILio/getstream/chat/android/ui/common/utils/GiphyInfoType;Lio/getstream/chat/android/ui/common/utils/GiphySizingMode;Landroidx/compose/ui/layout/ContentScale;ZLkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Ljava/util/List;ILjava/lang/Object;)Ljava/util/List;
459461
}
460462

461463
public final class io/getstream/chat/android/compose/ui/attachments/content/AudioRecordAttachmentContentKt {
@@ -532,8 +534,10 @@ public final class io/getstream/chat/android/compose/ui/attachments/content/Comp
532534
public final class io/getstream/chat/android/compose/ui/attachments/content/ComposableSingletons$MediaAttachmentContentKt {
533535
public static final field INSTANCE Lio/getstream/chat/android/compose/ui/attachments/content/ComposableSingletons$MediaAttachmentContentKt;
534536
public static field lambda-1 Lkotlin/jvm/functions/Function3;
537+
public static field lambda-2 Lkotlin/jvm/functions/Function3;
535538
public fun <init> ()V
536539
public final fun getLambda-1$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function3;
540+
public final fun getLambda-2$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function3;
537541
}
538542

539543
public final class io/getstream/chat/android/compose/ui/attachments/content/ComposableSingletons$MediaAttachmentPreviewContentKt {
@@ -584,19 +588,75 @@ public final class io/getstream/chat/android/compose/ui/attachments/content/File
584588
public static final fun FileUploadItem (Lio/getstream/chat/android/models/Attachment;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V
585589
}
586590

591+
public final class io/getstream/chat/android/compose/ui/attachments/content/GiphyAttachmentClickData {
592+
public static final field $stable I
593+
public final fun component1 ()Landroid/content/Context;
594+
public final fun component2 ()Ljava/lang/String;
595+
public final fun component3 ()Lio/getstream/chat/android/models/Attachment;
596+
public final fun component4 ()Lio/getstream/chat/android/models/Message;
597+
public fun equals (Ljava/lang/Object;)Z
598+
public final fun getAttachment ()Lio/getstream/chat/android/models/Attachment;
599+
public final fun getContext ()Landroid/content/Context;
600+
public final fun getMessage ()Lio/getstream/chat/android/models/Message;
601+
public final fun getUrl ()Ljava/lang/String;
602+
public fun hashCode ()I
603+
public fun toString ()Ljava/lang/String;
604+
}
605+
587606
public final class io/getstream/chat/android/compose/ui/attachments/content/GiphyAttachmentContentKt {
607+
public static final fun GiphyAttachmentContent (Lio/getstream/chat/android/compose/state/messages/attachments/AttachmentState;Landroidx/compose/ui/Modifier;Lio/getstream/chat/android/ui/common/utils/GiphyInfoType;Lio/getstream/chat/android/ui/common/utils/GiphySizingMode;Landroidx/compose/ui/layout/ContentScale;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;II)V
588608
public static final fun GiphyAttachmentContent (Lio/getstream/chat/android/compose/state/messages/attachments/AttachmentState;Landroidx/compose/ui/Modifier;Lio/getstream/chat/android/ui/common/utils/GiphyInfoType;Lio/getstream/chat/android/ui/common/utils/GiphySizingMode;Landroidx/compose/ui/layout/ContentScale;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V
589609
}
590610

591611
public final class io/getstream/chat/android/compose/ui/attachments/content/ImageAttachmentPreviewContentKt {
592612
public static final fun ImageAttachmentPreviewContent (Ljava/util/List;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V
593613
}
594614

615+
public final class io/getstream/chat/android/compose/ui/attachments/content/LinkAttachmentClickData {
616+
public static final field $stable I
617+
public final fun component1 ()Landroid/content/Context;
618+
public final fun component2 ()Ljava/lang/String;
619+
public final fun component3 ()Lio/getstream/chat/android/models/Attachment;
620+
public final fun component4 ()Lio/getstream/chat/android/models/Message;
621+
public fun equals (Ljava/lang/Object;)Z
622+
public final fun getAttachment ()Lio/getstream/chat/android/models/Attachment;
623+
public final fun getContext ()Landroid/content/Context;
624+
public final fun getMessage ()Lio/getstream/chat/android/models/Message;
625+
public final fun getUrl ()Ljava/lang/String;
626+
public fun hashCode ()I
627+
public fun toString ()Ljava/lang/String;
628+
}
629+
595630
public final class io/getstream/chat/android/compose/ui/attachments/content/LinkAttachmentContentKt {
631+
public static final fun LinkAttachmentContent (Lio/getstream/chat/android/compose/state/messages/attachments/AttachmentState;ILandroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;II)V
596632
public static final fun LinkAttachmentContent (Lio/getstream/chat/android/compose/state/messages/attachments/AttachmentState;ILandroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V
597633
}
598634

635+
public final class io/getstream/chat/android/compose/ui/attachments/content/MediaAttachmentClickData {
636+
public static final field $stable I
637+
public final fun component1 ()Landroidx/activity/compose/ManagedActivityResultLauncher;
638+
public final fun component2 ()Lio/getstream/chat/android/models/Message;
639+
public final fun component3 ()I
640+
public final fun component4 ()Z
641+
public final fun component5 ()Lio/getstream/chat/android/ui/common/helper/DownloadAttachmentUriGenerator;
642+
public final fun component6 ()Lio/getstream/chat/android/ui/common/helper/DownloadRequestInterceptor;
643+
public final fun component7 ()Lio/getstream/chat/android/ui/common/images/resizing/StreamCdnImageResizing;
644+
public final fun component8 ()Z
645+
public fun equals (Ljava/lang/Object;)Z
646+
public final fun getAttachmentPosition ()I
647+
public final fun getDownloadAttachmentUriGenerator ()Lio/getstream/chat/android/ui/common/helper/DownloadAttachmentUriGenerator;
648+
public final fun getDownloadRequestInterceptor ()Lio/getstream/chat/android/ui/common/helper/DownloadRequestInterceptor;
649+
public final fun getMediaGalleryPreviewLauncher ()Landroidx/activity/compose/ManagedActivityResultLauncher;
650+
public final fun getMessage ()Lio/getstream/chat/android/models/Message;
651+
public final fun getSkipEnrichUrl ()Z
652+
public final fun getStreamCdnImageResizing ()Lio/getstream/chat/android/ui/common/images/resizing/StreamCdnImageResizing;
653+
public final fun getVideoThumbnailsEnabled ()Z
654+
public fun hashCode ()I
655+
public fun toString ()Ljava/lang/String;
656+
}
657+
599658
public final class io/getstream/chat/android/compose/ui/attachments/content/MediaAttachmentContentKt {
659+
public static final fun MediaAttachmentContent (Lio/getstream/chat/android/compose/state/messages/attachments/AttachmentState;Landroidx/compose/ui/Modifier;IZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;II)V
600660
public static final fun MediaAttachmentContent (Lio/getstream/chat/android/compose/state/messages/attachments/AttachmentState;Landroidx/compose/ui/Modifier;IZLkotlin/jvm/functions/Function8;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;II)V
601661
}
602662

@@ -637,9 +697,13 @@ public final class io/getstream/chat/android/compose/ui/attachments/factory/Comp
637697
public static final field INSTANCE Lio/getstream/chat/android/compose/ui/attachments/factory/ComposableSingletons$MediaAttachmentFactoryKt;
638698
public static field lambda-1 Lkotlin/jvm/functions/Function3;
639699
public static field lambda-2 Lkotlin/jvm/functions/Function3;
700+
public static field lambda-3 Lkotlin/jvm/functions/Function3;
701+
public static field lambda-4 Lkotlin/jvm/functions/Function3;
640702
public fun <init> ()V
641703
public final fun getLambda-1$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function3;
642704
public final fun getLambda-2$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function3;
705+
public final fun getLambda-3$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function3;
706+
public final fun getLambda-4$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function3;
643707
}
644708

645709
public final class io/getstream/chat/android/compose/ui/attachments/factory/ComposableSingletons$QuotedAttachmentFactoryKt {
@@ -666,19 +730,25 @@ public final class io/getstream/chat/android/compose/ui/attachments/factory/File
666730
public final class io/getstream/chat/android/compose/ui/attachments/factory/GiphyAttachmentFactory : io/getstream/chat/android/compose/ui/attachments/AttachmentFactory {
667731
public static final field $stable I
668732
public fun <init> ()V
733+
public fun <init> (Lio/getstream/chat/android/ui/common/utils/GiphyInfoType;Lio/getstream/chat/android/ui/common/utils/GiphySizingMode;Landroidx/compose/ui/layout/ContentScale;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V
734+
public synthetic fun <init> (Lio/getstream/chat/android/ui/common/utils/GiphyInfoType;Lio/getstream/chat/android/ui/common/utils/GiphySizingMode;Landroidx/compose/ui/layout/ContentScale;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
669735
public fun <init> (Lio/getstream/chat/android/ui/common/utils/GiphyInfoType;Lio/getstream/chat/android/ui/common/utils/GiphySizingMode;Landroidx/compose/ui/layout/ContentScale;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)V
670736
public synthetic fun <init> (Lio/getstream/chat/android/ui/common/utils/GiphyInfoType;Lio/getstream/chat/android/ui/common/utils/GiphySizingMode;Landroidx/compose/ui/layout/ContentScale;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
671737
}
672738

673739
public final class io/getstream/chat/android/compose/ui/attachments/factory/LinkAttachmentFactory : io/getstream/chat/android/compose/ui/attachments/AttachmentFactory {
674740
public static final field $stable I
741+
public fun <init> (ILkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V
742+
public synthetic fun <init> (ILkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
675743
public fun <init> (ILkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)V
676744
public synthetic fun <init> (ILkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
677745
}
678746

679747
public final class io/getstream/chat/android/compose/ui/attachments/factory/MediaAttachmentFactory : io/getstream/chat/android/compose/ui/attachments/AttachmentFactory {
680748
public static final field $stable I
681749
public fun <init> ()V
750+
public fun <init> (IZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;)V
751+
public synthetic fun <init> (IZLkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
682752
public fun <init> (IZLkotlin/jvm/functions/Function8;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;)V
683753
public synthetic fun <init> (IZLkotlin/jvm/functions/Function8;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
684754
}

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/StreamAttachmentFactories.kt

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import androidx.compose.ui.layout.ContentScale
2323
import androidx.core.net.toUri
2424
import io.getstream.chat.android.client.ChatClient
2525
import io.getstream.chat.android.compose.state.mediagallerypreview.MediaGalleryPreviewResult
26+
import io.getstream.chat.android.compose.ui.attachments.content.GiphyAttachmentClickData
27+
import io.getstream.chat.android.compose.ui.attachments.content.LinkAttachmentClickData
28+
import io.getstream.chat.android.compose.ui.attachments.content.MediaAttachmentClickData
2629
import io.getstream.chat.android.compose.ui.attachments.content.onFileAttachmentContentItemClick
2730
import io.getstream.chat.android.compose.ui.attachments.content.onFileUploadContentItemClick
2831
import io.getstream.chat.android.compose.ui.attachments.content.onGiphyAttachmentContentClick
@@ -85,6 +88,11 @@ public object StreamAttachmentFactories {
8588
*
8689
* @return A [List] of various [AttachmentFactory] instances that provide different attachments support.
8790
*/
91+
@Deprecated(
92+
message = "Use defaults() method instead.",
93+
replaceWith = ReplaceWith("defaults(...)"),
94+
level = DeprecationLevel.WARNING,
95+
)
8896
public fun defaultFactories(
8997
getChatClient: () -> ChatClient = { ChatClient.instance() },
9098
linkDescriptionMaxLines: Int = DEFAULT_LINK_DESCRIPTION_MAX_LINES,
@@ -146,6 +154,73 @@ public object StreamAttachmentFactories {
146154
UnsupportedAttachmentFactory,
147155
).filterNot { skipTypes.contains(it.type) }
148156

157+
public fun defaults(
158+
getChatClient: () -> ChatClient = { ChatClient.instance() },
159+
linkDescriptionMaxLines: Int = DEFAULT_LINK_DESCRIPTION_MAX_LINES,
160+
giphyInfoType: GiphyInfoType = GiphyInfoType.ORIGINAL,
161+
giphySizingMode: GiphySizingMode = GiphySizingMode.ADAPTIVE,
162+
contentScale: ContentScale = ContentScale.Crop,
163+
skipEnrichUrl: Boolean = false,
164+
onUploadContentItemClick: (
165+
Attachment,
166+
List<AttachmentPreviewHandler>,
167+
) -> Unit = ::onFileUploadContentItemClick,
168+
onLinkContentItemClick: (LinkAttachmentClickData) -> Unit = {
169+
onLinkAttachmentContentClick(it.context, it.url)
170+
},
171+
onGiphyContentItemClick: (GiphyAttachmentClickData) -> Unit = {
172+
onGiphyAttachmentContentClick(it.context, it.url)
173+
},
174+
onMediaContentItemClick: (MediaAttachmentClickData) -> Unit = {
175+
onMediaAttachmentContentItemClick(
176+
it.mediaGalleryPreviewLauncher,
177+
it.message,
178+
it.attachmentPosition,
179+
it.videoThumbnailsEnabled,
180+
it.downloadAttachmentUriGenerator,
181+
it.downloadRequestInterceptor,
182+
it.streamCdnImageResizing,
183+
it.skipEnrichUrl,
184+
)
185+
},
186+
showFileSize: (Attachment) -> Boolean = { true },
187+
onFileContentItemClick: (
188+
previewHandlers: List<AttachmentPreviewHandler>,
189+
attachment: Attachment,
190+
) -> Unit = ::onFileAttachmentContentItemClick,
191+
skipTypes: List<AttachmentFactory.Type> = emptyList(),
192+
): List<AttachmentFactory> = listOf(
193+
UploadAttachmentFactory(
194+
onContentItemClick = onUploadContentItemClick,
195+
),
196+
AudioRecordAttachmentFactory(
197+
viewModelFactory = AudioPlayerViewModelFactory(
198+
getAudioPlayer = { getChatClient().audioPlayer },
199+
getRecordingUri = { it.assetUrl ?: it.upload?.toUri()?.toString() },
200+
),
201+
getCurrentUserId = { getChatClient().getCurrentOrStoredUserId() },
202+
),
203+
LinkAttachmentFactory(
204+
linkDescriptionMaxLines = linkDescriptionMaxLines,
205+
onItemClick = onLinkContentItemClick,
206+
),
207+
GiphyAttachmentFactory(
208+
giphyInfoType = giphyInfoType,
209+
giphySizingMode = giphySizingMode,
210+
contentScale = contentScale,
211+
onItemClick = onGiphyContentItemClick,
212+
),
213+
MediaAttachmentFactory(
214+
skipEnrichUrl = skipEnrichUrl,
215+
onContentItemClick = onMediaContentItemClick,
216+
),
217+
FileAttachmentFactory(
218+
showFileSize = showFileSize,
219+
onContentItemClick = onFileContentItemClick,
220+
),
221+
UnsupportedAttachmentFactory,
222+
).filterNot { skipTypes.contains(it.type) }
223+
149224
/**
150225
* Default quoted attachment factories we provide, which can transform image, file and link attachments.
151226
*

0 commit comments

Comments
 (0)