diff --git a/res/layout/chat_bubble_alt_incoming.xml b/res/layout/chat_bubble_alt_incoming.xml index 50919279b..b0f74659c 100644 --- a/res/layout/chat_bubble_alt_incoming.xml +++ b/res/layout/chat_bubble_alt_incoming.xml @@ -30,7 +30,7 @@ Votre correspondant est en train de taper... %i messages non lus + + Renvoyer diff --git a/res/values-RU/strings.xml b/res/values-RU/strings.xml index 584dcc105..09c298f80 100755 --- a/res/values-RU/strings.xml +++ b/res/values-RU/strings.xml @@ -448,4 +448,6 @@ Remote is writing... %i unread messages + + Retry diff --git a/res/values/strings.xml b/res/values/strings.xml index 521c25c7d..1e662fe7e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -446,4 +446,6 @@ Remote is writing... %i unread messages + + Retry diff --git a/src/org/linphone/ChatFragment.java b/src/org/linphone/ChatFragment.java index 88b386072..26059cadb 100644 --- a/src/org/linphone/ChatFragment.java +++ b/src/org/linphone/ChatFragment.java @@ -95,6 +95,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC private static final int MENU_PICTURE_LARGE = 4; private static final int MENU_PICTURE_REAL = 5; private static final int MENU_COPY_TEXT = 6; + private static final int MENU_RESEND_MESSAGE = 7; private static final int COMPRESSOR_QUALITY = 100; private static final int SIZE_SMALL = 500; private static final int SIZE_MEDIUM = 1000; @@ -509,6 +510,11 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC } else { menu.add(v.getId(), MENU_COPY_TEXT, 0, getString(R.string.copy_text)); } + + LinphoneChatMessage msg = getMessageForId(v.getId()); + if (msg != null && msg.getStatus() == LinphoneChatMessage.State.NotDelivered) { + menu.add(v.getId(), MENU_RESEND_MESSAGE, 0, getString(R.string.retry)); + } } } @@ -517,13 +523,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC switch (item.getItemId()) { case MENU_DELETE_MESSAGE: LinphoneActivity.instance().getChatStorage().deleteMessage(chatRoom, item.getGroupId()); - for (int i = 0; i < messagesLayout.getChildCount(); i++) { - View v = messagesLayout.getChildAt(i); - if (v.getId() == item.getGroupId()) { - v.setVisibility(View.GONE); - break; - } - } + hideMessageBubble(item.getGroupId()); break; case MENU_SAVE_PICTURE: saveImage(item.getGroupId()); @@ -543,6 +543,9 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC case MENU_PICTURE_REAL: uploadAndSendImage(fileToUploadPath, imageToUpload, ImageSize.REAL); break; + case MENU_RESEND_MESSAGE: + resendMessage(item.getGroupId()); + break; } return true; } @@ -618,13 +621,15 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC } private void sendTextMessage() { + sendTextMessage(message.getText().toString()); + message.setText(""); + } + + private void sendTextMessage(String messageToSend) { LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); boolean isNetworkReachable = lc == null ? false : lc.isNetworkReachable(); - if (chatRoom != null && message != null && message.getText().length() > 0 && isNetworkReachable) { - String messageToSend = message.getText().toString(); - message.setText(""); - + if (chatRoom != null && messageToSend != null && messageToSend.length() > 0 && isNetworkReachable) { LinphoneChatMessage chatMessage = chatRoom.createLinphoneChatMessage(messageToSend); chatRoom.sendMessage(chatMessage, this); @@ -668,6 +673,48 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC } } + private LinphoneChatMessage getMessageForId(int id) { + LinphoneChatMessage msg = null; + try { + msg = LinphoneActivity.instance().getChatStorage().getMessage(chatRoom, id); + } catch (Exception e) {} + + if (msg == null) { + for (BubbleChat bubble : lastSentMessagesBubbles) { + if (bubble.getId() == id) { + return bubble.getNativeMessageObject(); + } + } + } + + return msg; + } + + private void hideMessageBubble(int id) { + for (int i = 0; i < messagesLayout.getChildCount(); i++) { + View v = messagesLayout.getChildAt(i); + if (v.getId() == id) { + v.setVisibility(View.GONE); + break; + } + } + } + + private void resendMessage(int id) { + LinphoneChatMessage message = getMessageForId(id); + if (message == null) + return; + + LinphoneActivity.instance().getChatStorage().deleteMessage(chatRoom, id); + hideMessageBubble(id); + + if (message.getText() != null && message.getText().length() > 0) { + sendTextMessage(message.getText()); + } else { + sendImageMessage(message.getExternalBodyUrl(), null); + } + } + private void scrollToEnd() { messagesScrollView.postDelayed(new Runnable() { @Override diff --git a/src/org/linphone/ChatStorage.java b/src/org/linphone/ChatStorage.java index f7432598e..b7249e923 100644 --- a/src/org/linphone/ChatStorage.java +++ b/src/org/linphone/ChatStorage.java @@ -353,6 +353,18 @@ public class ChatStorage { return message; } + public LinphoneChatMessage getMessage(LinphoneChatRoom chatroom, int id) { + if (useNativeAPI) { + LinphoneChatMessage[] history = chatroom.getHistory(); + for (LinphoneChatMessage msg : history) { + if (msg.getStorageId() == id) { + return msg; + } + } + } + return null; + } + public void removeDiscussion(String correspondent) { if (useNativeAPI) { LinphoneChatRoom chatroom = LinphoneManager.getLc().getOrCreateChatRoom(correspondent); diff --git a/src/org/linphone/ui/BubbleChat.java b/src/org/linphone/ui/BubbleChat.java index c84670635..e405d0499 100644 --- a/src/org/linphone/ui/BubbleChat.java +++ b/src/org/linphone/ui/BubbleChat.java @@ -92,12 +92,14 @@ public class BubbleChat { private String imageUrl, textMessage; private LinphoneChatMessage.State state; private LinphoneChatMessage nativeMessage; + private int id; - public BubbleChat(final Context context, int id, String message, Bitmap image, long time, boolean isIncoming, LinphoneChatMessage.State status, String url, int previousID) { + public BubbleChat(final Context context, int ID, String message, Bitmap image, long time, boolean isIncoming, LinphoneChatMessage.State status, String url, int previousID) { view = new RelativeLayout(context); imageUrl = url; textMessage = message; state = status; + id = ID; LayoutParams layoutParams = new LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); @@ -325,4 +327,8 @@ public class BubbleChat { public void setNativeMessageObject(LinphoneChatMessage message) { nativeMessage = message; } + + public int getId() { + return id; + } }