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

Feature start of the channel view #5145

Merged
merged 4 commits into from
Jan 15, 2024
Merged

Conversation

JcMinarro
Copy link
Member

🎯 Goal

Add a new MessageItem type that represents the beginning of a channel conversation and allows our customers to add a "Welcome View" or any other data related to the channel.

The default view our SDK renders in that case is an empty view

Fix: https://github.com/GetStream/android-internal-board/issues/237

🎨 UI Changes

Example of how this view will be rendered

Before After
Screenshot_20240111_133507 Screenshot_20240111_133401

🧪 Testing

To see it in action, you need to go to the beginning of a channel. Logining as "Marton" you can find a couple of conversations with a few messages.
A custom MessageListItemViewHolderFactory needs to be added to the MessageListView.
The following patch add all needed stuff to render it

Provide the patch summary here
Index: stream-chat-android-ui-components-sample/src/main/kotlin/io/getstream/chat/ui/sample/feature/chat/ChatFragment.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/stream-chat-android-ui-components-sample/src/main/kotlin/io/getstream/chat/ui/sample/feature/chat/ChatFragment.kt b/stream-chat-android-ui-components-sample/src/main/kotlin/io/getstream/chat/ui/sample/feature/chat/ChatFragment.kt
--- a/stream-chat-android-ui-components-sample/src/main/kotlin/io/getstream/chat/ui/sample/feature/chat/ChatFragment.kt	(revision 848379aabb70316203bc58d6495c0390de5a4f10)
+++ b/stream-chat-android-ui-components-sample/src/main/kotlin/io/getstream/chat/ui/sample/feature/chat/ChatFragment.kt	(date 1704977004214)
@@ -35,13 +35,20 @@
 import io.getstream.chat.android.ui.common.state.messages.list.DeletedMessageVisibility
 import io.getstream.chat.android.ui.common.state.messages.list.EditMessage
 import io.getstream.chat.android.ui.common.state.messages.list.SendAnyway
+import io.getstream.chat.android.ui.feature.messages.list.adapter.BaseMessageItemViewHolder
+import io.getstream.chat.android.ui.feature.messages.list.adapter.MessageListItem
+import io.getstream.chat.android.ui.feature.messages.list.adapter.MessageListItemPayloadDiff
+import io.getstream.chat.android.ui.feature.messages.list.adapter.MessageListItemViewHolderFactory
+import io.getstream.chat.android.ui.feature.messages.list.adapter.MessageListItemViewType
 import io.getstream.chat.android.ui.utils.extensions.getCreatedAtOrThrow
+import io.getstream.chat.android.ui.utils.extensions.inflater
 import io.getstream.chat.android.ui.viewmodel.messages.MessageComposerViewModel
 import io.getstream.chat.android.ui.viewmodel.messages.MessageListHeaderViewModel
 import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModel
 import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModelFactory
 import io.getstream.chat.android.ui.viewmodel.messages.bindView
 import io.getstream.chat.ui.sample.common.navigateSafely
+import io.getstream.chat.ui.sample.databinding.CustomStartOfTheChannelViewBinding
 import io.getstream.chat.ui.sample.databinding.FragmentChatBinding
 import io.getstream.chat.ui.sample.feature.chat.composer.CustomMessageComposerLeadingContent
 import io.getstream.chat.ui.sample.feature.common.ConfirmationDialogFragment
@@ -181,6 +188,7 @@
 
     private fun initMessageListViewModel() {
         val calendar = Calendar.getInstance()
+        binding.messageListView.setMessageViewHolderFactory(CustomMessageListItemViewHolderFactory())
         messageListViewModel.apply {
             messageListViewModel.setDeletedMessageVisibility(
                 deletedMessageVisibility = DeletedMessageVisibility.VISIBLE_FOR_CURRENT_USER,
@@ -270,4 +278,25 @@
     private companion object {
         private const val OVERRIDE_LEADING_CONTENT = false
     }
+
+    class CustomMessageListItemViewHolderFactory : MessageListItemViewHolderFactory() {
+        override fun createViewHolder(
+            parentView: ViewGroup,
+            viewType: Int,
+        ): BaseMessageItemViewHolder<out MessageListItem> {
+            if (viewType == MessageListItemViewType.START_OF_THE_CHANNEL) {
+                return CustomStartOfTheChannelViewHolder(parentView)
+            }
+            return super.createViewHolder(parentView, viewType)
+        }
+    }
+
+    class CustomStartOfTheChannelViewHolder(
+        parentView: ViewGroup,
+    ) : BaseMessageItemViewHolder<MessageListItem.StartOfTheChannelItem>(
+         CustomStartOfTheChannelViewBinding.inflate(LayoutInflater.from(parentView.context), parentView, false).root
+    ) {
+        override fun bindData(data: MessageListItem.StartOfTheChannelItem, diff: MessageListItemPayloadDiff?) {
+        }
+    }
 }

🎉 GIF

@JcMinarro JcMinarro requested a review from a team as a code owner January 11, 2024 12:46
@JcMinarro JcMinarro force-pushed the feature/start-of-the-channel-view branch from e0b0349 to 1299c82 Compare January 11, 2024 13:08
@kanat kanat added enhancement New feature or request v6 labels Jan 12, 2024
Copy link
Collaborator

@kanat kanat left a comment

Choose a reason for hiding this comment

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

Overall, LGTM

@kanat
Copy link
Collaborator

kanat commented Jan 15, 2024

@JcMinarro is this ready to be merged? :)

I'm asking due to PR's name Feature start....
So I was wondering if there is something next coming for this feature.

@JcMinarro
Copy link
Member Author

Yes, it is 🙃

@JcMinarro JcMinarro merged commit 69054a9 into develop Jan 15, 2024
7 checks passed
@JcMinarro JcMinarro deleted the feature/start-of-the-channel-view branch January 15, 2024 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request v6
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants