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 (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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
@ -61,7 +62,8 @@ public class ApiTwentyEightPlus {
|
|||
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();
|
||||
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()) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue