-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from sendbird/release/3.10.0
3.10.0
- Loading branch information
Showing
53 changed files
with
1,544 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
uikit/src/main/java/com/sendbird/uikit/activities/adapter/FormFieldAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.sendbird.uikit.activities.adapter | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.DiffUtil | ||
import com.sendbird.uikit.activities.viewholder.BaseViewHolder | ||
import com.sendbird.uikit.databinding.SbViewFormFieldBinding | ||
import com.sendbird.uikit.internal.model.Form | ||
import com.sendbird.uikit.internal.model.FormField | ||
|
||
internal class FormFieldAdapter : BaseAdapter<FormField, BaseViewHolder<FormField>>() { | ||
private val formFields: MutableList<FormField> = mutableListOf() | ||
|
||
fun isReadyToSubmit(): Boolean { | ||
return formFields.all { it.isReadyToSubmit() } | ||
} | ||
|
||
fun updateValidation() { | ||
formFields.forEachIndexed { index, formField -> | ||
val lastValidation = formField.lastValidation | ||
val validation = formField.isReadyToSubmit() | ||
formField.lastValidation = validation | ||
if (lastValidation != validation) { | ||
notifyItemChanged(index) | ||
} | ||
} | ||
} | ||
|
||
fun setFormFields(form: Form) { | ||
val newFormFields = if (form.isAnswered) { | ||
form.formFields.filter { it.answer != null } | ||
} else { | ||
form.formFields | ||
} | ||
val diffResult = DiffUtil.calculateDiff(FormFieldDiffCallback(formFields, newFormFields)) | ||
formFields.clear() | ||
formFields.addAll(newFormFields) | ||
diffResult.dispatchUpdatesTo(this) | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder<FormField> { | ||
return FormFieldViewHolder( | ||
SbViewFormFieldBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
) | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return formFields.size | ||
} | ||
|
||
override fun getItem(position: Int): FormField { | ||
return formFields[position] | ||
} | ||
|
||
override fun getItems(): List<FormField> { | ||
return formFields.toList() | ||
} | ||
|
||
override fun onBindViewHolder(holder: BaseViewHolder<FormField>, position: Int) { | ||
holder.bind(getItem(position)) | ||
} | ||
|
||
internal class FormFieldViewHolder( | ||
val binding: SbViewFormFieldBinding | ||
) : BaseViewHolder<FormField>(binding.root) { | ||
override fun bind(item: FormField) { | ||
binding.formFieldView.drawFormField(item) | ||
} | ||
} | ||
|
||
private class FormFieldDiffCallback( | ||
private val oldList: List<FormField>, | ||
private val newList: List<FormField> | ||
) : DiffUtil.Callback() { | ||
override fun getOldListSize(): Int { | ||
return oldList.size | ||
} | ||
|
||
override fun getNewListSize(): Int { | ||
return newList.size | ||
} | ||
|
||
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { | ||
val oldItem = oldList[oldItemPosition] | ||
val newItem = newList[newItemPosition] | ||
return oldItem.formFieldKey == newItem.formFieldKey && | ||
oldItem.messageId == newItem.messageId | ||
} | ||
|
||
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { | ||
return oldList[oldItemPosition] == newList[newItemPosition] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
uikit/src/main/java/com/sendbird/uikit/activities/adapter/SuggestedRepliesAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.sendbird.uikit.activities.adapter | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.DiffUtil | ||
import com.sendbird.uikit.activities.viewholder.BaseViewHolder | ||
import com.sendbird.uikit.databinding.SbViewSuggestedReplyBinding | ||
import com.sendbird.uikit.interfaces.OnItemClickListener | ||
|
||
internal class SuggestedRepliesAdapter : BaseAdapter<String, BaseViewHolder<String>>() { | ||
var onItemClickListener: OnItemClickListener<String>? = null | ||
var suggestedReplies: List<String> = listOf() | ||
set(value) { | ||
val diffResult = DiffUtil.calculateDiff(SuggestedReplyDiffCallback(field, value)) | ||
field = value | ||
diffResult.dispatchUpdatesTo(this) | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder<String> { | ||
return SuggestedReplyViewHolder( | ||
SbViewSuggestedReplyBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
).apply { | ||
this.binding.suggestedReplyView.setOnClickListener { | ||
val item = getItem(absoluteAdapterPosition) | ||
val index = suggestedReplies.indexOf(item) | ||
if (index == -1) return@setOnClickListener | ||
onItemClickListener?.onItemClick(binding.root, index, item) | ||
} | ||
} | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return suggestedReplies.size | ||
} | ||
|
||
override fun getItem(position: Int): String { | ||
return suggestedReplies[position] | ||
} | ||
|
||
override fun getItems(): List<String> { | ||
return suggestedReplies.toList() | ||
} | ||
|
||
override fun onBindViewHolder(holder: BaseViewHolder<String>, position: Int) { | ||
holder.bind(getItem(position)) | ||
} | ||
|
||
private class SuggestedReplyViewHolder( | ||
val binding: SbViewSuggestedReplyBinding | ||
) : BaseViewHolder<String>(binding.root) { | ||
override fun bind(item: String) { | ||
binding.suggestedReplyView.drawSuggestedReplies(item) | ||
} | ||
} | ||
|
||
private class SuggestedReplyDiffCallback( | ||
private val oldList: List<String>, | ||
private val newList: List<String> | ||
) : DiffUtil.Callback() { | ||
override fun getOldListSize(): Int { | ||
return oldList.size | ||
} | ||
|
||
override fun getNewListSize(): Int { | ||
return newList.size | ||
} | ||
|
||
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { | ||
return oldList[oldItemPosition] == newList[newItemPosition] | ||
} | ||
|
||
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { | ||
return oldList[oldItemPosition] == newList[newItemPosition] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.