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
|
<ImageView
|
||||||
android:id="@+id/switchCamera"
|
android:id="@+id/switchCamera"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
|
android:paddingTop="20dp"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
|
|
|
@ -180,8 +180,13 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneO
|
||||||
@Override
|
@Override
|
||||||
public void onMessageReceived(LinphoneAddress from, String message) {
|
public void onMessageReceived(LinphoneAddress from, String message) {
|
||||||
if (from.asStringUriOnly().equals(sipUri)) {
|
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();
|
scrollToEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSipUri() {
|
||||||
|
return sipUri;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class ChatStorage {
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveMessage(String from, String to, String message) {
|
public int saveMessage(String from, String to, String message) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
if (from.equals("")) {
|
if (from.equals("")) {
|
||||||
values.put("localContact", from);
|
values.put("localContact", from);
|
||||||
|
@ -62,7 +62,7 @@ public class ChatStorage {
|
||||||
values.put("message", message);
|
values.put("message", message);
|
||||||
values.put("read", NOT_READ);
|
values.put("read", NOT_READ);
|
||||||
values.put("time", System.currentTimeMillis());
|
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) {
|
public List<ChatMessage> getMessages(String correspondent) {
|
||||||
|
|
|
@ -415,14 +415,13 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
chatStorage = new ChatStorage(this);
|
chatStorage = new ChatStorage(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
chatStorage.saveMessage(from.asStringUriOnly(), "", message);
|
int id = chatStorage.saveMessage(from.asStringUriOnly(), "", message);
|
||||||
|
|
||||||
Log.d("Message received from " + from + ": " + message);
|
ChatFragment chatFragment = ((ChatFragment) messageListenerFragment);
|
||||||
if (messageListenerFragment != null && messageListenerFragment.isVisible()) {
|
if (messageListenerFragment != null && messageListenerFragment.isVisible() && chatFragment.getSipUri().equals(from.asStringUriOnly())) {
|
||||||
((ChatFragment) messageListenerFragment).onMessageReceived(from, message);
|
chatFragment.onMessageReceived(from, message);
|
||||||
}
|
chatStorage.markMessageAsRead(id);
|
||||||
|
} else if (LinphoneService.isReady()) {
|
||||||
if (LinphoneService.isReady()) {
|
|
||||||
LinphoneUtils.findUriPictureOfContactAndSetDisplayName(from, getContentResolver());
|
LinphoneUtils.findUriPictureOfContactAndSetDisplayName(from, getContentResolver());
|
||||||
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), from.getDisplayName(), message);
|
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), from.getDisplayName(), message);
|
||||||
displayMissedChats(chatStorage.getUnreadMessageCount());
|
displayMissedChats(chatStorage.getUnreadMessageCount());
|
||||||
|
@ -443,7 +442,6 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
|
||||||
}
|
}
|
||||||
|
|
||||||
chatStorage.saveMessage("", to, message);
|
chatStorage.saveMessage("", to, message);
|
||||||
Log.d("Message sent to " + to + ": " + message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue