Improved multi content messages handling

This commit is contained in:
Sylvain Berfini 2019-02-14 11:36:38 +01:00
parent 83dbf54c9d
commit ac2ddf83b4
2 changed files with 24 additions and 4 deletions

View file

@ -1050,11 +1050,17 @@ public class ChatMessagesFragment extends Fragment
/** Message sending */ /** Message sending */
private void sendMessage() { private void sendMessage() {
ChatMessage msg = mChatRoom.createEmptyMessage(); ChatMessage msg = mChatRoom.createEmptyMessage();
boolean isBasicChatRoom = mChatRoom.hasCapability(ChatRoomCapabilities.Basic.toInt());
boolean sendMultipleImagesAsDifferentMessages =
getResources().getBoolean(R.bool.send_multiple_images_as_different_messages);
boolean sendImageAndTextAsDifferentMessages =
getResources().getBoolean(R.bool.send_text_and_images_as_different_messages);
String text = mMessageTextToSend.getText().toString(); String text = mMessageTextToSend.getText().toString();
boolean hasText = text != null && text.length() > 0; boolean hasText = text != null && text.length() > 0;
for (int i = 0; i < mFilesUploadLayout.getChildCount(); i++) { int filesCount = mFilesUploadLayout.getChildCount();
for (int i = 0; i < filesCount; i++) {
String filePath = (String) mFilesUploadLayout.getChildAt(i).getTag(); String filePath = (String) mFilesUploadLayout.getChildAt(i).getTag();
String fileName = filePath.substring(filePath.lastIndexOf("/") + 1); String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
String extension = FileUtils.getExtensionFromFileName(fileName); String extension = FileUtils.getExtensionFromFileName(fileName);
@ -1068,8 +1074,21 @@ public class ChatMessagesFragment extends Fragment
content.setName(fileName); content.setName(fileName);
content.setFilePath(filePath); // Let the file body handler take care of the upload content.setFilePath(filePath); // Let the file body handler take care of the upload
if (getResources().getBoolean(R.bool.send_text_and_images_as_different_messages) boolean split =
&& (mFilesUploadLayout.getChildCount() > 1 || hasText)) { isBasicChatRoom; // Always split contents in basic chat rooms for compatibility
if (hasText && sendImageAndTextAsDifferentMessages) {
split = true;
} else if (mFilesUploadLayout.getChildCount() > 1
&& sendMultipleImagesAsDifferentMessages) {
split = true;
// Allow the last image to be sent with text if image and text at the same time OK
if (hasText && !sendImageAndTextAsDifferentMessages && i == filesCount - 1) {
split = false;
}
}
if (split) {
ChatMessage fileMessage = mChatRoom.createFileTransferMessage(content); ChatMessage fileMessage = mChatRoom.createFileTransferMessage(content);
fileMessage.send(); fileMessage.send();
} else { } else {

View file

@ -96,7 +96,8 @@
<string name="temp_photo_name_with_date">linphone-android-photo-%s</string> <string name="temp_photo_name_with_date">linphone-android-photo-%s</string>
<bool name="lower_space_between_chat_bubbles_if_same_person">true</bool> <bool name="lower_space_between_chat_bubbles_if_same_person">true</bool>
<bool name="allow_multiple_images_and_text">true</bool> <bool name="allow_multiple_images_and_text">true</bool>
<bool name="send_text_and_images_as_different_messages">true</bool> <bool name="send_text_and_images_as_different_messages">false</bool>
<bool name="send_multiple_images_as_different_messages">true</bool>
<bool name="use_new_chat_bubbles_layout">true</bool> <bool name="use_new_chat_bubbles_layout">true</bool>
<bool name="use_big_pictures_to_preview_images_file_transfers">true</bool> <bool name="use_big_pictures_to_preview_images_file_transfers">true</bool>