Fix up wearable reply stuff a little.
1) Don't include MasterSecret in PendingIntents. 2) Correctly reply to non-push group threads, rather than just an individual in that group. // FREEBIE
This commit is contained in:
parent
f0b2cc5590
commit
13eed3baa7
7 changed files with 102 additions and 93 deletions
|
@ -981,15 +981,6 @@
|
|||
<!-- transport_selection_list_item -->
|
||||
<string name="transport_selection_list_item__transport_icon">Transport icon</string>
|
||||
|
||||
|
||||
<!-- Wear Reply -->
|
||||
<string name="wear_reply_label">Reply</string>
|
||||
<string-array name="wear_replies">
|
||||
<item>Yes</item>
|
||||
<item>No</item>
|
||||
<item>OK</item>
|
||||
<item>Thanks</item>
|
||||
</string-array>
|
||||
<!-- EOF -->
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -5,25 +5,29 @@ 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 {
|
||||
|
||||
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);
|
||||
|
@ -32,7 +36,7 @@ public class MarkReadReceiver extends BroadcastReceiver {
|
|||
@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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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<NotificationItem> 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));
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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,20 +70,7 @@ 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;
|
||||
|
||||
|
@ -92,9 +79,8 @@ public class NotificationState {
|
|||
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
|
||||
|
@ -105,4 +91,27 @@ public class NotificationState {
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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 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<Void, Void, Void>() {
|
||||
@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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue