Skip to content

Commit 6066a0c

Browse files
committed
Handle unresolvable attachments in XML
1 parent 0e2fc6a commit 6066a0c

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

stream-chat-android-ui-components/src/main/kotlin/io/getstream/chat/android/ui/feature/messages/composer/attachment/picker/AttachmentsPickerDialogFragment.kt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import android.view.View
2323
import android.view.ViewGroup
2424
import android.widget.CheckedTextView
2525
import android.widget.FrameLayout
26+
import android.widget.Toast
2627
import androidx.constraintlayout.widget.ConstraintLayout
2728
import androidx.core.view.descendants
2829
import androidx.viewpager2.widget.ViewPager2
@@ -93,9 +94,7 @@ public class AttachmentsPickerDialogFragment : BottomSheetDialogFragment() {
9394

9495
override fun onDismiss(dialog: DialogInterface) {
9596
if (::style.isInitialized && style.saveAttachmentsOnDismiss) {
96-
attachmentsSelectionListener?.onAttachmentsSelected(
97-
selectedAttachments.mapNotNull { it.toAttachment(requireContext()) },
98-
)
97+
attachmentsSelectionListener?.onAttachmentsSelected(resolveSelectedAttachments())
9998
}
10099
super.onDismiss(dialog)
101100
}
@@ -117,9 +116,7 @@ public class AttachmentsPickerDialogFragment : BottomSheetDialogFragment() {
117116
binding.attachButton.setImageDrawable(style.submitAttachmentsButtonIconDrawable)
118117
binding.attachButton.isEnabled = false
119118
binding.attachButton.setOnClickListener {
120-
attachmentsSelectionListener?.onAttachmentsSelected(
121-
selectedAttachments.mapNotNull { it.toAttachment(requireContext()) },
122-
)
119+
attachmentsSelectionListener?.onAttachmentsSelected(resolveSelectedAttachments())
123120
dismiss()
124121
}
125122
}
@@ -162,9 +159,7 @@ public class AttachmentsPickerDialogFragment : BottomSheetDialogFragment() {
162159
}
163160

164161
override fun onSelectedAttachmentsSubmitted() {
165-
attachmentsSelectionListener?.onAttachmentsSelected(
166-
selectedAttachments.mapNotNull { it.toAttachment(requireContext()) },
167-
)
162+
attachmentsSelectionListener?.onAttachmentsSelected(resolveSelectedAttachments())
168163
dismiss()
169164
}
170165

@@ -235,6 +230,18 @@ public class AttachmentsPickerDialogFragment : BottomSheetDialogFragment() {
235230
this.pollSubmissionListener = pollSubmissionListener
236231
}
237232

233+
private fun resolveSelectedAttachments(): List<Attachment> {
234+
val resolved = selectedAttachments.mapNotNull { it.toAttachment(requireContext()) }
235+
if (resolved.size < selectedAttachments.size) {
236+
Toast.makeText(
237+
requireContext(),
238+
R.string.stream_ui_attachment_picker_error_unresolvable_attachments,
239+
Toast.LENGTH_LONG,
240+
).show()
241+
}
242+
return resolved
243+
}
244+
238245
private fun setSelectedTab(checkedTextView: CheckedTextView, pagePosition: Int) {
239246
binding.attachmentPager.setCurrentItem(pagePosition, false)
240247
binding.attachmentButtonsContainer.descendants.forEach {

0 commit comments

Comments
 (0)