mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Prevents attaching more than 12 files to a same message
This commit is contained in:
parent
7cf51f51a1
commit
99e771898a
6 changed files with 36 additions and 3 deletions
|
|
@ -129,7 +129,9 @@ class ConversationFragment : SlidingPaneChildFragment() {
|
|||
private var filePathToExport: String? = null
|
||||
|
||||
private val pickMedia = registerForActivityResult(
|
||||
ActivityResultContracts.PickMultipleVisualMedia()
|
||||
ActivityResultContracts.PickMultipleVisualMedia(
|
||||
maxItems = SendMessageInConversationViewModel.MAX_FILES_TO_ATTACH
|
||||
)
|
||||
) { list ->
|
||||
if (!list.isNullOrEmpty()) {
|
||||
for (uri in list) {
|
||||
|
|
|
|||
|
|
@ -58,6 +58,8 @@ import org.linphone.utils.LinphoneUtils
|
|||
class SendMessageInConversationViewModel @UiThread constructor() : GenericViewModel() {
|
||||
companion object {
|
||||
private const val TAG = "[Send Message In Conversation ViewModel]"
|
||||
|
||||
const val MAX_FILES_TO_ATTACH = 12
|
||||
}
|
||||
|
||||
val textToSend = MutableLiveData<String>()
|
||||
|
|
@ -72,6 +74,8 @@ class SendMessageInConversationViewModel @UiThread constructor() : GenericViewMo
|
|||
|
||||
val isFileAttachmentsListOpen = MutableLiveData<Boolean>()
|
||||
|
||||
val maxNumberOfAttachmentsReached = MutableLiveData<Boolean>()
|
||||
|
||||
val attachments = MutableLiveData<ArrayList<FileModel>>()
|
||||
|
||||
val isReplying = MutableLiveData<Boolean>()
|
||||
|
|
@ -147,6 +151,7 @@ class SendMessageInConversationViewModel @UiThread constructor() : GenericViewMo
|
|||
isEmojiPickerOpen.value = false
|
||||
isPlayingVoiceRecord.value = false
|
||||
isInCallConversation.value = false
|
||||
maxNumberOfAttachmentsReached.value = false
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
|
|
@ -309,12 +314,32 @@ class SendMessageInConversationViewModel @UiThread constructor() : GenericViewMo
|
|||
}
|
||||
val list = arrayListOf<FileModel>()
|
||||
attachments.value = list
|
||||
maxNumberOfAttachmentsReached.value = false
|
||||
|
||||
isFileAttachmentsListOpen.value = false
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun addAttachment(file: String) {
|
||||
if (attachments.value.orEmpty().size >= MAX_FILES_TO_ATTACH) {
|
||||
Log.w(
|
||||
"$TAG Max number of attachments [$MAX_FILES_TO_ATTACH] reached, file [$file] won't be attached"
|
||||
)
|
||||
showRedToastEvent.postValue(
|
||||
Event(
|
||||
Pair(
|
||||
R.string.conversation_maximum_number_of_attachments_reached,
|
||||
R.drawable.warning_circle
|
||||
)
|
||||
)
|
||||
)
|
||||
viewModelScope.launch {
|
||||
Log.i("$TAG Deleting temporary file [$file]")
|
||||
FileUtils.deleteFile(file)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
val list = arrayListOf<FileModel>()
|
||||
list.addAll(attachments.value.orEmpty())
|
||||
|
||||
|
|
@ -326,6 +351,7 @@ class SendMessageInConversationViewModel @UiThread constructor() : GenericViewMo
|
|||
|
||||
list.add(model)
|
||||
attachments.value = list
|
||||
maxNumberOfAttachmentsReached.value = list.size >= MAX_FILES_TO_ATTACH
|
||||
|
||||
if (list.isNotEmpty()) {
|
||||
isFileAttachmentsListOpen.value = true
|
||||
|
|
@ -353,6 +379,7 @@ class SendMessageInConversationViewModel @UiThread constructor() : GenericViewMo
|
|||
Log.w("$TAG Failed to find file attachment matching [$file]")
|
||||
}
|
||||
attachments.value = list
|
||||
maxNumberOfAttachmentsReached.value = list.size >= MAX_FILES_TO_ATTACH
|
||||
|
||||
if (list.isEmpty()) {
|
||||
isFileAttachmentsListOpen.value = false
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_enabled="false" android:color="?attr/color_main2_200"/>
|
||||
<item android:state_enabled="false" android:color="?attr/color_grey_300"/>
|
||||
<item android:state_pressed="true" android:color="?attr/color_main1_500"/>
|
||||
<item android:color="?attr/color_main2_500"/>
|
||||
</selector>
|
||||
|
|
@ -97,6 +97,7 @@
|
|||
android:layout_height="0dp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:onClick="@{openFilePickerClickListener}"
|
||||
android:enabled="@{!viewModel.maxNumberOfAttachmentsReached}"
|
||||
android:padding="8dp"
|
||||
android:src="@drawable/paperclip"
|
||||
android:contentDescription="@string/content_description_chat_open_attach_media"
|
||||
|
|
@ -112,6 +113,7 @@
|
|||
android:layout_height="0dp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:onClick="@{openCameraClickListener}"
|
||||
android:enabled="@{!viewModel.maxNumberOfAttachmentsReached}"
|
||||
android:padding="8dp"
|
||||
android:src="@drawable/camera"
|
||||
android:contentDescription="@string/content_description_chat_take_picture"
|
||||
|
|
|
|||
|
|
@ -454,6 +454,7 @@
|
|||
<string name="conversation_warning_disabled_because_not_secured_subtitle">Cette conversation a été désactivée pour garantir votre sécurité.</string>
|
||||
<string name="conversation_warning_disabled_encrypted_bottom_sheet_title">Chiffrement obligatoire</string>
|
||||
<string name="conversation_warning_disabled_encrypted_bottom_sheet_message">Vous avez activé le chiffrement obligatoire. Vos conversations non chiffrées sont désactivées pour garantir votre sécurité. Vous pouvez recréer cette conversation ou bien désactiver le chiffrement obligatoire dans vos paramètres de compte.</string>
|
||||
<string name="conversation_maximum_number_of_attachments_reached">Nombre maximum de fichiers atteint !</string>
|
||||
<string name="conversation_dialog_set_subject">Nommer la conversation</string>
|
||||
<string name="conversation_dialog_edit_subject">Renommer la conversation</string>
|
||||
<string name="conversation_dialog_subject_hint">Nom de la conversation</string>
|
||||
|
|
|
|||
|
|
@ -489,7 +489,8 @@
|
|||
<string name="conversation_warning_disabled_because_not_secured_title">This conversation is not encrypted!</string>
|
||||
<string name="conversation_warning_disabled_because_not_secured_subtitle">For your safety, this conversation was disabled.</string>
|
||||
<string name="conversation_warning_disabled_encrypted_bottom_sheet_title">Mandatory encryption</string>
|
||||
<string name="conversation_warning_disabled_encrypted_bottom_sheet_message"></string>
|
||||
<string name="conversation_warning_disabled_encrypted_bottom_sheet_message">You enabled mandatory encryption. Non encrypted conversations are disabled for your safety. You can re-create this conversation or disable mandatory encryption in your account parameters.</string>
|
||||
<string name="conversation_maximum_number_of_attachments_reached">Maximum number of attachments reached!</string>
|
||||
<string name="conversation_dialog_set_subject">Set conversation subject</string>
|
||||
<string name="conversation_dialog_edit_subject">Edit conversation subject</string>
|
||||
<string name="conversation_dialog_subject_hint">Conversation subject</string>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue