Added group chat message notification + some cleanup in notification code

This commit is contained in:
Sylvain Berfini 2017-11-02 12:08:31 +01:00
parent 315e4a0ba3
commit f94ad81a5d
7 changed files with 54 additions and 26 deletions

View file

@ -208,6 +208,7 @@
<string name="subject_changed">new subject : %s</string>
<string name="admin_set">%s is admin</string>
<string name="admin_unset">%s is no longer admin</string>
<string name="group_chat_notif">%1: %2</string>
<!-- Status Bar -->
<string name="status_connected">Registered</string>

View file

@ -1229,21 +1229,24 @@ public class LinphoneManager implements CoreListener, ChatMessageListener, Senso
}
Address from = message.getFromAddress();
String to = message.getToAddress().asString();
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(from);
String textMessage = (message.getFileTransferInformation() != null) ? getString(R.string.content_description_incoming_file) : message.getText();
String textMessage = (message.getFileTransferInformation() != null) ?
getString(R.string.content_description_incoming_file) : message.getText();
try {
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(from);
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) {
LinphoneService.instance().displayMessageNotification(to, from.asStringUriOnly(), contact.getFullName(), textMessage);
LinphoneService.instance().displayGroupChatMessageNotification(subject, cr.getConferenceAddress().asString(), contact.getFullName(), contact.getThumbnailUri(), textMessage);
} 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);
}
}

View file

@ -595,7 +595,36 @@ public final class LinphoneService extends Service {
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);
notifIntent.putExtra("GoToChat", true);
notifIntent.putExtra("ChatContactSipUri", fromSipUri);
@ -612,22 +641,17 @@ public final class LinphoneService extends Service {
mMsgNotifCount++;
}
Uri pictureUri = null;
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(Factory.instance().createAddress(fromSipUri));
if (contact != null)
pictureUri = contact.getThumbnailUri();
Bitmap bm = null;
if (pictureUri != null) {
if (fromPictureUri != null) {
try {
bm = MediaStore.Images.Media.getBitmap(getContentResolver(), pictureUri);
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, to, fromName, message, bm, notifContentIntent);
mMsgNotif = Compatibility.createMessageNotification(getApplicationContext(), mMsgNotifCount, fromName, message, bm, notifContentIntent);
notifyWrapper(MESSAGE_NOTIF_ID, mMsgNotif);
}

View file

@ -278,6 +278,7 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
if (contactsSelected.size() == 1) {
contactsSelectedLayout.removeAllViews();
LinphoneActivity.instance().displayChat(contactsSelected.get(0).getAddress(), "", "");
//TODO create group chat room with only two participants ?
} else {
contactsSelectedLayout.removeAllViews();
LinphoneActivity.instance().goToChatGroupInfos(contactsSelected, null, false, true);

View file

@ -195,7 +195,7 @@ public class ChatEventsAdapter extends BaseAdapter implements ChatMessageListene
} else {
LinphoneContact contact = null;
for (LinphoneContact c : mParticipants) {
if (contact.hasAddress(remoteSender.asStringUriOnly())) {
if (c != null && c.hasAddress(remoteSender.asStringUriOnly())) {
contact = c;
break;
}

View file

@ -68,7 +68,6 @@ import org.linphone.core.Factory;
import org.linphone.core.Friend;
import org.linphone.core.FriendList;
import org.linphone.core.Participant;
import org.linphone.mediastream.Log;
import org.linphone.receivers.ContactsUpdatedListener;
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)) {
String to = msg.getToAddress().asString();
if (contact != null) {
LinphoneService.instance().displayMessageNotification(to, from.asStringUriOnly(),
contact.getFullName(), getString(R.string.message_cant_be_decrypted_notif));
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(),
contact.getFullName(), contact.getThumbnailUri(), getString(R.string.message_cant_be_decrypted_notif));
} else {
LinphoneService.instance().displayMessageNotification(to, from.asStringUriOnly(),
from.getUsername(), getString(R.string.message_cant_be_decrypted_notif));
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(),
from.getUsername(), null, getString(R.string.message_cant_be_decrypted_notif));
}
}
} else if (LinphoneManager.getLc().limeEnabled() == Core.LimeState.Mandatory) {

View file

@ -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)) {
return ApiTwentySixPlus.createMessageNotification(context, msgCount, msgSender, msg, contactIcon, intent);
} else if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) {