diff --git a/res/values/strings.xml b/res/values/strings.xml
index 6704027544..a28a9126dc 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -981,15 +981,6 @@
Transport icon
-
-
- Reply
-
- - Yes
- - No
- - OK
- - Thanks
-
diff --git a/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java b/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java
index 4338a7a42c..9925f64147 100644
--- a/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java
+++ b/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java
@@ -5,34 +5,38 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
+import android.support.annotation.Nullable;
import android.util.Log;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.DatabaseFactory;
-public class MarkReadReceiver extends BroadcastReceiver {
+public class MarkReadReceiver extends MasterSecretBroadcastReceiver {
- public static final String CLEAR_ACTION = "org.thoughtcrime.securesms.notifications.CLEAR";
+ private static final String TAG = MarkReadReceiver.class.getSimpleName();
+ public static final String CLEAR_ACTION = "org.thoughtcrime.securesms.notifications.CLEAR";
+ public static final String THREAD_IDS_EXTRA = "thread_ids";
@Override
- public void onReceive(final Context context, Intent intent) {
- if (!intent.getAction().equals(CLEAR_ACTION))
+ protected void onReceive(final Context context, Intent intent,
+ @Nullable final MasterSecret masterSecret)
+ {
+ if (!CLEAR_ACTION.equals(intent.getAction()))
return;
- final long[] threadIds = intent.getLongArrayExtra("thread_ids");
- final MasterSecret masterSecret = intent.getParcelableExtra("master_secret");
+ final long[] threadIds = intent.getLongArrayExtra(THREAD_IDS_EXTRA);
- if (threadIds != null && masterSecret != null) {
- Log.w("MarkReadReceiver", "threadIds length: " + threadIds.length);
+ if (threadIds != null) {
+ Log.w("TAG", "threadIds length: " + threadIds.length);
((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE))
- .cancel(MessageNotifier.NOTIFICATION_ID);
+ .cancel(MessageNotifier.NOTIFICATION_ID);
new AsyncTask() {
@Override
protected Void doInBackground(Void... params) {
for (long threadId : threadIds) {
- Log.w("MarkReadReceiver", "Marking as read: " + threadId);
+ Log.w(TAG, "Marking as read: " + threadId);
DatabaseFactory.getThreadDatabase(context).setRead(threadId);
}
diff --git a/src/org/thoughtcrime/securesms/notifications/MasterSecretBroadcastReceiver.java b/src/org/thoughtcrime/securesms/notifications/MasterSecretBroadcastReceiver.java
new file mode 100644
index 0000000000..059e33e0d4
--- /dev/null
+++ b/src/org/thoughtcrime/securesms/notifications/MasterSecretBroadcastReceiver.java
@@ -0,0 +1,19 @@
+package org.thoughtcrime.securesms.notifications;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.support.annotation.Nullable;
+
+import org.thoughtcrime.securesms.crypto.MasterSecret;
+import org.thoughtcrime.securesms.service.KeyCachingService;
+
+public abstract class MasterSecretBroadcastReceiver extends BroadcastReceiver {
+
+ @Override
+ public final void onReceive(Context context, Intent intent) {
+ onReceive(context, intent, KeyCachingService.getMasterSecret(context));
+ }
+
+ protected abstract void onReceive(Context context, Intent intent, @Nullable MasterSecret masterSecret);
+}
diff --git a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java
index ef82154ce0..06ba1bb0b7 100644
--- a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java
+++ b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java
@@ -98,8 +98,8 @@ public class MessageNotifier {
sendInThreadNotification(context, recipients);
} else {
Intent intent = new Intent(context, ConversationActivity.class);
- intent.putExtra("recipients", recipients.getIds());
- intent.putExtra("thread_id", threadId);
+ intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients.getIds());
+ intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
@@ -195,8 +195,8 @@ public class MessageNotifier {
List notifications = notificationState.getNotifications();
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
- Recipient recipient = notifications.get(0).getIndividualRecipient();
Recipients recipients = notifications.get(0).getRecipients();
+ Recipient recipient = notifications.get(0).getIndividualRecipient();
int largeIconTargetSize = context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size);
Drawable recipientPhoto = recipient.getContactPhoto().asDrawable(context, recipients == null ? ContactColors.UNKNOWN_COLOR.toConversationColor(context) :
recipients.getColor().toConversationColor(context));
@@ -224,16 +224,16 @@ public class MessageNotifier {
if (masterSecret != null) {
Action markAsReadAction = new Action(R.drawable.check,
context.getString(R.string.MessageNotifier_mark_read),
- notificationState.getMarkAsReadIntent(context, masterSecret));
+ notificationState.getMarkAsReadIntent(context));
Action replyAction = new Action(R.drawable.ic_reply_white_36dp,
context.getString(R.string.MessageNotifier_reply),
- notifications.get(0).getReplyIntent(context));
+ notificationState.getQuickReplyIntent(context, recipients));
Action wearableReplyAction = new Action.Builder(R.drawable.ic_reply,
- context.getString(R.string.wear_reply_label),
- notificationState.getReplyIntent(context, masterSecret, recipient.getRecipientId()))
- .addRemoteInput(new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel(context.getString(R.string.wear_reply_label)).build())
+ context.getString(R.string.MessageNotifier_reply),
+ notificationState.getWearableReplyIntent(context, recipients))
+ .addRemoteInput(new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel(context.getString(R.string.MessageNotifier_reply)).build())
.build();
builder.addAction(markAsReadAction);
@@ -296,7 +296,7 @@ public class MessageNotifier {
if (masterSecret != null) {
Action markAllAsReadAction = new Action(R.drawable.check,
context.getString(R.string.MessageNotifier_mark_all_as_read),
- notificationState.getMarkAsReadIntent(context, masterSecret));
+ notificationState.getMarkAsReadIntent(context));
builder.addAction(markAllAsReadAction);
builder.extend(new NotificationCompat.WearableExtender().addAction(markAllAsReadAction));
}
diff --git a/src/org/thoughtcrime/securesms/notifications/NotificationItem.java b/src/org/thoughtcrime/securesms/notifications/NotificationItem.java
index db81902a07..424bcf2932 100644
--- a/src/org/thoughtcrime/securesms/notifications/NotificationItem.java
+++ b/src/org/thoughtcrime/securesms/notifications/NotificationItem.java
@@ -36,8 +36,8 @@ public class NotificationItem {
this.timestamp = timestamp;
}
- public @Nullable Recipients getRecipients() {
- return threadRecipients;
+ public Recipients getRecipients() {
+ return threadRecipients == null ? recipients : threadRecipients;
}
public Recipient getIndividualRecipient() {
@@ -92,16 +92,5 @@ public class NotificationItem {
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
- public PendingIntent getReplyIntent(Context context) {
- Intent intent = new Intent(context, ConversationPopupActivity.class);
- Recipients notifyRecipients = threadRecipients != null ? threadRecipients : recipients;
- if (notifyRecipients != null) intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, notifyRecipients.getIds());
-
- intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
- intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
-
- return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
- }
-
}
diff --git a/src/org/thoughtcrime/securesms/notifications/NotificationState.java b/src/org/thoughtcrime/securesms/notifications/NotificationState.java
index 52ac5563bb..51391b8d17 100644
--- a/src/org/thoughtcrime/securesms/notifications/NotificationState.java
+++ b/src/org/thoughtcrime/securesms/notifications/NotificationState.java
@@ -4,11 +4,11 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
-import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
-import org.thoughtcrime.securesms.crypto.MasterSecret;
+import org.thoughtcrime.securesms.ConversationActivity;
+import org.thoughtcrime.securesms.ConversationPopupActivity;
import org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.VibrateState;
import org.thoughtcrime.securesms.recipients.Recipients;
@@ -70,39 +70,48 @@ public class NotificationState {
return notifications;
}
- public PendingIntent getMarkAsReadIntent(Context context, MasterSecret masterSecret) {
- Bundle extras = new Bundle();
- extras.putParcelable("master_secret", masterSecret);
- return craftIntent(context, MarkReadReceiver.CLEAR_ACTION, extras);
- }
-
- public PendingIntent getReplyIntent(Context context, MasterSecret masterSecret, long recipientId) {
- Bundle extras = new Bundle();
- extras.putParcelable("master_secret", masterSecret);
- extras.putLong("recipient_id", recipientId);
- return craftIntent(context, WearReplyReceiver.REPLY_ACTION, extras);
- }
-
- private PendingIntent craftIntent(Context context, String intentAction, Bundle extras) {
+ public PendingIntent getMarkAsReadIntent(Context context) {
long[] threadArray = new long[threads.size()];
- int index = 0;
+ int index = 0;
for (long thread : threads) {
Log.w("NotificationState", "Added thread: " + thread);
threadArray[index++] = thread;
}
- Intent intent = new Intent(intentAction);
- intent.putExtra("thread_ids", threadArray);
- intent.putExtras(extras);
+ Intent intent = new Intent(MarkReadReceiver.CLEAR_ACTION);
+ intent.putExtra(MarkReadReceiver.THREAD_IDS_EXTRA, threadArray);
intent.setPackage(context.getPackageName());
// XXX : This is an Android bug. If we don't pull off the extra
// once before handing off the PendingIntent, the array will be
// truncated to one element when the PendingIntent fires. Thanks guys!
Log.w("NotificationState", "Pending array off intent length: " +
- intent.getLongArrayExtra("thread_ids").length);
+ intent.getLongArrayExtra("thread_ids").length);
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
+
+ public PendingIntent getWearableReplyIntent(Context context, Recipients recipients) {
+ if (threads.size() != 1) throw new AssertionError("We only support replies to single thread notifications!");
+
+ Intent intent = new Intent(WearReplyReceiver.REPLY_ACTION);
+ intent.putExtra(WearReplyReceiver.RECIPIENT_IDS_EXTRA, recipients.getIds());
+ intent.setPackage(context.getPackageName());
+
+ return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ }
+
+ public PendingIntent getQuickReplyIntent(Context context, Recipients recipients) {
+ if (threads.size() != 1) throw new AssertionError("We only support replies to single thread notifications!");
+
+ Intent intent = new Intent(context, ConversationPopupActivity.class);
+ intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients.getIds());
+ intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, (long)threads.toArray()[0]);
+ intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
+
+ return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ }
+
+
}
diff --git a/src/org/thoughtcrime/securesms/notifications/WearReplyReceiver.java b/src/org/thoughtcrime/securesms/notifications/WearReplyReceiver.java
index 6929c81f11..302f547a8f 100644
--- a/src/org/thoughtcrime/securesms/notifications/WearReplyReceiver.java
+++ b/src/org/thoughtcrime/securesms/notifications/WearReplyReceiver.java
@@ -17,70 +17,67 @@
package org.thoughtcrime.securesms.notifications;
-import android.app.NotificationManager;
-import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.support.annotation.Nullable;
import android.support.v4.app.RemoteInput;
-import android.util.Log;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.DatabaseFactory;
-import org.thoughtcrime.securesms.recipients.Recipient;
+import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
import org.thoughtcrime.securesms.recipients.RecipientFactory;
-import org.thoughtcrime.securesms.recipients.RecipientProvider;
import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.sms.MessageSender;
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
+import ws.com.google.android.mms.pdu.PduBody;
+
/**
* Get the response text from the Wearable Device and sends an message as a reply
- *
- * @author Alix Ducros (Ported to TextSecure-Codebase by Christoph Haefner)
*/
-public class WearReplyReceiver extends BroadcastReceiver {
+public class WearReplyReceiver extends MasterSecretBroadcastReceiver {
- public static final String TAG = WearReplyReceiver.class.getSimpleName();
- public static final String REPLY_ACTION = "org.thoughtcrime.securesms.notifications.WEAR_REPLY";
+ public static final String TAG = WearReplyReceiver.class.getSimpleName();
+ public static final String REPLY_ACTION = "org.thoughtcrime.securesms.notifications.WEAR_REPLY";
+ public static final String RECIPIENT_IDS_EXTRA = "recipient_ids";
@Override
- public void onReceive(final Context context, Intent intent) {
- if (!intent.getAction().equals(REPLY_ACTION))
- return;
+ protected void onReceive(final Context context, Intent intent,
+ final @Nullable MasterSecret masterSecret)
+ {
+ if (!REPLY_ACTION.equals(intent.getAction())) return;
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
- if (remoteInput == null)
- return;
- final long[] threadIds = intent.getLongArrayExtra("thread_ids");
- final MasterSecret masterSecret = intent.getParcelableExtra("master_secret");
- final long recipientId = intent.getLongExtra("recipient_id", -1);
+ if (remoteInput == null) return;
+
+ final long[] recipientIds = intent.getLongArrayExtra(RECIPIENT_IDS_EXTRA);
final CharSequence responseText = remoteInput.getCharSequence(MessageNotifier.EXTRA_VOICE_REPLY);
+ final Recipients recipients = RecipientFactory.getRecipientsForIds(context, recipientIds, false);
- final Recipients recipients = RecipientFactory.getRecipientsForIds(context, new long[]{recipientId}, false);
-
- if (threadIds != null && masterSecret != null) {
-
- ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
- .cancel(MessageNotifier.NOTIFICATION_ID);
-
+ if (masterSecret != null && responseText != null) {
new AsyncTask() {
@Override
protected Void doInBackground(Void... params) {
- for (long threadId : threadIds) {
- Log.w(TAG, "Marking as read: " + threadId);
- DatabaseFactory.getThreadDatabase(context).setRead(threadId);
+ long threadId;
+
+ if (recipients.isGroupRecipient()) {
+ OutgoingMediaMessage reply = new OutgoingMediaMessage(context, recipients, new PduBody(), responseText.toString(), 0);
+ threadId = MessageSender.send(context, masterSecret, reply, -1, false);
+ } else {
+ OutgoingTextMessage reply = new OutgoingTextMessage(recipients, responseText.toString());
+ threadId = MessageSender.send(context, masterSecret, reply, -1, false);
}
- OutgoingTextMessage reply = new OutgoingTextMessage(recipients, responseText.toString());
- MessageSender.send(context, masterSecret, reply, threadIds[0], false);
-
+ DatabaseFactory.getThreadDatabase(context).setRead(threadId);
MessageNotifier.updateNotification(context, masterSecret);
+
return null;
}
}.execute();
}
+
}
}