Added sender icon & message timestamp
This commit is contained in:
parent
dc170e357e
commit
0048482d1c
5 changed files with 87 additions and 70 deletions
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -40,50 +41,51 @@ import static org.linphone.compatibility.Compatibility.KEY_TEXT_REPLY;
|
||||||
|
|
||||||
@TargetApi(28)
|
@TargetApi(28)
|
||||||
public class ApiTwentyEightPlus {
|
public class ApiTwentyEightPlus {
|
||||||
public static Notification createMessageNotification(Context context, Notifiable notif, Bitmap contactIcon, PendingIntent intent) {
|
public static Notification createMessageNotification(Context context, Notifiable notif, Bitmap contactIcon, PendingIntent intent) {
|
||||||
String replyLabel = context.getResources().getString(R.string.notification_reply_label);
|
String replyLabel = context.getResources().getString(R.string.notification_reply_label);
|
||||||
RemoteInput remoteInput = new RemoteInput.Builder(KEY_TEXT_REPLY).setLabel(replyLabel).build();
|
RemoteInput remoteInput = new RemoteInput.Builder(KEY_TEXT_REPLY).setLabel(replyLabel).build();
|
||||||
|
|
||||||
Intent replyIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
Intent replyIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
||||||
replyIntent.setAction(INTENT_REPLY_NOTIF_ACTION);
|
replyIntent.setAction(INTENT_REPLY_NOTIF_ACTION);
|
||||||
replyIntent.putExtra(INTENT_NOTIF_ID, notif.getNotificationId());
|
replyIntent.putExtra(INTENT_NOTIF_ID, notif.getNotificationId());
|
||||||
replyIntent.putExtra(INTENT_LOCAL_IDENTITY, notif.getLocalIdentity());
|
replyIntent.putExtra(INTENT_LOCAL_IDENTITY, notif.getLocalIdentity());
|
||||||
|
|
||||||
PendingIntent replyPendingIntent = PendingIntent.getBroadcast(context,
|
PendingIntent replyPendingIntent = PendingIntent.getBroadcast(context,
|
||||||
notif.getNotificationId(), replyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
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)
|
context.getString(R.string.notification_reply_label), replyPendingIntent)
|
||||||
.addRemoteInput(remoteInput)
|
.addRemoteInput(remoteInput)
|
||||||
.setAllowGeneratedReplies(true)
|
.setAllowGeneratedReplies(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
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());
|
||||||
style.addMessage(message.getMessage(), message.getTime(), user);
|
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());
|
if (notif.isGroup()) {
|
||||||
}
|
style.setConversationTitle(notif.getGroupTitle());
|
||||||
style.setGroupConversation(notif.isGroup());
|
}
|
||||||
|
style.setGroupConversation(notif.isGroup());
|
||||||
|
|
||||||
return new Notification.Builder(context, context.getString(R.string.notification_channel_id))
|
return new Notification.Builder(context, context.getString(R.string.notification_channel_id))
|
||||||
.setSmallIcon(R.drawable.topbar_chat_notification)
|
.setSmallIcon(R.drawable.topbar_chat_notification)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.setContentIntent(intent)
|
.setContentIntent(intent)
|
||||||
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
|
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
|
||||||
.setLargeIcon(contactIcon)
|
.setLargeIcon(contactIcon)
|
||||||
.setCategory(Notification.CATEGORY_MESSAGE)
|
.setCategory(Notification.CATEGORY_MESSAGE)
|
||||||
.setVisibility(Notification.VISIBILITY_PRIVATE)
|
.setVisibility(Notification.VISIBILITY_PRIVATE)
|
||||||
.setPriority(Notification.PRIORITY_HIGH)
|
.setPriority(Notification.PRIORITY_HIGH)
|
||||||
.setNumber(notif.getMessages().size())
|
.setNumber(notif.getMessages().size())
|
||||||
.setWhen(System.currentTimeMillis())
|
.setWhen(System.currentTimeMillis())
|
||||||
.setShowWhen(true)
|
.setShowWhen(true)
|
||||||
.setColor(context.getColor(R.color.notification_color_led))
|
.setColor(context.getColor(R.color.notification_color_led))
|
||||||
.setStyle(style)
|
.setStyle(style)
|
||||||
.addAction(action)
|
.addAction(action)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue