Moved incoming chat message notif to Manager to display it even if app is in background
This commit is contained in:
parent
5101fdc213
commit
ce887b3ef0
3 changed files with 27 additions and 22 deletions
|
@ -721,24 +721,7 @@ public class LinphoneActivity extends FragmentActivity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessageReceived(LinphoneAddress from, LinphoneChatMessage message) {
|
public void onMessageReceived(LinphoneAddress from, LinphoneChatMessage message, int id) {
|
||||||
if (getResources().getBoolean(R.bool.disable_chat)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String textMessage = message.getMessage();
|
|
||||||
String url = message.getExternalBodyUrl();
|
|
||||||
String notificationText = null;
|
|
||||||
int id = -1;
|
|
||||||
if (textMessage != null && textMessage.length() > 0) {
|
|
||||||
id = getChatStorage().saveMessage(from.asStringUriOnly(), "", textMessage);
|
|
||||||
notificationText = textMessage;
|
|
||||||
} else if (url != null && url.length() > 0) {
|
|
||||||
Bitmap bm = ChatFragment.downloadImage(url);
|
|
||||||
id = getChatStorage().saveMessage(from.asStringUriOnly(), "", bm);
|
|
||||||
notificationText = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
ChatFragment chatFragment = ((ChatFragment) messageListenerFragment);
|
ChatFragment chatFragment = ((ChatFragment) messageListenerFragment);
|
||||||
if (messageListenerFragment != null && messageListenerFragment.isVisible() && chatFragment.getSipUri().equals(from.asStringUriOnly())) {
|
if (messageListenerFragment != null && messageListenerFragment.isVisible() && chatFragment.getSipUri().equals(from.asStringUriOnly())) {
|
||||||
chatFragment.onMessageReceived(id, from, message);
|
chatFragment.onMessageReceived(id, from, message);
|
||||||
|
@ -749,8 +732,6 @@ public class LinphoneActivity extends FragmentActivity implements
|
||||||
((ChatListFragment) messageListFragment).refresh();
|
((ChatListFragment) messageListFragment).refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LinphoneUtils.findUriPictureOfContactAndSetDisplayName(from, getContentResolver());
|
|
||||||
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), from.getDisplayName(), notificationText);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateMissedChatCount() {
|
public void updateMissedChatCount() {
|
||||||
|
|
|
@ -86,6 +86,7 @@ import android.content.SharedPreferences;
|
||||||
import android.content.SharedPreferences.Editor;
|
import android.content.SharedPreferences.Editor;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.hardware.Sensor;
|
import android.hardware.Sensor;
|
||||||
import android.hardware.SensorEvent;
|
import android.hardware.SensorEvent;
|
||||||
import android.hardware.SensorEventListener;
|
import android.hardware.SensorEventListener;
|
||||||
|
@ -920,8 +921,31 @@ public final class LinphoneManager implements LinphoneCoreListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) {
|
public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) {
|
||||||
|
if (mServiceContext.getResources().getBoolean(R.bool.disable_chat)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LinphoneAddress from = message.getFrom();
|
||||||
|
ChatStorage chatStorage = new ChatStorage(mServiceContext);
|
||||||
|
|
||||||
|
String textMessage = message.getMessage();
|
||||||
|
String url = message.getExternalBodyUrl();
|
||||||
|
String notificationText = null;
|
||||||
|
int id = -1;
|
||||||
|
if (textMessage != null && textMessage.length() > 0) {
|
||||||
|
id = chatStorage.saveMessage(from.asStringUriOnly(), "", textMessage);
|
||||||
|
notificationText = textMessage;
|
||||||
|
} else if (url != null && url.length() > 0) {
|
||||||
|
Bitmap bm = ChatFragment.downloadImage(url);
|
||||||
|
id = chatStorage.saveMessage(from.asStringUriOnly(), "", bm);
|
||||||
|
notificationText = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
LinphoneUtils.findUriPictureOfContactAndSetDisplayName(from, mServiceContext.getContentResolver());
|
||||||
|
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), from.getDisplayName(), notificationText);
|
||||||
|
|
||||||
for (LinphoneSimpleListener listener : getSimpleListeners(LinphoneActivity.class)) {
|
for (LinphoneSimpleListener listener : getSimpleListeners(LinphoneActivity.class)) {
|
||||||
((LinphoneOnMessageReceivedListener) listener).onMessageReceived(message.getFrom(), message);
|
((LinphoneOnMessageReceivedListener) listener).onMessageReceived(from, message, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ public interface LinphoneSimpleListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static interface LinphoneOnMessageReceivedListener extends LinphoneSimpleListener {
|
public static interface LinphoneOnMessageReceivedListener extends LinphoneSimpleListener {
|
||||||
void onMessageReceived(LinphoneAddress from, LinphoneChatMessage message);
|
void onMessageReceived(LinphoneAddress from, LinphoneChatMessage message, int id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static interface LinphoneOnRegistrationStateChangedListener extends LinphoneSimpleListener {
|
public static interface LinphoneOnRegistrationStateChangedListener extends LinphoneSimpleListener {
|
||||||
|
|
Loading…
Reference in a new issue