Skip to content

Commit

Permalink
Merge pull request #44 from sendbird/release/3.21.0
Browse files Browse the repository at this point in the history
3.21.0
  • Loading branch information
sendbird-sdk-deployment authored Sep 12, 2024
2 parents 8319e30 + 2249ab3 commit 93f1b97
Show file tree
Hide file tree
Showing 74 changed files with 1,569 additions and 661 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Changelog
### v3.21.0 (Sep 12, 2024) with Chat SDK `v4.19.0`
* Changed the Form type message UI rendering due to the modification of the Form model from BaseMessage to MessageForm.
* Sendbird Business Messaging changes
* Changed behavior not to send viewed stats in case the message is fallback message.
* Fixed not collecting viewed stats when the category filter is changed.

### v3.20.1 (Aug 30, 2024) with Chat SDK `v4.18.0`
* Added support for EmojiCategory. You can now filter emojis for different messages when adding Reactions to a message.
* New Interfaces
Expand All @@ -12,8 +18,7 @@
* Note: You need to set your custom EmojiCategory using [Sendbird Platform API](https://sendbird.com/docs/chat/platform-api/v3/message/reactions-and-emojis/reactions-and-emojis-overview) in advance.
* Fixed a crash in the new version due to new fields not having default value.

### <strike>v3.20.0 (Aug 29, 2024) with Chat SDK `v4.18.0`</strike> *DEPRECATED*
* **Deprecated as this version would cause `MissingFieldException` from `NotificationTemplate` due to adding a new field without a default value.**
### v3.20.0 (Aug 29, 2024) with Chat SDK `v4.18.0`
* Added support for EmojiCategory. You can now filter emojis for different messages when adding Reactions to a message.
* New Interfaces
```kotlin
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ android.nonTransitiveRClass=false
android.nonFinalResIds=false
android.enableR8.fullMode=false

UIKIT_VERSION = 3.20.1
UIKIT_VERSION = 3.21.0
UIKIT_VERSION_CODE = 1
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class BaseApplication : MultiDexApplication() {
*/
fun setupConfigurations() {
when (PreferenceUtils.selectedSampleType) {
SampleType.Basic -> {
null, SampleType.Basic -> {
// set whether to use user profile
UIKitConfig.common.enableUsingDefaultUserProfile = true
// set whether to use typing indicators in channel list
Expand Down
2 changes: 1 addition & 1 deletion uikit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

// Sendbird
api 'com.sendbird.sdk:sendbird-chat:4.18.0'
api 'com.sendbird.sdk:sendbird-chat:4.19.0'

implementation 'com.github.bumptech.glide:glide:4.16.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.16.0'
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package com.sendbird.uikit.activities.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.sendbird.android.message.MessageForm
import com.sendbird.android.message.MessageFormItem
import com.sendbird.uikit.databinding.SbViewFormItemTextBinding
import com.sendbird.uikit.databinding.SbViewFormItemChipBinding
import com.sendbird.uikit.databinding.SbViewFormItemTextareaBinding
import com.sendbird.uikit.internal.extensions.convertToViewType
import com.sendbird.uikit.internal.extensions.isEqualTo
import com.sendbird.uikit.internal.extensions.isSubmittable
import com.sendbird.uikit.internal.extensions.shouldCheckValidation
import com.sendbird.uikit.internal.interfaces.OnFormValidationChangedListener

internal class FormItemAdapter(private val onValidationChangedListener: OnFormValidationChangedListener) : ListAdapter<MessageFormItem, FormItemAdapter.MessageFormItemViewHolder>(diffUtil) {
private var messageForm: MessageForm? = null
private var validations: MutableList<Boolean>? = null

fun isSubmittable(): Boolean {
return currentList.all { messageFormItem ->
messageFormItem.isSubmittable
}
}

fun updateValidation() {
currentList.forEachIndexed { index, messageFormItem ->
val lastValidation = messageFormItem.shouldCheckValidation
val validation = messageFormItem.isSubmittable
messageFormItem.shouldCheckValidation = validation
if (lastValidation != validation) {
notifyItemChanged(index)
}
}
}

fun setMessageForm(form: MessageForm) {
messageForm = form
validations = MutableList(form.items.size) { true }
submitList(form.items)
}

private fun updateValidation(index: Int, isValid: Boolean) {
validations?.set(index, isValid)
onValidationChangedListener.onValidationChanged(validations?.all { it } == true)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MessageFormItemViewHolder {
return when (viewType) {
MessageFormViewType.TEXT.value -> FormItemTextViewHolder(
SbViewFormItemTextBinding.inflate(LayoutInflater.from(parent.context), parent, false)
)
MessageFormViewType.TEXTAREA.value -> FormItemTextareaViewHolder(
SbViewFormItemTextareaBinding.inflate(LayoutInflater.from(parent.context), parent, false)
)
MessageFormViewType.CHIP.value -> FormItemChipViewHolder(
SbViewFormItemChipBinding.inflate(LayoutInflater.from(parent.context), parent, false)
)
else -> FormItemTextViewHolder(
SbViewFormItemTextBinding.inflate(LayoutInflater.from(parent.context), parent, false)
)
}
}

override fun getItemViewType(position: Int): Int {
return getItem(position).style?.layout?.convertToViewType() ?: MessageFormViewType.TEXT.value
}

override fun onBindViewHolder(holder: MessageFormItemViewHolder, position: Int) {
holder.bind(getItem(position), messageForm?.isSubmitted == false) {
updateValidation(position, it)
}
}

private class FormItemTextViewHolder(
val binding: SbViewFormItemTextBinding
) : MessageFormItemViewHolder(binding.root) {
override fun bind(item: MessageFormItem, isEnabled: Boolean, onValidationChangedListener: OnFormValidationChangedListener) {
binding.formItemView.onValidationListener = onValidationChangedListener
binding.formItemView.drawFormItem(item, isEnabled, item.shouldCheckValidation)
}
}

private class FormItemTextareaViewHolder(
val binding: SbViewFormItemTextareaBinding
) : MessageFormItemViewHolder(binding.root) {
override fun bind(item: MessageFormItem, isEnabled: Boolean, onValidationChangedListener: OnFormValidationChangedListener) {
binding.formItemView.onValidationListener = onValidationChangedListener
binding.formItemView.drawFormItem(item, isEnabled, item.shouldCheckValidation)
}
}

private class FormItemChipViewHolder(
val binding: SbViewFormItemChipBinding
) : MessageFormItemViewHolder(binding.root) {
override fun bind(item: MessageFormItem, isEnabled: Boolean, onValidationChangedListener: OnFormValidationChangedListener) {
binding.formItemView.onValidationListener = onValidationChangedListener
binding.formItemView.drawFormItem(item, isEnabled, item.shouldCheckValidation)
}
}

abstract class MessageFormItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
abstract fun bind(item: MessageFormItem, isEnabled: Boolean, onValidationChangedListener: OnFormValidationChangedListener)
}

companion object {
val diffUtil = object : DiffUtil.ItemCallback<MessageFormItem>() {
override fun areItemsTheSame(oldItem: MessageFormItem, newItem: MessageFormItem): Boolean {
return oldItem.id == newItem.id
}

override fun areContentsTheSame(oldItem: MessageFormItem, newItem: MessageFormItem): Boolean {
return oldItem.draftValues isEqualTo newItem.draftValues &&
oldItem.submittedValues isEqualTo newItem.submittedValues &&
!(oldItem.required == false && newItem.required == false)
}
}
}
}

internal enum class MessageFormViewType(val value: Int) {
TEXT(0),
TEXTAREA(1),
CHIP(2),
UNKNOWN(3)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.sendbird.uikit.activities.adapter;

import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;

import android.view.ViewGroup;

import androidx.annotation.NonNull;
Expand All @@ -19,8 +17,8 @@
import com.sendbird.uikit.internal.interfaces.OnFeedbackRatingClickListener;
import com.sendbird.uikit.internal.ui.viewholders.FormMessageViewHolder;
import com.sendbird.uikit.internal.ui.viewholders.OtherTemplateMessageViewHolder;
import com.sendbird.uikit.internal.utils.TemplateViewCachePool;
import com.sendbird.uikit.internal.ui.viewholders.OtherUserMessageViewHolder;
import com.sendbird.uikit.internal.utils.TemplateViewCachePool;
import com.sendbird.uikit.model.MessageListUIParams;

/**
Expand Down Expand Up @@ -84,6 +82,12 @@ public MessageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewT
finalListener.onFeedbackClicked(view, rating);
}
});
otherTemplateMessageViewHolder.setOnSuggestedRepliesClickListener((view, pos, data) -> {
final OnItemClickListener<String> finalListener = this.suggestedRepliesClickListener;
if (finalListener != null) {
finalListener.onItemClick(view, pos, data);
}
});
} else if (viewHolder instanceof FormMessageViewHolder) {
FormMessageViewHolder formMessageViewHolder = (FormMessageViewHolder) viewHolder;
formMessageViewHolder.setOnSubmitClickListener((message, form) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,20 +264,21 @@ public static int getViewType(@NonNull BaseMessage message) {
public static MessageType getMessageType(@NonNull BaseMessage message) {
MessageType type;

MessageTemplateStatus messageTemplateStatus = MessageTemplateExtensionsKt.getMessageTemplateStatus(message);
if (messageTemplateStatus != null) {
// NOT_APPLICABLE is possible when the message is a unknown version of template message or the message is not a template message.
final MessageTemplateStatus messageTemplateStatus = MessageTemplateExtensionsKt.getMessageTemplateStatus(message);
if (MessageTemplateExtensionsKt.isTemplateMessage(message) && messageTemplateStatus != null) {
switch (messageTemplateStatus) {
case CACHED:
case LOADING:
case FAILED_TO_FETCH:
case FAILED_TO_PARSE:
return MessageType.VIEW_TYPE_TEMPLATE_MESSAGE_OTHER;
case NOT_APPLICABLE:
break;
return MessageType.VIEW_TYPE_UNKNOWN_MESSAGE_OTHER;
}
}

if (message.getChannelType() == ChannelType.GROUP && !message.getForms().isEmpty()) {
if (message.getChannelType() == ChannelType.GROUP && message.getMessageForm() != null) {
return MessageType.VIEW_TYPE_FORM_TYPE_MESSAGE;
}

Expand Down
3 changes: 1 addition & 2 deletions uikit/src/main/java/com/sendbird/uikit/consts/StringSet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,10 @@ object StringSet {
const val delete = "delete"

// template message
const val template = "template"
const val message_template_params = "message_template_params"
const val message_template_status = "message_template_status"
const val container_type = "container_type"
const val ui = "ui"
const val default = "default"

// Config
const val none = "none"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.sendbird.android.message.Feedback;
import com.sendbird.android.message.FeedbackRating;
import com.sendbird.android.message.FileMessage;
import com.sendbird.android.message.Form;
import com.sendbird.android.message.MessageForm;
import com.sendbird.android.message.SendingStatus;
import com.sendbird.android.params.MessageListParams;
import com.sendbird.android.params.UserMessageCreateParams;
Expand Down Expand Up @@ -579,8 +579,8 @@ protected void onSuggestedRepliesClicked(@NonNull String suggestedReply) {
* @param form The form to be submitted
* since 3.12.1
*/
protected void onFormSubmitButtonClicked(@NonNull BaseMessage message, @NonNull Form form) {
message.submitForm(form, (e) -> {
protected void onFormSubmitButtonClicked(@NonNull BaseMessage message, @NonNull MessageForm form) {
message.submitMessageForm((e) -> {
if (e != null) {
showConfirmDialog(getString(R.string.sb_forms_submit_failed));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.sendbird.uikit.interfaces

import com.sendbird.android.message.BaseMessage
import com.sendbird.android.message.Form
import com.sendbird.android.message.MessageForm

/**
* Interface definition for a callback to be invoked when the submit button of the form is clicked.
Expand All @@ -16,5 +16,5 @@ fun interface FormSubmitButtonClickListener {
* @param form the form to be submitted
* @since 3.12.1
*/
fun onClicked(message: BaseMessage, form: Form)
fun onClicked(message: BaseMessage, form: MessageForm)
}
Loading

0 comments on commit 93f1b97

Please sign in to comment.