Added retry button to chat message context menu
This commit is contained in:
parent
e1ce793b77
commit
81f51960e6
10 changed files with 87 additions and 16 deletions
|
@ -30,7 +30,7 @@
|
|||
<TextView
|
||||
android:id="@+id/time"
|
||||
android:textColor="@android:color/darker_gray"
|
||||
android:textSize="12dp"
|
||||
android:textSize="12sp"
|
||||
android:gravity="bottom"
|
||||
android:singleLine="true"
|
||||
android:paddingLeft="5dp"
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<TextView
|
||||
android:id="@+id/time"
|
||||
android:textColor="@android:color/darker_gray"
|
||||
android:textSize="12dp"
|
||||
android:textSize="12sp"
|
||||
android:gravity="bottom"
|
||||
android:singleLine="true"
|
||||
android:paddingRight="5dp"
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
<TextView
|
||||
android:id="@+id/time"
|
||||
android:textColor="@android:color/darker_gray"
|
||||
android:textSize="12dp"
|
||||
android:textSize="12sp"
|
||||
android:singleLine="true"
|
||||
android:paddingLeft="5dp"
|
||||
android:linksClickable="true"
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
<TextView
|
||||
android:id="@+id/time"
|
||||
android:textColor="@android:color/darker_gray"
|
||||
android:textSize="12dp"
|
||||
android:textSize="12sp"
|
||||
android:singleLine="true"
|
||||
android:paddingRight="5dp"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -393,4 +393,6 @@
|
|||
|
||||
<string name="remote_composing">Votre correspondant est en train de taper...</string>
|
||||
<string name="unread_messages">%i messages non lus</string>
|
||||
|
||||
<string name="retry">Renvoyer</string>
|
||||
</resources>
|
||||
|
|
|
@ -448,4 +448,6 @@
|
|||
|
||||
<string name="remote_composing">Remote is writing...</string>
|
||||
<string name="unread_messages">%i unread messages</string>
|
||||
|
||||
<string name="retry">Retry</string>
|
||||
</resources>
|
||||
|
|
|
@ -446,4 +446,6 @@
|
|||
|
||||
<string name="remote_composing">Remote is writing...</string>
|
||||
<string name="unread_messages">%i unread messages</string>
|
||||
|
||||
<string name="retry">Retry</string>
|
||||
</resources>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue