Fix chat messages misbehaviour
This commit is contained in:
parent
606b19b15c
commit
7581e5a2b8
4 changed files with 15 additions and 11 deletions
|
@ -24,6 +24,7 @@
|
|||
<ImageView
|
||||
android:id="@+id/switchCamera"
|
||||
android:visibility="gone"
|
||||
android:paddingTop="20dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
|
|
|
@ -180,8 +180,13 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneO
|
|||
@Override
|
||||
public void onMessageReceived(LinphoneAddress from, String message) {
|
||||
if (from.asStringUriOnly().equals(sipUri)) {
|
||||
displayMessage(previousMessageID + 1, message, getString(R.string.now_date_format), true, messagesLayout);
|
||||
int id = previousMessageID + 1;
|
||||
displayMessage(id, message, getString(R.string.now_date_format), true, messagesLayout);
|
||||
scrollToEnd();
|
||||
}
|
||||
}
|
||||
|
||||
public String getSipUri() {
|
||||
return sipUri;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public class ChatStorage {
|
|||
db.close();
|
||||
}
|
||||
|
||||
public void saveMessage(String from, String to, String message) {
|
||||
public int saveMessage(String from, String to, String message) {
|
||||
ContentValues values = new ContentValues();
|
||||
if (from.equals("")) {
|
||||
values.put("localContact", from);
|
||||
|
@ -62,7 +62,7 @@ public class ChatStorage {
|
|||
values.put("message", message);
|
||||
values.put("read", NOT_READ);
|
||||
values.put("time", System.currentTimeMillis());
|
||||
db.insert(TABLE_NAME, null, values);
|
||||
return (int) db.insert(TABLE_NAME, null, values);
|
||||
}
|
||||
|
||||
public List<ChatMessage> getMessages(String correspondent) {
|
||||
|
|
|
@ -415,14 +415,13 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
|||
chatStorage = new ChatStorage(this);
|
||||
}
|
||||
|
||||
chatStorage.saveMessage(from.asStringUriOnly(), "", message);
|
||||
int id = chatStorage.saveMessage(from.asStringUriOnly(), "", message);
|
||||
|
||||
Log.d("Message received from " + from + ": " + message);
|
||||
if (messageListenerFragment != null && messageListenerFragment.isVisible()) {
|
||||
((ChatFragment) messageListenerFragment).onMessageReceived(from, message);
|
||||
}
|
||||
|
||||
if (LinphoneService.isReady()) {
|
||||
ChatFragment chatFragment = ((ChatFragment) messageListenerFragment);
|
||||
if (messageListenerFragment != null && messageListenerFragment.isVisible() && chatFragment.getSipUri().equals(from.asStringUriOnly())) {
|
||||
chatFragment.onMessageReceived(from, message);
|
||||
chatStorage.markMessageAsRead(id);
|
||||
} else if (LinphoneService.isReady()) {
|
||||
LinphoneUtils.findUriPictureOfContactAndSetDisplayName(from, getContentResolver());
|
||||
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), from.getDisplayName(), message);
|
||||
displayMissedChats(chatStorage.getUnreadMessageCount());
|
||||
|
@ -443,7 +442,6 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
|||
}
|
||||
|
||||
chatStorage.saveMessage("", to, message);
|
||||
Log.d("Message sent to " + to + ": " + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue