public fun changeSelectedAttachments(attachmentItem: AttachmentPickerItemState) { val dataSet = attachments val itemIndex = dataSet.indexOf(attachmentItem) val newFiles = dataSet.toMutableList() val newItem = dataSet[itemIndex].copy(isSelected = !newFiles[itemIndex].isSelected) newFiles.removeAt(itemIndex)  newFiles.add(itemIndex, newItem) if (attachmentsPickerMode == Files) { files = newFiles } else if (attachmentsPickerMode == Images) { images = newFiles } attachments = newFiles }
Triggered when an [AttachmentMetaData] is selected in the list. Added or removed from the corresponding list, be it [files] or [images], based on [attachmentsPickerMode].