MessageStyle notifications replace car extender
This commit is contained in:
parent
953307ca30
commit
2fbd9e6744
|
@ -517,7 +517,6 @@ public class NotificationService {
|
||||||
final Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService, quietHours ? "quiet_hours" : (notify ? "messages" : "silent_messages"));
|
final Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService, quietHours ? "quiet_hours" : (notify ? "messages" : "silent_messages"));
|
||||||
if (messages.size() >= 1) {
|
if (messages.size() >= 1) {
|
||||||
final Conversation conversation = (Conversation) messages.get(0).getConversation();
|
final Conversation conversation = (Conversation) messages.get(0).getConversation();
|
||||||
final UnreadConversation.Builder mUnreadBuilder = new UnreadConversation.Builder(conversation.getName().toString());
|
|
||||||
mBuilder.setLargeIcon(mXmppConnectionService.getAvatarService()
|
mBuilder.setLargeIcon(mXmppConnectionService.getAvatarService()
|
||||||
.get(conversation, AvatarService.getSystemUiAvatarSize(mXmppConnectionService)));
|
.get(conversation, AvatarService.getSystemUiAvatarSize(mXmppConnectionService)));
|
||||||
mBuilder.setContentTitle(conversation.getName());
|
mBuilder.setContentTitle(conversation.getName());
|
||||||
|
@ -528,28 +527,31 @@ public class NotificationService {
|
||||||
Message message;
|
Message message;
|
||||||
//TODO starting with Android 9 we might want to put images in MessageStyle
|
//TODO starting with Android 9 we might want to put images in MessageStyle
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P && (message = getImage(messages)) != null) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P && (message = getImage(messages)) != null) {
|
||||||
modifyForImage(mBuilder, mUnreadBuilder, message, messages);
|
modifyForImage(mBuilder, message, messages);
|
||||||
} else {
|
} else {
|
||||||
modifyForTextOnly(mBuilder, mUnreadBuilder, messages);
|
modifyForTextOnly(mBuilder, messages);
|
||||||
}
|
}
|
||||||
RemoteInput remoteInput = new RemoteInput.Builder("text_reply").setLabel(UIHelper.getMessageHint(mXmppConnectionService, conversation)).build();
|
RemoteInput remoteInput = new RemoteInput.Builder("text_reply").setLabel(UIHelper.getMessageHint(mXmppConnectionService, conversation)).build();
|
||||||
PendingIntent markAsReadPendingIntent = createReadPendingIntent(conversation);
|
PendingIntent markAsReadPendingIntent = createReadPendingIntent(conversation);
|
||||||
NotificationCompat.Action markReadAction = new NotificationCompat.Action.Builder(
|
NotificationCompat.Action markReadAction = new NotificationCompat.Action.Builder(
|
||||||
R.drawable.ic_drafts_white_24dp,
|
R.drawable.ic_drafts_white_24dp,
|
||||||
mXmppConnectionService.getString(R.string.mark_as_read),
|
mXmppConnectionService.getString(R.string.mark_as_read),
|
||||||
markAsReadPendingIntent).build();
|
markAsReadPendingIntent)
|
||||||
|
.setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_MARK_AS_READ)
|
||||||
|
.setShowsUserInterface(false)
|
||||||
|
.build();
|
||||||
String replyLabel = mXmppConnectionService.getString(R.string.reply);
|
String replyLabel = mXmppConnectionService.getString(R.string.reply);
|
||||||
NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
|
NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
|
||||||
R.drawable.ic_send_text_offline,
|
R.drawable.ic_send_text_offline,
|
||||||
replyLabel,
|
replyLabel,
|
||||||
createReplyIntent(conversation, false)).addRemoteInput(remoteInput).build();
|
createReplyIntent(conversation, false))
|
||||||
|
.setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_REPLY)
|
||||||
|
.setShowsUserInterface(false)
|
||||||
|
.addRemoteInput(remoteInput).build();
|
||||||
NotificationCompat.Action wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_wear_reply,
|
NotificationCompat.Action wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_wear_reply,
|
||||||
replyLabel,
|
replyLabel,
|
||||||
createReplyIntent(conversation, true)).addRemoteInput(remoteInput).build();
|
createReplyIntent(conversation, true)).addRemoteInput(remoteInput).build();
|
||||||
mBuilder.extend(new NotificationCompat.WearableExtender().addAction(wearReplyAction));
|
mBuilder.extend(new NotificationCompat.WearableExtender().addAction(wearReplyAction));
|
||||||
mUnreadBuilder.setReplyAction(createReplyIntent(conversation, true), remoteInput);
|
|
||||||
mUnreadBuilder.setReadPendingIntent(markAsReadPendingIntent);
|
|
||||||
mBuilder.extend(new NotificationCompat.CarExtender().setUnreadConversation(mUnreadBuilder.build()));
|
|
||||||
int addedActionsCount = 1;
|
int addedActionsCount = 1;
|
||||||
mBuilder.addAction(markReadAction);
|
mBuilder.addAction(markReadAction);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
@ -609,8 +611,7 @@ public class NotificationService {
|
||||||
return mBuilder;
|
return mBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void modifyForImage(final Builder builder, final UnreadConversation.Builder uBuilder,
|
private void modifyForImage(final Builder builder, final Message message, final ArrayList<Message> messages) {
|
||||||
final Message message, final ArrayList<Message> messages) {
|
|
||||||
try {
|
try {
|
||||||
final Bitmap bitmap = mXmppConnectionService.getFileBackend().getThumbnail(message, getPixel(288), false);
|
final Bitmap bitmap = mXmppConnectionService.getFileBackend().getThumbnail(message, getPixel(288), false);
|
||||||
final ArrayList<Message> tmp = new ArrayList<>();
|
final ArrayList<Message> tmp = new ArrayList<>();
|
||||||
|
@ -631,7 +632,7 @@ public class NotificationService {
|
||||||
}
|
}
|
||||||
builder.setStyle(bigPictureStyle);
|
builder.setStyle(bigPictureStyle);
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
modifyForTextOnly(builder, uBuilder, messages);
|
modifyForTextOnly(builder, messages);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -653,7 +654,7 @@ public class NotificationService {
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void modifyForTextOnly(final Builder builder, final UnreadConversation.Builder uBuilder, final ArrayList<Message> messages) {
|
private void modifyForTextOnly(final Builder builder, final ArrayList<Message> messages) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
final Conversation conversation = (Conversation) messages.get(0).getConversation();
|
final Conversation conversation = (Conversation) messages.get(0).getConversation();
|
||||||
final Person.Builder meBuilder = new Person.Builder().setName(mXmppConnectionService.getString(R.string.me));
|
final Person.Builder meBuilder = new Person.Builder().setName(mXmppConnectionService.getString(R.string.me));
|
||||||
|
@ -707,15 +708,6 @@ public class NotificationService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/** message preview for Android Auto **/
|
|
||||||
for (Message message : messages) {
|
|
||||||
Pair<CharSequence, Boolean> preview = UIHelper.getMessagePreview(mXmppConnectionService, message);
|
|
||||||
// only show user written text
|
|
||||||
if (!preview.second) {
|
|
||||||
uBuilder.addMessage(preview.first.toString());
|
|
||||||
uBuilder.setLatestTimestamp(message.getTimeSent());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Message getImage(final Iterable<Message> messages) {
|
private Message getImage(final Iterable<Message> messages) {
|
||||||
|
|
Loading…
Reference in New Issue