Skip to content

Commit f9b0c6c

Browse files
committed
- Updated applications to SDK 5.1.0
1 parent d4c6f40 commit f9b0c6c

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed

samplejava/src/main/java/com/example/chattutorial/ChannelActivity2.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
6161
MessageInputViewModel messageInputViewModel = provider.get(MessageInputViewModel.class);
6262

6363
// Set view factory manager for Imgur attachments
64-
ImgurAttachmentViewFactory imgurAttachmentViewFactory = new ImgurAttachmentViewFactory();
64+
ImgurAttachmentFactory imgurAttachmentFactory = new ImgurAttachmentFactory();
6565

66-
List<ImgurAttachmentViewFactory> imgurAttachmentViewFactories = new ArrayList<ImgurAttachmentViewFactory>();
67-
imgurAttachmentViewFactories.add(imgurAttachmentViewFactory);
66+
List<ImgurAttachmentFactory> imgurAttachmentViewFactories = new ArrayList<ImgurAttachmentFactory>();
67+
imgurAttachmentViewFactories.add(imgurAttachmentFactory);
6868

6969
AttachmentFactoryManager attachmentFactoryManager = new AttachmentFactoryManager(imgurAttachmentViewFactories);
7070
binding.messageListView.setAttachmentFactoryManager(attachmentFactoryManager);

samplejava/src/main/java/com/example/chattutorial/ChannelActivity3.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.content.Context;
44
import android.content.Intent;
55
import android.os.Bundle;
6-
import android.text.TextUtils;
76
import android.widget.TextView;
87

98
import androidx.activity.OnBackPressedCallback;
@@ -63,10 +62,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
6362
MessageInputViewModel messageInputViewModel = provider.get(MessageInputViewModel.class);
6463

6564
// Set view factory manager for Imgur attachments
66-
ImgurAttachmentViewFactory imgurAttachmentViewFactory = new ImgurAttachmentViewFactory();
65+
ImgurAttachmentFactory imgurAttachmentFactory = new ImgurAttachmentFactory();
6766

68-
List<ImgurAttachmentViewFactory> imgurAttachmentViewFactories = new ArrayList<ImgurAttachmentViewFactory>();
69-
imgurAttachmentViewFactories.add(imgurAttachmentViewFactory);
67+
List<ImgurAttachmentFactory> imgurAttachmentViewFactories = new ArrayList<ImgurAttachmentFactory>();
68+
imgurAttachmentViewFactories.add(imgurAttachmentFactory);
7069

7170
AttachmentFactoryManager attachmentFactoryManager = new AttachmentFactoryManager(imgurAttachmentViewFactories);
7271
binding.messageListView.setAttachmentFactoryManager(attachmentFactoryManager);

samplejava/src/main/java/com/example/chattutorial/ChannelActivity4.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
6969
MessageInputViewModel messageInputViewModel = provider.get(MessageInputViewModel.class);
7070

7171
// Set view factory manager for Imgur attachments
72-
ImgurAttachmentViewFactory imgurAttachmentViewFactory = new ImgurAttachmentViewFactory();
72+
ImgurAttachmentFactory imgurAttachmentFactory = new ImgurAttachmentFactory();
7373

74-
List<ImgurAttachmentViewFactory> imgurAttachmentViewFactories = new ArrayList<ImgurAttachmentViewFactory>();
75-
imgurAttachmentViewFactories.add(imgurAttachmentViewFactory);
74+
List<ImgurAttachmentFactory> imgurAttachmentViewFactories = new ArrayList<ImgurAttachmentFactory>();
75+
imgurAttachmentViewFactories.add(imgurAttachmentFactory);
7676

7777
AttachmentFactoryManager attachmentFactoryManager = new AttachmentFactoryManager(imgurAttachmentViewFactories);
7878
binding.messageListView.setAttachmentFactoryManager(attachmentFactoryManager);

samplejava/src/main/java/com/example/chattutorial/ImgurAttachmentViewFactory.java renamed to samplejava/src/main/java/com/example/chattutorial/ImgurAttachmentFactory.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,37 @@
1919
import io.getstream.chat.android.ui.message.list.adapter.viewholder.attachment.AttachmentFactory;
2020
import io.getstream.chat.android.ui.message.list.adapter.viewholder.attachment.InnerAttachmentViewHolder;
2121

22-
public class ImgurAttachmentViewFactory implements AttachmentFactory {
22+
/** A custom attachment factory to show an imgur logo if the attachment URL is an imgur image. **/
23+
public class ImgurAttachmentFactory implements AttachmentFactory {
2324

2425

26+
// 1. Check whether the message contains an Imgur attachment
2527
@Override
2628
public boolean canHandle(@NonNull Message message) {
2729
return containsImgurAttachments(message) != null;
2830
}
2931

32+
// 2. Create the ViewHolder that will be used to display the Imgur logo
33+
// over Imgur attachments
3034
@NonNull
3135
@Override
32-
public InnerAttachmentViewHolder createViewHolder(@NonNull Message message, @Nullable MessageListListenerContainer messageListListenerContainer, @NonNull ViewGroup viewGroup) {
36+
public InnerAttachmentViewHolder createViewHolder(
37+
@NonNull Message message,
38+
@Nullable MessageListListenerContainer listeners,
39+
@NonNull ViewGroup parent
40+
) {
3341
Attachment imgurAttachment = containsImgurAttachments(message);
3442

35-
AttachmentImgurBinding attachmentImgurBinding = AttachmentImgurBinding.inflate(LayoutInflater.from(viewGroup.getContext()), null, false);
43+
AttachmentImgurBinding attachmentImgurBinding = AttachmentImgurBinding.inflate(LayoutInflater.from(parent.getContext()), null, false);
3644

3745
return new ImgurAttachmentViewHolder(attachmentImgurBinding, imgurAttachment);
3846
}
3947

4048
private Attachment containsImgurAttachments(@NotNull Message message) {
4149
for (int i = 0; i < message.getAttachments().size(); i++) {
42-
boolean containsAttachments = message.getAttachments().get(i).getImageUrl().contains("imgur");
50+
String imageUrl = message.getAttachments().get(i).getImageUrl();
4351

44-
if (containsAttachments) {
52+
if (imageUrl != null && imageUrl.contains("imgur")) {
4553
return message.getAttachments().get(i);
4654
}
4755
}

samplekotlin/src/main/java/com/example/chattutorial/ImgurAttachmentViewFactory.kt renamed to samplekotlin/src/main/java/com/example/chattutorial/ImgurAttachmentFactory.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@ import io.getstream.chat.android.ui.message.list.adapter.viewholder.attachment.I
1313
/** A custom attachment factory to show an imgur logo if the attachment URL is an imgur image. */
1414
class ImgurAttachmentFactory : AttachmentFactory {
1515

16+
// 1. Check whether the message contains an Imgur attachment
1617
override fun canHandle(message: Message): Boolean {
1718
val imgurAttachment = message.attachments.firstOrNull { it.isImgurAttachment() }
1819
return imgurAttachment != null
1920
}
2021

22+
// 2. Create the ViewHolder that will be used to display the Imgur logo
23+
// over Imgur attachments
2124
override fun createViewHolder(
2225
message: Message,
2326
listeners: MessageListListenerContainer?,
2427
parent: ViewGroup
2528
): InnerAttachmentViewHolder {
26-
val imgurAttachment = message.attachments.firstOrNull { it.isImgurAttachment() }
27-
?: return createViewHolder(message, listeners, parent)
29+
val imgurAttachment = message.attachments.first() { it.isImgurAttachment() }
2830
val binding = AttachmentImgurBinding
2931
.inflate(LayoutInflater.from(parent.context), null, false)
3032
return ImgurAttachmentViewHolder(

0 commit comments

Comments
 (0)