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 (cr.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) {
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 {
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 {
String subject = cr.getSubject();
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 {
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 (contact != null) {
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 {
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) {

View file

@ -27,6 +27,7 @@ import android.app.RemoteInput;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Icon;
import org.linphone.R;
import org.linphone.notifications.Notifiable;
@ -40,50 +41,51 @@ import static org.linphone.compatibility.Compatibility.KEY_TEXT_REPLY;
@TargetApi(28)
public class ApiTwentyEightPlus {
public static Notification createMessageNotification(Context context, Notifiable notif, Bitmap contactIcon, PendingIntent intent) {
String replyLabel = context.getResources().getString(R.string.notification_reply_label);
RemoteInput remoteInput = new RemoteInput.Builder(KEY_TEXT_REPLY).setLabel(replyLabel).build();
public static Notification createMessageNotification(Context context, Notifiable notif, Bitmap contactIcon, PendingIntent intent) {
String replyLabel = context.getResources().getString(R.string.notification_reply_label);
RemoteInput remoteInput = new RemoteInput.Builder(KEY_TEXT_REPLY).setLabel(replyLabel).build();
Intent replyIntent = new Intent(context, NotificationBroadcastReceiver.class);
replyIntent.setAction(INTENT_REPLY_NOTIF_ACTION);
replyIntent.putExtra(INTENT_NOTIF_ID, notif.getNotificationId());
replyIntent.putExtra(INTENT_LOCAL_IDENTITY, notif.getLocalIdentity());
Intent replyIntent = new Intent(context, NotificationBroadcastReceiver.class);
replyIntent.setAction(INTENT_REPLY_NOTIF_ACTION);
replyIntent.putExtra(INTENT_NOTIF_ID, notif.getNotificationId());
replyIntent.putExtra(INTENT_LOCAL_IDENTITY, notif.getLocalIdentity());
PendingIntent replyPendingIntent = PendingIntent.getBroadcast(context,
notif.getNotificationId(), replyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent replyPendingIntent = PendingIntent.getBroadcast(context,
notif.getNotificationId(), replyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification.Action action = new Notification.Action.Builder(R.drawable.chat_send_over,
Notification.Action action = new Notification.Action.Builder(R.drawable.chat_send_over,
context.getString(R.string.notification_reply_label), replyPendingIntent)
.addRemoteInput(remoteInput)
.setAllowGeneratedReplies(true)
.build();
Person me = new Person.Builder().setName(notif.getMyself()).build();
Notification.MessagingStyle style = new Notification.MessagingStyle(me);
for (NotifiableMessage message : notif.getMessages()) {
Person user = new Person.Builder().setName(message.getSender()).build();
style.addMessage(message.getMessage(), message.getTime(), user);
}
if (notif.isGroup()) {
style.setConversationTitle(notif.getGroupTitle());
}
style.setGroupConversation(notif.isGroup());
Person me = new Person.Builder().setName(notif.getMyself()).build();
Notification.MessagingStyle style = new Notification.MessagingStyle(me);
for (NotifiableMessage message : notif.getMessages()) {
Icon userIcon = Icon.createWithBitmap(message.getSenderBitmap());
Person user = new Person.Builder().setName(message.getSender()).setIcon(userIcon).build();
style.addMessage(message.getMessage(), message.getTime(), user);
}
if (notif.isGroup()) {
style.setConversationTitle(notif.getGroupTitle());
}
style.setGroupConversation(notif.isGroup());
return new Notification.Builder(context, context.getString(R.string.notification_channel_id))
.setSmallIcon(R.drawable.topbar_chat_notification)
.setAutoCancel(true)
.setContentIntent(intent)
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
.setLargeIcon(contactIcon)
.setCategory(Notification.CATEGORY_MESSAGE)
.setVisibility(Notification.VISIBILITY_PRIVATE)
.setPriority(Notification.PRIORITY_HIGH)
.setNumber(notif.getMessages().size())
.setWhen(System.currentTimeMillis())
.setShowWhen(true)
.setColor(context.getColor(R.color.notification_color_led))
.setStyle(style)
.addAction(action)
.build();
}
return new Notification.Builder(context, context.getString(R.string.notification_channel_id))
.setSmallIcon(R.drawable.topbar_chat_notification)
.setAutoCancel(true)
.setContentIntent(intent)
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
.setLargeIcon(contactIcon)
.setCategory(Notification.CATEGORY_MESSAGE)
.setVisibility(Notification.VISIBILITY_PRIVATE)
.setPriority(Notification.PRIORITY_HIGH)
.setNumber(notif.getMessages().size())
.setWhen(System.currentTimeMillis())
.setShowWhen(true)
.setColor(context.getColor(R.color.notification_color_led))
.setStyle(style)
.addAction(action)
.build();
}
}

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.
*/
import android.graphics.Bitmap;
public class NotifiableMessage {
String mMessage;
String mSender;
long mTime;
Bitmap mSenderBitmap;
public NotifiableMessage(String message, String sender, long time) {
mMessage = message;
@ -41,4 +44,12 @@ public class NotifiableMessage {
public long getTime() {
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;
}
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);
notifIntent.putExtra("GoToChat", true);
notifIntent.putExtra("ChatContactSipUri", conferenceAddress);
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;
if (fromPictureUri != null) {
try {
@ -158,12 +145,27 @@ public class NotificationsManager {
} else {
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,
mContext.getString(R.string.group_chat_notif).replace("%1", fromName).replace("%2", message), bm, pendingIntent);
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);
notifIntent.putExtra("GoToChat", true);
notifIntent.putExtra("ChatContactSipUri", fromSipUri);
@ -173,18 +175,6 @@ public class NotificationsManager {
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;
if (fromPictureUri != null) {
try {
@ -195,6 +185,20 @@ public class NotificationsManager {
} else {
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);
sendNotification(notif.getNotificationId(), notification);
}