@@ -23,6 +23,7 @@ import android.view.View
2323import android.view.ViewGroup
2424import android.widget.CheckedTextView
2525import android.widget.FrameLayout
26+ import android.widget.Toast
2627import androidx.constraintlayout.widget.ConstraintLayout
2728import androidx.core.view.descendants
2829import 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