From 6476bb518dbe197cd2cf4aefe5f9e5c7bd0ad8b0 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Sat, 7 Dec 2024 21:14:34 +0100 Subject: [PATCH] Added sub menu for file picker in conversation to allow picking files other than media --- .../chat/fragment/ConversationFragment.kt | 22 ++++- .../chat/viewmodel/ConversationViewModel.kt | 2 + .../SendMessageInConversationViewModel.kt | 28 ++++++ .../layout/chat_conversation_file_pickers.xml | 86 +++++++++++++++++++ .../res/layout/chat_conversation_fragment.xml | 8 +- .../layout/chat_conversation_send_area.xml | 70 +++++++-------- app/src/main/res/values-fr/strings.xml | 3 + app/src/main/res/values/strings.xml | 5 +- 8 files changed, 180 insertions(+), 44 deletions(-) create mode 100644 app/src/main/res/layout/chat_conversation_file_pickers.xml diff --git a/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationFragment.kt b/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationFragment.kt index c74fb33d3..10b210fa0 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationFragment.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/fragment/ConversationFragment.kt @@ -126,6 +126,7 @@ open class ConversationFragment : SlidingPaneChildFragment() { maxItems = SendMessageInConversationViewModel.MAX_FILES_TO_ATTACH ) ) { list -> + sendMessageViewModel.closeFilePickerBottomSheet() if (list.isNotEmpty()) { for (uri in list) { lifecycleScope.launch { @@ -147,9 +148,21 @@ open class ConversationFragment : SlidingPaneChildFragment() { private var pendingImageCaptureFile: File? = null + private val pickDocument = registerForActivityResult( + ActivityResultContracts.OpenMultipleDocuments() + ) { files -> + sendMessageViewModel.closeFilePickerBottomSheet() + for (fileUri in files) { + val path = fileUri.toString() + Log.i("$TAG Picked file [$path]") + sendMessageViewModel.addAttachment(path) + } + } + private val startCameraCapture = registerForActivityResult( ActivityResultContracts.TakePicture() ) { captured -> + sendMessageViewModel.closeFilePickerBottomSheet() val path = pendingImageCaptureFile?.absolutePath if (path != null) { if (captured) { @@ -257,13 +270,13 @@ open class ConversationFragment : SlidingPaneChildFragment() { } override fun afterTextChanged(p0: Editable?) { - sendMessageViewModel.isParticipantsListOpen.value = false + sendMessageViewModel.closeParticipantsList() val split = p0.toString().split(" ") for (part in split) { if (part == "@") { Log.i("$TAG '@' found, opening participants list") - sendMessageViewModel.isParticipantsListOpen.value = true + sendMessageViewModel.openParticipantsList() } } } @@ -608,6 +621,11 @@ open class ConversationFragment : SlidingPaneChildFragment() { } binding.setOpenFilePickerClickListener { + Log.i("$TAG Opening file picker") + pickDocument.launch(arrayOf("*/*")) + } + + binding.setOpenMediaPickerClickListener { Log.i("$TAG Opening media picker") pickMedia.launch( PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageAndVideo) diff --git a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationViewModel.kt b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationViewModel.kt index 6db7d18c9..b87c6747f 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/ConversationViewModel.kt @@ -323,6 +323,7 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo itemToScrollTo.value = -1 } + @UiThread override fun onCleared() { super.onCleared() @@ -335,6 +336,7 @@ class ConversationViewModel @UiThread constructor() : AbstractConversationViewMo } } + @WorkerThread override fun beforeNotifyingChatRoomFound(sameOne: Boolean) { if (!sameOne) { Log.i("$TAG Conversation found and not the same as before, configuring it...") diff --git a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/SendMessageInConversationViewModel.kt b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/SendMessageInConversationViewModel.kt index ebadf511a..7ced4921b 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/viewmodel/SendMessageInConversationViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/viewmodel/SendMessageInConversationViewModel.kt @@ -70,6 +70,8 @@ class SendMessageInConversationViewModel @UiThread constructor() : GenericViewMo val isEmojiPickerOpen = MutableLiveData() + val areFilePickersOpen = MutableLiveData() + val isParticipantsListOpen = MutableLiveData() val participants = MutableLiveData>() @@ -151,6 +153,7 @@ class SendMessageInConversationViewModel @UiThread constructor() : GenericViewMo } isEmojiPickerOpen.value = false + areFilePickersOpen.value = false isPlayingVoiceRecord.value = false isCallConversation.value = false maxNumberOfAttachmentsReached.value = false @@ -199,6 +202,8 @@ class SendMessageInConversationViewModel @UiThread constructor() : GenericViewMo if (isEmojiPickerOpen.value == true) { requestKeyboardHidingEvent.value = Event(true) } + closeFilePickerBottomSheet() + closeParticipantsList() } @UiThread @@ -206,6 +211,18 @@ class SendMessageInConversationViewModel @UiThread constructor() : GenericViewMo emojiToAddEvent.value = Event(emoji) } + @UiThread + fun toggleFilePickersVisibility() { + areFilePickersOpen.value = areFilePickersOpen.value == false + isEmojiPickerOpen.value = false + closeParticipantsList() + } + + @UiThread + fun closeFilePickerBottomSheet() { + areFilePickersOpen.value = false + } + @UiThread fun replyToMessage(model: MessageModel) { coreContext.postOnCoreThread { @@ -302,6 +319,13 @@ class SendMessageInConversationViewModel @UiThread constructor() : GenericViewMo } } + @UiThread + fun openParticipantsList() { + isParticipantsListOpen.value = true + isEmojiPickerOpen.value = false + closeFilePickerBottomSheet() + } + @UiThread fun closeParticipantsList() { isParticipantsListOpen.value = false @@ -418,6 +442,10 @@ class SendMessageInConversationViewModel @UiThread constructor() : GenericViewMo return } + isEmojiPickerOpen.value = false + closeFilePickerBottomSheet() + closeParticipantsList() + coreContext.postOnCoreThread { requestKeyboardHidingEvent.postValue(Event(true)) isVoiceRecording.postValue(true) diff --git a/app/src/main/res/layout/chat_conversation_file_pickers.xml b/app/src/main/res/layout/chat_conversation_file_pickers.xml new file mode 100644 index 000000000..db5d50d69 --- /dev/null +++ b/app/src/main/res/layout/chat_conversation_file_pickers.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/chat_conversation_fragment.xml b/app/src/main/res/layout/chat_conversation_fragment.xml index 8e52ac4ea..8648a3352 100644 --- a/app/src/main/res/layout/chat_conversation_fragment.xml +++ b/app/src/main/res/layout/chat_conversation_fragment.xml @@ -15,11 +15,14 @@ name="showMenuClickListener" type="View.OnClickListener" /> + @@ -313,8 +316,9 @@ android:visibility="@{viewModel.isReadOnly || viewModel.isDisabledBecauseNotSecured || viewModel.searchBarVisible ? View.GONE : View.VISIBLE}" layout="@layout/chat_conversation_send_area" app:layout_constraintBottom_toBottomOf="parent" - bind:openFilePickerClickListener="@{openFilePickerClickListener}" + bind:openMediaPickerClickListener="@{openMediaPickerClickListener}" bind:openCameraClickListener="@{openCameraClickListener}" + bind:openFilePickerClickListener="@{openFilePickerClickListener}" bind:viewModel="@{sendMessageViewModel}"/> + @@ -29,13 +32,6 @@ android:visibility="@{viewModel.isVoiceRecording ? View.INVISIBLE : View.VISIBLE}" app:constraint_referenced_ids="attach_file, message_area_background, message_to_send" /> - - - - + + + + + app:constraint_referenced_ids="file_pickers, emoji_picker, participants, attachments, reply_area" /> - - @@ -133,7 +125,7 @@ android:contentDescription="@null" app:layout_constraintBottom_toBottomOf="@id/message_to_send" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toEndOf="@id/capture_image" + app:layout_constraintStart_toEndOf="@id/attach_file" app:layout_constraintTop_toTopOf="@id/message_to_send" /> Conversation non trouvée Aucun résultat trouvé Dernier résultat atteint + Prendre une photo + Ouvrir la gallerie + Choisir un fichier Membres du groupe (%s) Ajouter des membres diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c75065098..9c133fbd1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -514,6 +514,9 @@ Conversation was not found No matching result found Last matching result reached + Take picture + Open gallery + Pick file Group members (%s) Add participants @@ -857,7 +860,7 @@ Sends message in conversation Message will no longer be a reply to a previous message Opens emoji picker - Opens media picker + Opens file picker Opens camera to take a picture Click to edit the subject of this conversation Silences on/off this conversation