aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2016-09-28 21:31:15 +0200
committerChristian Schneppe <christian@pix-art.de>2016-09-28 21:31:15 +0200
commit6fdaed555ebcb18a313b78cebeab5c376861544d (patch)
tree4eaf9e980ae349476d36920f4b7e5c4ecfd53f17 /src/main/java/de
parentbd91a49fb8bb716d50c528e55b074a929159d7c7 (diff)
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)
Diffstat (limited to 'src/main/java/de')
-rw-r--r--src/main/java/de/pixart/messenger/services/NotificationService.java14
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java16
2 files changed, 20 insertions, 10 deletions
diff --git a/src/main/java/de/pixart/messenger/services/NotificationService.java b/src/main/java/de/pixart/messenger/services/NotificationService.java
index cef9abada..293442662 100644
--- a/src/main/java/de/pixart/messenger/services/NotificationService.java
+++ b/src/main/java/de/pixart/messenger/services/NotificationService.java
@@ -305,11 +305,11 @@ public class NotificationService {
modifyForTextOnly(mBuilder, messages);
}
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) {
- mBuilder.addAction(action);
- } else {
- mBuilder.extend(new NotificationCompat.WearableExtender().addAction(action));
+ mBuilder.addAction(replyAction);
}
if ((message = getFirstDownloadableMessage(messages)) != null) {
mBuilder.addAction(
@@ -482,11 +482,13 @@ public class NotificationService {
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);
intent.setAction(XmppConnectionService.ACTION_REPLY_TO_CONVERSATION);
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() {
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index 1083f5965..2f61ed919 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -658,7 +658,7 @@ public class XmppConnectionService extends Service {
if (remoteInput != null && c != null) {
final CharSequence body = remoteInput.getCharSequence("text_reply");
if (body != null && body.length() > 0) {
- directReply(c, body.toString());
+ directReply(c, body.toString(),intent.getBooleanExtra("dismiss_notification",false));
}
}
break;
@@ -791,7 +791,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.markUnread();
if (message.getEncryption() == Message.ENCRYPTION_PGP) {
@@ -800,7 +800,11 @@ public class XmppConnectionService extends Service {
public void success(Message message) {
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
sendMessage(message);
- mNotificationService.pushFromDirectReply(message);
+ if (dismissAfterReply) {
+ markRead(message.getConversation(),true);
+ } else {
+ mNotificationService.pushFromDirectReply(message);
+ }
}
@Override
@@ -815,7 +819,11 @@ public class XmppConnectionService extends Service {
});
} else {
sendMessage(message);
- mNotificationService.pushFromDirectReply(message);
+ if (dismissAfterReply) {
+ markRead(conversation,true);
+ } else {
+ mNotificationService.pushFromDirectReply(message);
+ }
}
}