Added group chat message notification + some cleanup in notification code
This commit is contained in:
parent
315e4a0ba3
commit
f94ad81a5d
7 changed files with 54 additions and 26 deletions
|
@ -208,6 +208,7 @@
|
||||||
<string name="subject_changed">new subject : %s</string>
|
<string name="subject_changed">new subject : %s</string>
|
||||||
<string name="admin_set">%s is admin</string>
|
<string name="admin_set">%s is admin</string>
|
||||||
<string name="admin_unset">%s is no longer admin</string>
|
<string name="admin_unset">%s is no longer admin</string>
|
||||||
|
<string name="group_chat_notif">%1: %2</string>
|
||||||
|
|
||||||
<!-- Status Bar -->
|
<!-- Status Bar -->
|
||||||
<string name="status_connected">Registered</string>
|
<string name="status_connected">Registered</string>
|
||||||
|
|
|
@ -1229,21 +1229,24 @@ public class LinphoneManager implements CoreListener, ChatMessageListener, Senso
|
||||||
}
|
}
|
||||||
|
|
||||||
Address from = message.getFromAddress();
|
Address from = message.getFromAddress();
|
||||||
String to = message.getToAddress().asString();
|
|
||||||
|
|
||||||
String textMessage = (message.getFileTransferInformation() != null) ?
|
|
||||||
getString(R.string.content_description_incoming_file) : message.getText();
|
|
||||||
try {
|
|
||||||
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(from);
|
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(from);
|
||||||
|
String textMessage = (message.getFileTransferInformation() != null) ? getString(R.string.content_description_incoming_file) : message.getText();
|
||||||
|
|
||||||
if (!mServiceContext.getResources().getBoolean(R.bool.disable_chat_message_notification)) {
|
if (!mServiceContext.getResources().getBoolean(R.bool.disable_chat_message_notification)) {
|
||||||
|
if (cr.canHandleParticipants()) {
|
||||||
|
String subject = cr.getSubject();
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
LinphoneService.instance().displayMessageNotification(to, from.asStringUriOnly(), contact.getFullName(), textMessage);
|
LinphoneService.instance().displayGroupChatMessageNotification(subject, cr.getConferenceAddress().asString(), contact.getFullName(), contact.getThumbnailUri(), textMessage);
|
||||||
} else {
|
} else {
|
||||||
LinphoneService.instance().displayMessageNotification(to, from.asStringUriOnly(), from.getUsername(), textMessage);
|
LinphoneService.instance().displayGroupChatMessageNotification(subject, cr.getConferenceAddress().asString(), from.getUsername(), null, textMessage);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (contact != null) {
|
||||||
|
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), contact.getFullName(), contact.getThumbnailUri(), textMessage);
|
||||||
|
} else {
|
||||||
|
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), from.getUsername(), null, textMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -595,7 +595,36 @@ public final class LinphoneService extends Service {
|
||||||
resetIntentLaunchedOnNotificationClick();
|
resetIntentLaunchedOnNotificationClick();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayMessageNotification(String to, String fromSipUri, String fromName, String message) {
|
public void displayGroupChatMessageNotification(String subject, String conferenceAddress, String fromName, Uri fromPictureUri, String message) {
|
||||||
|
Intent notifIntent = new Intent(this, LinphoneActivity.class);
|
||||||
|
notifIntent.putExtra("GoToChat", true);
|
||||||
|
notifIntent.putExtra("ChatContactSipUri", conferenceAddress);
|
||||||
|
|
||||||
|
PendingIntent notifContentIntent = PendingIntent.getActivity(this, 0, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
|
if (mMsgNotif == null) {
|
||||||
|
mMsgNotifCount = 1;
|
||||||
|
} else {
|
||||||
|
mMsgNotifCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bitmap bm = null;
|
||||||
|
if (fromPictureUri != null) {
|
||||||
|
try {
|
||||||
|
bm = MediaStore.Images.Media.getBitmap(getContentResolver(), fromPictureUri);
|
||||||
|
} catch (Exception e) {
|
||||||
|
bm = BitmapFactory.decodeResource(getResources(), R.drawable.topbar_avatar);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bm = BitmapFactory.decodeResource(getResources(), R.drawable.topbar_avatar);
|
||||||
|
}
|
||||||
|
mMsgNotif = Compatibility.createMessageNotification(getApplicationContext(), mMsgNotifCount, subject,
|
||||||
|
getString(R.string.group_chat_notif).replace("%1", fromName).replace("%2", message), bm, notifContentIntent);
|
||||||
|
|
||||||
|
notifyWrapper(MESSAGE_NOTIF_ID, mMsgNotif);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void displayMessageNotification(String fromSipUri, String fromName, Uri fromPictureUri, String message) {
|
||||||
Intent notifIntent = new Intent(this, LinphoneActivity.class);
|
Intent notifIntent = new Intent(this, LinphoneActivity.class);
|
||||||
notifIntent.putExtra("GoToChat", true);
|
notifIntent.putExtra("GoToChat", true);
|
||||||
notifIntent.putExtra("ChatContactSipUri", fromSipUri);
|
notifIntent.putExtra("ChatContactSipUri", fromSipUri);
|
||||||
|
@ -612,22 +641,17 @@ public final class LinphoneService extends Service {
|
||||||
mMsgNotifCount++;
|
mMsgNotifCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uri pictureUri = null;
|
|
||||||
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(Factory.instance().createAddress(fromSipUri));
|
|
||||||
if (contact != null)
|
|
||||||
pictureUri = contact.getThumbnailUri();
|
|
||||||
|
|
||||||
Bitmap bm = null;
|
Bitmap bm = null;
|
||||||
if (pictureUri != null) {
|
if (fromPictureUri != null) {
|
||||||
try {
|
try {
|
||||||
bm = MediaStore.Images.Media.getBitmap(getContentResolver(), pictureUri);
|
bm = MediaStore.Images.Media.getBitmap(getContentResolver(), fromPictureUri);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
bm = BitmapFactory.decodeResource(getResources(), R.drawable.topbar_avatar);
|
bm = BitmapFactory.decodeResource(getResources(), R.drawable.topbar_avatar);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bm = BitmapFactory.decodeResource(getResources(), R.drawable.topbar_avatar);
|
bm = BitmapFactory.decodeResource(getResources(), R.drawable.topbar_avatar);
|
||||||
}
|
}
|
||||||
mMsgNotif = Compatibility.createMessageNotification(getApplicationContext(), mMsgNotifCount, to, fromName, message, bm, notifContentIntent);
|
mMsgNotif = Compatibility.createMessageNotification(getApplicationContext(), mMsgNotifCount, fromName, message, bm, notifContentIntent);
|
||||||
|
|
||||||
notifyWrapper(MESSAGE_NOTIF_ID, mMsgNotif);
|
notifyWrapper(MESSAGE_NOTIF_ID, mMsgNotif);
|
||||||
}
|
}
|
||||||
|
|
|
@ -278,6 +278,7 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
|
||||||
if (contactsSelected.size() == 1) {
|
if (contactsSelected.size() == 1) {
|
||||||
contactsSelectedLayout.removeAllViews();
|
contactsSelectedLayout.removeAllViews();
|
||||||
LinphoneActivity.instance().displayChat(contactsSelected.get(0).getAddress(), "", "");
|
LinphoneActivity.instance().displayChat(contactsSelected.get(0).getAddress(), "", "");
|
||||||
|
//TODO create group chat room with only two participants ?
|
||||||
} else {
|
} else {
|
||||||
contactsSelectedLayout.removeAllViews();
|
contactsSelectedLayout.removeAllViews();
|
||||||
LinphoneActivity.instance().goToChatGroupInfos(contactsSelected, null, false, true);
|
LinphoneActivity.instance().goToChatGroupInfos(contactsSelected, null, false, true);
|
||||||
|
|
|
@ -195,7 +195,7 @@ public class ChatEventsAdapter extends BaseAdapter implements ChatMessageListene
|
||||||
} else {
|
} else {
|
||||||
LinphoneContact contact = null;
|
LinphoneContact contact = null;
|
||||||
for (LinphoneContact c : mParticipants) {
|
for (LinphoneContact c : mParticipants) {
|
||||||
if (contact.hasAddress(remoteSender.asStringUriOnly())) {
|
if (c != null && c.hasAddress(remoteSender.asStringUriOnly())) {
|
||||||
contact = c;
|
contact = c;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,6 @@ import org.linphone.core.Factory;
|
||||||
import org.linphone.core.Friend;
|
import org.linphone.core.Friend;
|
||||||
import org.linphone.core.FriendList;
|
import org.linphone.core.FriendList;
|
||||||
import org.linphone.core.Participant;
|
import org.linphone.core.Participant;
|
||||||
import org.linphone.mediastream.Log;
|
|
||||||
import org.linphone.receivers.ContactsUpdatedListener;
|
import org.linphone.receivers.ContactsUpdatedListener;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -625,11 +624,11 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
|
||||||
if (!getResources().getBoolean(R.bool.disable_chat_message_notification)) {
|
if (!getResources().getBoolean(R.bool.disable_chat_message_notification)) {
|
||||||
String to = msg.getToAddress().asString();
|
String to = msg.getToAddress().asString();
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
LinphoneService.instance().displayMessageNotification(to, from.asStringUriOnly(),
|
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(),
|
||||||
contact.getFullName(), getString(R.string.message_cant_be_decrypted_notif));
|
contact.getFullName(), contact.getThumbnailUri(), getString(R.string.message_cant_be_decrypted_notif));
|
||||||
} else {
|
} else {
|
||||||
LinphoneService.instance().displayMessageNotification(to, from.asStringUriOnly(),
|
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(),
|
||||||
from.getUsername(), getString(R.string.message_cant_be_decrypted_notif));
|
from.getUsername(), null, getString(R.string.message_cant_be_decrypted_notif));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (LinphoneManager.getLc().limeEnabled() == Core.LimeState.Mandatory) {
|
} else if (LinphoneManager.getLc().limeEnabled() == Core.LimeState.Mandatory) {
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class Compatibility {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Notification createMessageNotification(Context context, int msgCount,String to, String msgSender, String msg, Bitmap contactIcon, PendingIntent intent) {
|
public static Notification createMessageNotification(Context context, int msgCount, String msgSender, String msg, Bitmap contactIcon, PendingIntent intent) {
|
||||||
if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
|
if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
|
||||||
return ApiTwentySixPlus.createMessageNotification(context, msgCount, msgSender, msg, contactIcon, intent);
|
return ApiTwentySixPlus.createMessageNotification(context, msgCount, msgSender, msg, contactIcon, intent);
|
||||||
} else if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) {
|
} else if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) {
|
||||||
|
|
Loading…
Reference in a new issue