Added sender icon & message timestamp

This commit is contained in:
Sylvain Berfini 2018-11-21 10:12:38 +01:00
parent dc170e357e
commit 0048482d1c
5 changed files with 87 additions and 70 deletions

View file

@ -1075,16 +1075,16 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
if (!mServiceContext.getResources().getBoolean(R.bool.disable_chat_message_notification) && !message.isOutgoing()) { if (!mServiceContext.getResources().getBoolean(R.bool.disable_chat_message_notification) && !message.isOutgoing()) {
if (cr.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) { if (cr.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) {
if (contact != null) { if (contact != null) {
LinphoneService.instance().getNotificationManager().displayMessageNotification(cr.getPeerAddress().asStringUriOnly(), contact.getFullName(), contact.getThumbnailUri(), textMessage, cr.getLocalAddress()); LinphoneService.instance().getNotificationManager().displayMessageNotification(cr.getPeerAddress().asStringUriOnly(), contact.getFullName(), contact.getThumbnailUri(), textMessage, cr.getLocalAddress(), message.getTime());
} else { } else {
LinphoneService.instance().getNotificationManager().displayMessageNotification(cr.getPeerAddress().asStringUriOnly(), from.getUsername(), null, textMessage, cr.getLocalAddress()); LinphoneService.instance().getNotificationManager().displayMessageNotification(cr.getPeerAddress().asStringUriOnly(), from.getUsername(), null, textMessage, cr.getLocalAddress(), message.getTime());
} }
} else { } else {
String subject = cr.getSubject(); String subject = cr.getSubject();
if (contact != null) { if (contact != null) {
LinphoneService.instance().getNotificationManager().displayGroupChatMessageNotification(subject, cr.getPeerAddress().asStringUriOnly(), contact.getFullName(), contact.getThumbnailUri(), textMessage, cr.getLocalAddress()); LinphoneService.instance().getNotificationManager().displayGroupChatMessageNotification(subject, cr.getPeerAddress().asStringUriOnly(), contact.getFullName(), contact.getThumbnailUri(), textMessage, cr.getLocalAddress(), message.getTime());
} else { } else {
LinphoneService.instance().getNotificationManager().displayGroupChatMessageNotification(subject, cr.getPeerAddress().asStringUriOnly(), from.getUsername(), null, textMessage, cr.getLocalAddress()); LinphoneService.instance().getNotificationManager().displayGroupChatMessageNotification(subject, cr.getPeerAddress().asStringUriOnly(), from.getUsername(), null, textMessage, cr.getLocalAddress(), message.getTime());
} }
} }
} }

View file

@ -952,10 +952,10 @@ 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)) {
if (contact != null) { if (contact != null) {
LinphoneService.instance().getNotificationManager().displayMessageNotification(from.asStringUriOnly(), LinphoneService.instance().getNotificationManager().displayMessageNotification(from.asStringUriOnly(),
contact.getFullName(), contact.getThumbnailUri(), getString(R.string.message_cant_be_decrypted_notif), cr.getLocalAddress()); contact.getFullName(), contact.getThumbnailUri(), getString(R.string.message_cant_be_decrypted_notif), cr.getLocalAddress(), msg.getTime());
} else { } else {
LinphoneService.instance().getNotificationManager().displayMessageNotification(from.asStringUriOnly(), LinphoneService.instance().getNotificationManager().displayMessageNotification(from.asStringUriOnly(),
from.getUsername(), null, getString(R.string.message_cant_be_decrypted_notif), cr.getLocalAddress()); from.getUsername(), null, getString(R.string.message_cant_be_decrypted_notif), cr.getLocalAddress(), msg.getTime());
} }
} }
} else if (LinphoneManager.getLc().limeEnabled() == LimeState.Mandatory) { } else if (LinphoneManager.getLc().limeEnabled() == LimeState.Mandatory) {

View file

@ -27,6 +27,7 @@ import android.app.RemoteInput;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.drawable.Icon;
import org.linphone.R; import org.linphone.R;
import org.linphone.notifications.Notifiable; import org.linphone.notifications.Notifiable;
@ -61,7 +62,8 @@ public class ApiTwentyEightPlus {
Person me = new Person.Builder().setName(notif.getMyself()).build(); Person me = new Person.Builder().setName(notif.getMyself()).build();
Notification.MessagingStyle style = new Notification.MessagingStyle(me); Notification.MessagingStyle style = new Notification.MessagingStyle(me);
for (NotifiableMessage message : notif.getMessages()) { for (NotifiableMessage message : notif.getMessages()) {
Person user = new Person.Builder().setName(message.getSender()).build(); Icon userIcon = Icon.createWithBitmap(message.getSenderBitmap());
Person user = new Person.Builder().setName(message.getSender()).setIcon(userIcon).build();
style.addMessage(message.getMessage(), message.getTime(), user); style.addMessage(message.getMessage(), message.getTime(), user);
} }
if (notif.isGroup()) { if (notif.isGroup()) {

View file

@ -19,10 +19,13 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
import android.graphics.Bitmap;
public class NotifiableMessage { public class NotifiableMessage {
String mMessage; String mMessage;
String mSender; String mSender;
long mTime; long mTime;
Bitmap mSenderBitmap;
public NotifiableMessage(String message, String sender, long time) { public NotifiableMessage(String message, String sender, long time) {
mMessage = message; mMessage = message;
@ -41,4 +44,12 @@ public class NotifiableMessage {
public long getTime() { public long getTime() {
return mTime; return mTime;
} }
public Bitmap getSenderBitmap() {
return mSenderBitmap;
}
public void setSenderBitmap(Bitmap bm) {
mSenderBitmap = bm;
}
} }

View file

@ -129,25 +129,12 @@ public class NotificationsManager {
return null; return null;
} }
public void displayGroupChatMessageNotification(String subject, String conferenceAddress, String fromName, Uri fromPictureUri, String message, Address localIdentity) { public void displayGroupChatMessageNotification(String subject, String conferenceAddress, String fromName, Uri fromPictureUri, String message, Address localIdentity, long timestamp) {
Intent notifIntent = new Intent(mContext, LinphoneActivity.class); Intent notifIntent = new Intent(mContext, LinphoneActivity.class);
notifIntent.putExtra("GoToChat", true); notifIntent.putExtra("GoToChat", true);
notifIntent.putExtra("ChatContactSipUri", conferenceAddress); notifIntent.putExtra("ChatContactSipUri", conferenceAddress);
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, notifIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notifiable notif = mChatNotifMap.get(conferenceAddress);
NotifiableMessage notifMessage = new NotifiableMessage(message, fromName, 0);
if (notif == null) {
notif = new Notifiable(mLastNotificationId);
mLastNotificationId += 1;
mChatNotifMap.put(conferenceAddress, notif);
}
notif.addMessage(notifMessage);
notif.setIsGroup(true);
notif.setGroupTitle(subject);
notif.setMyself(LinphoneUtils.getAddressDisplayName(localIdentity));
notif.setLocalIdentity(localIdentity.asString());
Bitmap bm; Bitmap bm;
if (fromPictureUri != null) { if (fromPictureUri != null) {
try { try {
@ -158,12 +145,27 @@ public class NotificationsManager {
} else { } else {
bm = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.topbar_avatar); bm = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.topbar_avatar);
} }
Notifiable notif = mChatNotifMap.get(conferenceAddress);
NotifiableMessage notifMessage = new NotifiableMessage(message, fromName, timestamp);
if (notif == null) {
notif = new Notifiable(mLastNotificationId);
mLastNotificationId += 1;
mChatNotifMap.put(conferenceAddress, notif);
}
notifMessage.setSenderBitmap(bm);
notif.addMessage(notifMessage);
notif.setIsGroup(true);
notif.setGroupTitle(subject);
notif.setMyself(LinphoneUtils.getAddressDisplayName(localIdentity));
notif.setLocalIdentity(localIdentity.asString());
Notification notification = Compatibility.createMessageNotification(mContext, notif, subject, Notification notification = Compatibility.createMessageNotification(mContext, notif, subject,
mContext.getString(R.string.group_chat_notif).replace("%1", fromName).replace("%2", message), bm, pendingIntent); mContext.getString(R.string.group_chat_notif).replace("%1", fromName).replace("%2", message), bm, pendingIntent);
sendNotification(notif.getNotificationId(), notification); sendNotification(notif.getNotificationId(), notification);
} }
public void displayMessageNotification(String fromSipUri, String fromName, Uri fromPictureUri, String message, Address localIdentity) { public void displayMessageNotification(String fromSipUri, String fromName, Uri fromPictureUri, String message, Address localIdentity, long timestamp) {
Intent notifIntent = new Intent(mContext, LinphoneActivity.class); Intent notifIntent = new Intent(mContext, LinphoneActivity.class);
notifIntent.putExtra("GoToChat", true); notifIntent.putExtra("GoToChat", true);
notifIntent.putExtra("ChatContactSipUri", fromSipUri); notifIntent.putExtra("ChatContactSipUri", fromSipUri);
@ -173,18 +175,6 @@ public class NotificationsManager {
fromName = fromSipUri; fromName = fromSipUri;
} }
Notifiable notif = mChatNotifMap.get(fromSipUri);
NotifiableMessage notifMessage = new NotifiableMessage(message, fromName, 0);
if (notif == null) {
notif = new Notifiable(mLastNotificationId);
mLastNotificationId += 1;
mChatNotifMap.put(fromSipUri, notif);
}
notif.addMessage(notifMessage);
notif.setIsGroup(false);
notif.setMyself(LinphoneUtils.getAddressDisplayName(localIdentity));
notif.setLocalIdentity(localIdentity.asString());
Bitmap bm; Bitmap bm;
if (fromPictureUri != null) { if (fromPictureUri != null) {
try { try {
@ -195,6 +185,20 @@ public class NotificationsManager {
} else { } else {
bm = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.topbar_avatar); bm = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.topbar_avatar);
} }
Notifiable notif = mChatNotifMap.get(fromSipUri);
NotifiableMessage notifMessage = new NotifiableMessage(message, fromName, timestamp);
if (notif == null) {
notif = new Notifiable(mLastNotificationId);
mLastNotificationId += 1;
mChatNotifMap.put(fromSipUri, notif);
}
notifMessage.setSenderBitmap(bm);
notif.addMessage(notifMessage);
notif.setIsGroup(false);
notif.setMyself(LinphoneUtils.getAddressDisplayName(localIdentity));
notif.setLocalIdentity(localIdentity.asString());
Notification notification = Compatibility.createMessageNotification(mContext, notif, fromName, message, bm, pendingIntent); Notification notification = Compatibility.createMessageNotification(mContext, notif, fromName, message, bm, pendingIntent);
sendNotification(notif.getNotificationId(), notification); sendNotification(notif.getNotificationId(), notification);
} }