Allow to dismiss the notification from a wear reply.
- use different IDs in the same method for the PendingIntent - fix reply for GPG encrypted replies (untested)
This commit is contained in:
parent
5cd8917122
commit
41db773b08
|
@ -297,11 +297,11 @@ public class NotificationService {
|
||||||
modifyForTextOnly(mBuilder, 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();
|
||||||
NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_send_text_offline, "Reply", createReplyIntent(conversation)).addRemoteInput(remoteInput).build();
|
NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(R.drawable.ic_send_text_offline, "Reply", createReplyIntent(conversation, false)).addRemoteInput(remoteInput).build();
|
||||||
|
NotificationCompat.Action wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_send_text_offline, "Reply", createReplyIntent(conversation, true)).addRemoteInput(remoteInput).build();
|
||||||
|
mBuilder.extend(new NotificationCompat.WearableExtender().addAction(wearReplyAction));
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
mBuilder.addAction(action);
|
mBuilder.addAction(replyAction);
|
||||||
} else {
|
|
||||||
mBuilder.extend(new NotificationCompat.WearableExtender().addAction(action));
|
|
||||||
}
|
}
|
||||||
if ((message = getFirstDownloadableMessage(messages)) != null) {
|
if ((message = getFirstDownloadableMessage(messages)) != null) {
|
||||||
mBuilder.addAction(
|
mBuilder.addAction(
|
||||||
|
@ -474,11 +474,13 @@ public class NotificationService {
|
||||||
return PendingIntent.getService(mXmppConnectionService, 0, intent, 0);
|
return PendingIntent.getService(mXmppConnectionService, 0, intent, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PendingIntent createReplyIntent(Conversation conversation) {
|
private PendingIntent createReplyIntent(Conversation conversation, boolean dismissAfterReply) {
|
||||||
final Intent intent = new Intent(mXmppConnectionService, XmppConnectionService.class);
|
final Intent intent = new Intent(mXmppConnectionService, XmppConnectionService.class);
|
||||||
intent.setAction(XmppConnectionService.ACTION_REPLY_TO_CONVERSATION);
|
intent.setAction(XmppConnectionService.ACTION_REPLY_TO_CONVERSATION);
|
||||||
intent.putExtra("uuid",conversation.getUuid());
|
intent.putExtra("uuid",conversation.getUuid());
|
||||||
return PendingIntent.getService(mXmppConnectionService, conversation.getUuid().hashCode() % 402361, intent, 0);
|
intent.putExtra("dismiss_notification",dismissAfterReply);
|
||||||
|
int id = conversation.getUuid().hashCode() % (dismissAfterReply ? 402359 : 426583);
|
||||||
|
return PendingIntent.getService(mXmppConnectionService, id, intent, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PendingIntent createDisableForeground() {
|
private PendingIntent createDisableForeground() {
|
||||||
|
|
|
@ -575,7 +575,7 @@ public class XmppConnectionService extends Service {
|
||||||
if (remoteInput != null && c != null) {
|
if (remoteInput != null && c != null) {
|
||||||
final CharSequence body = remoteInput.getCharSequence("text_reply");
|
final CharSequence body = remoteInput.getCharSequence("text_reply");
|
||||||
if (body != null && body.length() > 0) {
|
if (body != null && body.length() > 0) {
|
||||||
directReply(c, body.toString());
|
directReply(c, body.toString(),intent.getBooleanExtra("dismiss_notification",false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -708,7 +708,7 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void directReply(Conversation conversation, String body) {
|
private void directReply(Conversation conversation, String body, final boolean dismissAfterReply) {
|
||||||
Message message = new Message(conversation,body,conversation.getNextEncryption());
|
Message message = new Message(conversation,body,conversation.getNextEncryption());
|
||||||
message.markUnread();
|
message.markUnread();
|
||||||
if (message.getEncryption() == Message.ENCRYPTION_PGP) {
|
if (message.getEncryption() == Message.ENCRYPTION_PGP) {
|
||||||
|
@ -717,8 +717,12 @@ public class XmppConnectionService extends Service {
|
||||||
public void success(Message message) {
|
public void success(Message message) {
|
||||||
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
|
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
|
||||||
sendMessage(message);
|
sendMessage(message);
|
||||||
|
if (dismissAfterReply) {
|
||||||
|
markRead(message.getConversation(),true);
|
||||||
|
} else {
|
||||||
mNotificationService.pushFromDirectReply(message);
|
mNotificationService.pushFromDirectReply(message);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error(int errorCode, Message object) {
|
public void error(int errorCode, Message object) {
|
||||||
|
@ -732,9 +736,13 @@ public class XmppConnectionService extends Service {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
sendMessage(message);
|
sendMessage(message);
|
||||||
|
if (dismissAfterReply) {
|
||||||
|
markRead(conversation,true);
|
||||||
|
} else {
|
||||||
mNotificationService.pushFromDirectReply(message);
|
mNotificationService.pushFromDirectReply(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean xaOnSilentMode() {
|
private boolean xaOnSilentMode() {
|
||||||
return getPreferences().getBoolean("xa_on_silent_mode", false);
|
return getPreferences().getBoolean("xa_on_silent_mode", false);
|
||||||
|
|
Loading…
Reference in a new issue