Added retry button to chat message context menu

This commit is contained in:
Sylvain Berfini 2014-03-06 10:40:57 +01:00
parent e1ce793b77
commit 81f51960e6
10 changed files with 87 additions and 16 deletions

View file

@ -30,7 +30,7 @@
<TextView <TextView
android:id="@+id/time" android:id="@+id/time"
android:textColor="@android:color/darker_gray" android:textColor="@android:color/darker_gray"
android:textSize="12dp" android:textSize="12sp"
android:gravity="bottom" android:gravity="bottom"
android:singleLine="true" android:singleLine="true"
android:paddingLeft="5dp" android:paddingLeft="5dp"

View file

@ -16,7 +16,7 @@
<TextView <TextView
android:id="@+id/time" android:id="@+id/time"
android:textColor="@android:color/darker_gray" android:textColor="@android:color/darker_gray"
android:textSize="12dp" android:textSize="12sp"
android:gravity="bottom" android:gravity="bottom"
android:singleLine="true" android:singleLine="true"
android:paddingRight="5dp" android:paddingRight="5dp"

View file

@ -29,7 +29,7 @@
<TextView <TextView
android:id="@+id/time" android:id="@+id/time"
android:textColor="@android:color/darker_gray" android:textColor="@android:color/darker_gray"
android:textSize="12dp" android:textSize="12sp"
android:singleLine="true" android:singleLine="true"
android:paddingLeft="5dp" android:paddingLeft="5dp"
android:linksClickable="true" android:linksClickable="true"

View file

@ -37,7 +37,7 @@
<TextView <TextView
android:id="@+id/time" android:id="@+id/time"
android:textColor="@android:color/darker_gray" android:textColor="@android:color/darker_gray"
android:textSize="12dp" android:textSize="12sp"
android:singleLine="true" android:singleLine="true"
android:paddingRight="5dp" android:paddingRight="5dp"
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -393,4 +393,6 @@
<string name="remote_composing">Votre correspondant est en train de taper...</string> <string name="remote_composing">Votre correspondant est en train de taper...</string>
<string name="unread_messages">%i messages non lus</string> <string name="unread_messages">%i messages non lus</string>
<string name="retry">Renvoyer</string>
</resources> </resources>

View file

@ -448,4 +448,6 @@
<string name="remote_composing">Remote is writing...</string> <string name="remote_composing">Remote is writing...</string>
<string name="unread_messages">%i unread messages</string> <string name="unread_messages">%i unread messages</string>
<string name="retry">Retry</string>
</resources> </resources>

View file

@ -446,4 +446,6 @@
<string name="remote_composing">Remote is writing...</string> <string name="remote_composing">Remote is writing...</string>
<string name="unread_messages">%i unread messages</string> <string name="unread_messages">%i unread messages</string>
<string name="retry">Retry</string>
</resources> </resources>

View file

@ -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_LARGE = 4;
private static final int MENU_PICTURE_REAL = 5; private static final int MENU_PICTURE_REAL = 5;
private static final int MENU_COPY_TEXT = 6; 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 COMPRESSOR_QUALITY = 100;
private static final int SIZE_SMALL = 500; private static final int SIZE_SMALL = 500;
private static final int SIZE_MEDIUM = 1000; private static final int SIZE_MEDIUM = 1000;
@ -509,6 +510,11 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
} else { } else {
menu.add(v.getId(), MENU_COPY_TEXT, 0, getString(R.string.copy_text)); 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()) { switch (item.getItemId()) {
case MENU_DELETE_MESSAGE: case MENU_DELETE_MESSAGE:
LinphoneActivity.instance().getChatStorage().deleteMessage(chatRoom, item.getGroupId()); LinphoneActivity.instance().getChatStorage().deleteMessage(chatRoom, item.getGroupId());
for (int i = 0; i < messagesLayout.getChildCount(); i++) { hideMessageBubble(item.getGroupId());
View v = messagesLayout.getChildAt(i);
if (v.getId() == item.getGroupId()) {
v.setVisibility(View.GONE);
break;
}
}
break; break;
case MENU_SAVE_PICTURE: case MENU_SAVE_PICTURE:
saveImage(item.getGroupId()); saveImage(item.getGroupId());
@ -543,6 +543,9 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
case MENU_PICTURE_REAL: case MENU_PICTURE_REAL:
uploadAndSendImage(fileToUploadPath, imageToUpload, ImageSize.REAL); uploadAndSendImage(fileToUploadPath, imageToUpload, ImageSize.REAL);
break; break;
case MENU_RESEND_MESSAGE:
resendMessage(item.getGroupId());
break;
} }
return true; return true;
} }
@ -618,13 +621,15 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
} }
private void sendTextMessage() { private void sendTextMessage() {
sendTextMessage(message.getText().toString());
message.setText("");
}
private void sendTextMessage(String messageToSend) {
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
boolean isNetworkReachable = lc == null ? false : lc.isNetworkReachable(); boolean isNetworkReachable = lc == null ? false : lc.isNetworkReachable();
if (chatRoom != null && message != null && message.getText().length() > 0 && isNetworkReachable) { if (chatRoom != null && messageToSend != null && messageToSend.length() > 0 && isNetworkReachable) {
String messageToSend = message.getText().toString();
message.setText("");
LinphoneChatMessage chatMessage = chatRoom.createLinphoneChatMessage(messageToSend); LinphoneChatMessage chatMessage = chatRoom.createLinphoneChatMessage(messageToSend);
chatRoom.sendMessage(chatMessage, this); 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() { private void scrollToEnd() {
messagesScrollView.postDelayed(new Runnable() { messagesScrollView.postDelayed(new Runnable() {
@Override @Override

View file

@ -353,6 +353,18 @@ public class ChatStorage {
return message; 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) { public void removeDiscussion(String correspondent) {
if (useNativeAPI) { if (useNativeAPI) {
LinphoneChatRoom chatroom = LinphoneManager.getLc().getOrCreateChatRoom(correspondent); LinphoneChatRoom chatroom = LinphoneManager.getLc().getOrCreateChatRoom(correspondent);

View file

@ -92,12 +92,14 @@ public class BubbleChat {
private String imageUrl, textMessage; private String imageUrl, textMessage;
private LinphoneChatMessage.State state; private LinphoneChatMessage.State state;
private LinphoneChatMessage nativeMessage; 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); view = new RelativeLayout(context);
imageUrl = url; imageUrl = url;
textMessage = message; textMessage = message;
state = status; state = status;
id = ID;
LayoutParams layoutParams = new LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams layoutParams = new LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
@ -325,4 +327,8 @@ public class BubbleChat {
public void setNativeMessageObject(LinphoneChatMessage message) { public void setNativeMessageObject(LinphoneChatMessage message) {
nativeMessage = message; nativeMessage = message;
} }
public int getId() {
return id;
}
} }