Fix issue 1031 (chat message status icon not updated if it's not the last one sent)
This commit is contained in:
parent
24bf8520ed
commit
cd7c95ce72
2 changed files with 59 additions and 16 deletions
|
@ -111,7 +111,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
private LinphoneScrollView messagesScrollView;
|
private LinphoneScrollView messagesScrollView;
|
||||||
private int previousMessageID;
|
private int previousMessageID;
|
||||||
private Handler mHandler = new Handler();
|
private Handler mHandler = new Handler();
|
||||||
private BubbleChat lastSentMessageBubble;
|
private List<BubbleChat> lastSentMessagesBubbles;
|
||||||
private HashMap<Integer, String> latestImageMessages;
|
private HashMap<Integer, String> latestImageMessages;
|
||||||
private int messagesFilterLimit = 0;
|
private int messagesFilterLimit = 0;
|
||||||
private boolean useLinphoneMessageStorage;
|
private boolean useLinphoneMessageStorage;
|
||||||
|
@ -366,15 +366,17 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayMessage(int id, String message, long time, boolean isIncoming, LinphoneChatMessage.State status, RelativeLayout layout) {
|
private BubbleChat displayMessage(int id, String message, long time, boolean isIncoming, LinphoneChatMessage.State status, RelativeLayout layout) {
|
||||||
displayMessage(id, message, time, isIncoming, status, layout, true);
|
return displayMessage(id, message, time, isIncoming, status, layout, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayMessage(int id, String message, long time, boolean isIncoming, LinphoneChatMessage.State status, RelativeLayout layout, boolean show) {
|
private BubbleChat displayMessage(int id, String message, long time, boolean isIncoming, LinphoneChatMessage.State status, RelativeLayout layout, boolean show) {
|
||||||
id = checkId(id);
|
id = checkId(id);
|
||||||
BubbleChat bubble = new BubbleChat(layout.getContext(), id, message, null, time, isIncoming, status, null, previousMessageID);
|
BubbleChat bubble = new BubbleChat(layout.getContext(), id, message, null, time, isIncoming, status, null, previousMessageID);
|
||||||
if (!isIncoming) {
|
if (!isIncoming) {
|
||||||
lastSentMessageBubble = bubble;
|
if (lastSentMessagesBubbles == null)
|
||||||
|
lastSentMessagesBubbles = new ArrayList<BubbleChat>();
|
||||||
|
lastSentMessagesBubbles.add(bubble);
|
||||||
}
|
}
|
||||||
|
|
||||||
View v = bubble.getView();
|
View v = bubble.getView();
|
||||||
|
@ -385,16 +387,21 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
previousMessageID = id;
|
previousMessageID = id;
|
||||||
layout.addView(v);
|
layout.addView(v);
|
||||||
registerForContextMenu(v);
|
registerForContextMenu(v);
|
||||||
}
|
|
||||||
private void displayImageMessage(int id, Bitmap image, long time, boolean isIncoming, LinphoneChatMessage.State status, RelativeLayout layout, final String url) {
|
return bubble;
|
||||||
displayImageMessage(id, image, time, isIncoming, status, layout, url, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayImageMessage(int id, Bitmap image, long time, boolean isIncoming, LinphoneChatMessage.State status, RelativeLayout layout, final String url, boolean show) {
|
private BubbleChat displayImageMessage(int id, Bitmap image, long time, boolean isIncoming, LinphoneChatMessage.State status, RelativeLayout layout, final String url) {
|
||||||
|
return displayImageMessage(id, image, time, isIncoming, status, layout, url, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private BubbleChat displayImageMessage(int id, Bitmap image, long time, boolean isIncoming, LinphoneChatMessage.State status, RelativeLayout layout, final String url, boolean show) {
|
||||||
id = checkId(id);
|
id = checkId(id);
|
||||||
final BubbleChat bubble = new BubbleChat(layout.getContext(), id, null, image, time, isIncoming, status, url, previousMessageID);
|
final BubbleChat bubble = new BubbleChat(layout.getContext(), id, null, image, time, isIncoming, status, url, previousMessageID);
|
||||||
if (!isIncoming) {
|
if (!isIncoming) {
|
||||||
lastSentMessageBubble = bubble;
|
if (lastSentMessagesBubbles == null)
|
||||||
|
lastSentMessagesBubbles = new ArrayList<BubbleChat>();
|
||||||
|
lastSentMessagesBubbles.add(bubble);
|
||||||
}
|
}
|
||||||
|
|
||||||
final View v = bubble.getView();
|
final View v = bubble.getView();
|
||||||
|
@ -457,6 +464,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
previousMessageID = id;
|
previousMessageID = id;
|
||||||
layout.addView(v);
|
layout.addView(v);
|
||||||
registerForContextMenu(v);
|
registerForContextMenu(v);
|
||||||
|
|
||||||
|
return bubble;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeDisplayedChat(String newSipUri, String displayName, String pictureUri) {
|
public void changeDisplayedChat(String newSipUri, String displayName, String pictureUri) {
|
||||||
|
@ -601,7 +610,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
newId = LinphoneActivity.instance().onMessageSent(sipUri, messageToSend);
|
newId = LinphoneActivity.instance().onMessageSent(sipUri, messageToSend);
|
||||||
}
|
}
|
||||||
|
|
||||||
displayMessage(newId, messageToSend, System.currentTimeMillis(), false, State.InProgress, messagesLayout);
|
BubbleChat bubble = displayMessage(newId, messageToSend, System.currentTimeMillis(), false, State.InProgress, messagesLayout);
|
||||||
|
bubble.setNativeMessageObject(chatMessage);
|
||||||
scrollToEnd();
|
scrollToEnd();
|
||||||
} else if (!isNetworkReachable && LinphoneActivity.isInstanciated()) {
|
} else if (!isNetworkReachable && LinphoneActivity.isInstanciated()) {
|
||||||
LinphoneActivity.instance().displayCustomToast(getString(R.string.error_network_unreachable), Toast.LENGTH_LONG);
|
LinphoneActivity.instance().displayCustomToast(getString(R.string.error_network_unreachable), Toast.LENGTH_LONG);
|
||||||
|
@ -627,7 +637,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
if (useLinphoneMessageStorage)
|
if (useLinphoneMessageStorage)
|
||||||
url = saveImage(bitmap, newId, chatMessage);
|
url = saveImage(bitmap, newId, chatMessage);
|
||||||
|
|
||||||
displayImageMessage(newId, bitmap, System.currentTimeMillis(), false, State.InProgress, messagesLayout, url);
|
BubbleChat bubble = displayImageMessage(newId, bitmap, System.currentTimeMillis(), false, State.InProgress, messagesLayout, url);
|
||||||
|
bubble.setNativeMessageObject(chatMessage);
|
||||||
scrollToEnd();
|
scrollToEnd();
|
||||||
} else if (!isNetworkReachable && LinphoneActivity.isInstanciated()) {
|
} else if (!isNetworkReachable && LinphoneActivity.isInstanciated()) {
|
||||||
LinphoneActivity.instance().displayCustomToast(getString(R.string.error_network_unreachable), Toast.LENGTH_LONG);
|
LinphoneActivity.instance().displayCustomToast(getString(R.string.error_network_unreachable), Toast.LENGTH_LONG);
|
||||||
|
@ -681,7 +692,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLinphoneChatMessageStateChanged(LinphoneChatMessage msg, State state) {
|
public synchronized void onLinphoneChatMessageStateChanged(LinphoneChatMessage msg, State state) {
|
||||||
final String finalMessage = msg.getText();
|
final String finalMessage = msg.getText();
|
||||||
final String finalImage = msg.getExternalBodyUrl();
|
final String finalImage = msg.getExternalBodyUrl();
|
||||||
final State finalState = state;
|
final State finalState = state;
|
||||||
|
@ -706,8 +717,13 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (lastSentMessageBubble != null) {
|
|
||||||
lastSentMessageBubble.updateStatusView(finalState);
|
if (lastSentMessagesBubbles != null && lastSentMessagesBubbles.size() > 0) {
|
||||||
|
for (BubbleChat bubble : lastSentMessagesBubbles) {
|
||||||
|
if (bubble.getStatus() == State.InProgress || bubble.getStatus() == State.Idle) {
|
||||||
|
bubble.updateStatusView(bubble.getNativeMessageObject().getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.util.Map.Entry;
|
||||||
import org.linphone.LinphoneUtils;
|
import org.linphone.LinphoneUtils;
|
||||||
import org.linphone.R;
|
import org.linphone.R;
|
||||||
import org.linphone.core.LinphoneChatMessage;
|
import org.linphone.core.LinphoneChatMessage;
|
||||||
|
import org.linphone.core.LinphoneChatMessage.State;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
@ -88,11 +89,15 @@ public class BubbleChat {
|
||||||
private RelativeLayout view;
|
private RelativeLayout view;
|
||||||
private ImageView statusView;
|
private ImageView statusView;
|
||||||
private Button downloadOrShow;
|
private Button downloadOrShow;
|
||||||
private String imageUrl;
|
private String imageUrl, textMessage;
|
||||||
|
private LinphoneChatMessage.State state;
|
||||||
|
private LinphoneChatMessage nativeMessage;
|
||||||
|
|
||||||
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;
|
||||||
|
state = status;
|
||||||
|
|
||||||
LayoutParams layoutParams = new LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
LayoutParams layoutParams = new LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||||
|
|
||||||
|
@ -198,6 +203,8 @@ public class BubbleChat {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateStatusView(LinphoneChatMessage.State status) {
|
public void updateStatusView(LinphoneChatMessage.State status) {
|
||||||
|
state = status;
|
||||||
|
|
||||||
if (statusView == null) {
|
if (statusView == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -298,4 +305,24 @@ public class BubbleChat {
|
||||||
public void updateUrl(String newFileUrl) {
|
public void updateUrl(String newFileUrl) {
|
||||||
imageUrl = newFileUrl;
|
imageUrl = newFileUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTextMessage() {
|
||||||
|
return textMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getImageUrl() {
|
||||||
|
return imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public State getStatus() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinphoneChatMessage getNativeMessageObject() {
|
||||||
|
return nativeMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNativeMessageObject(LinphoneChatMessage message) {
|
||||||
|
nativeMessage = message;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue