From 921a17966c17ce07be784fc1f21639e133612332 Mon Sep 17 00:00:00 2001 From: John D Lewis Date: Wed, 16 Oct 2019 08:24:20 -0600 Subject: [PATCH] Notification updates (#11) * Add notification update receiver * Fix bug in call activity intent --- app/src/dev/AndroidManifest.xml | 13 +++++++ .../receivers/NotificationUpdateReceiver.java | 18 ++++++++++ app/src/prod/AndroidManifest.xml | 6 ++-- librelay/AndroidManifest.xml | 2 -- librelay/prod/AndroidManifest.xml | 8 ++--- .../forsta/librelay/jobs/PushDecryptJob.java | 1 - .../notifications/MarkReadReceiver.java | 4 +-- .../notifications/MessageNotifier.java | 1 - .../NotificationUpdateReceiver.java | 35 +++++++++++++++++++ .../librelay/notifications/ReplyReceiver.java | 11 +++++- .../librelay/service/WebRtcCallService.java | 3 +- 11 files changed, 86 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/io/forsta/relay/receivers/NotificationUpdateReceiver.java create mode 100644 librelay/src/io/forsta/librelay/notifications/NotificationUpdateReceiver.java diff --git a/app/src/dev/AndroidManifest.xml b/app/src/dev/AndroidManifest.xml index d0b1ed4..f071dc8 100644 --- a/app/src/dev/AndroidManifest.xml +++ b/app/src/dev/AndroidManifest.xml @@ -23,6 +23,19 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/io/forsta/relay/receivers/NotificationUpdateReceiver.java b/app/src/main/java/io/forsta/relay/receivers/NotificationUpdateReceiver.java new file mode 100644 index 0000000..b4fcfe8 --- /dev/null +++ b/app/src/main/java/io/forsta/relay/receivers/NotificationUpdateReceiver.java @@ -0,0 +1,18 @@ +package io.forsta.relay.receivers; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +public class NotificationUpdateReceiver extends BroadcastReceiver { + private static final String TAG = io.forsta.librelay.notifications.NotificationUpdateReceiver.class.getSimpleName(); + + + @Override + public void onReceive(Context context, Intent intent) { + Log.w(TAG, "Received notification update"); + + + } +} diff --git a/app/src/prod/AndroidManifest.xml b/app/src/prod/AndroidManifest.xml index 61a0be4..64dc84f 100644 --- a/app/src/prod/AndroidManifest.xml +++ b/app/src/prod/AndroidManifest.xml @@ -6,14 +6,14 @@ android:name="io.forsta.relay.receivers.RegistrationReceiver" android:exported="false"> - + - + @@ -21,7 +21,7 @@ android:name="io.forsta.relay.receivers.NotificationReplyReceiver" android:exported="false"> - + diff --git a/librelay/AndroidManifest.xml b/librelay/AndroidManifest.xml index df4fbc8..81eaa78 100644 --- a/librelay/AndroidManifest.xml +++ b/librelay/AndroidManifest.xml @@ -125,8 +125,6 @@ - diff --git a/librelay/prod/AndroidManifest.xml b/librelay/prod/AndroidManifest.xml index e8c3138..40ca0b5 100644 --- a/librelay/prod/AndroidManifest.xml +++ b/librelay/prod/AndroidManifest.xml @@ -39,24 +39,24 @@ android:enabled="true" android:exported="true"> - + - + - + - + diff --git a/librelay/src/io/forsta/librelay/jobs/PushDecryptJob.java b/librelay/src/io/forsta/librelay/jobs/PushDecryptJob.java index 21b6962..f550634 100644 --- a/librelay/src/io/forsta/librelay/jobs/PushDecryptJob.java +++ b/librelay/src/io/forsta/librelay/jobs/PushDecryptJob.java @@ -16,7 +16,6 @@ import io.forsta.librelay.database.DbFactory; import io.forsta.librelay.database.MessageDatabase; import io.forsta.librelay.messaging.MessageFactory; -import io.forsta.librelay.recipients.Recipient; import io.forsta.librelay.service.ForstaServiceAccountManager; import io.forsta.librelay.util.InvalidMessagePayloadException; import io.forsta.librelay.BuildConfig; diff --git a/librelay/src/io/forsta/librelay/notifications/MarkReadReceiver.java b/librelay/src/io/forsta/librelay/notifications/MarkReadReceiver.java index 1001cbc..f81711e 100644 --- a/librelay/src/io/forsta/librelay/notifications/MarkReadReceiver.java +++ b/librelay/src/io/forsta/librelay/notifications/MarkReadReceiver.java @@ -22,8 +22,8 @@ public class MarkReadReceiver extends BroadcastReceiver { - private static final String TAG = MarkReadReceiver.class.getSimpleName(); - public static final String CLEAR_ACTION = BuildConfig.APPLICATION_ID + "." + BuildConfig.FLAVOR + ".notifications.CLEAR"; + private static final String TAG = MarkReadReceiver.class.getSimpleName(); + public static final String CLEAR_ACTION = BuildConfig.APPLICATION_ID + "." + BuildConfig.FLAVOR + ".notifications.CLEAR"; public static final String THREAD_IDS_EXTRA = "thread_ids"; @Override diff --git a/librelay/src/io/forsta/librelay/notifications/MessageNotifier.java b/librelay/src/io/forsta/librelay/notifications/MessageNotifier.java index 4f83290..4401edd 100644 --- a/librelay/src/io/forsta/librelay/notifications/MessageNotifier.java +++ b/librelay/src/io/forsta/librelay/notifications/MessageNotifier.java @@ -73,7 +73,6 @@ public static void notifyMessageDeliveryFailed(Context context, long threadId) { .notify((int)threadId, builder.build()); } - // Main entry point for incoming message notifications. public static void updateNotification(@NonNull Context context, long threadId) { diff --git a/librelay/src/io/forsta/librelay/notifications/NotificationUpdateReceiver.java b/librelay/src/io/forsta/librelay/notifications/NotificationUpdateReceiver.java new file mode 100644 index 0000000..67065d1 --- /dev/null +++ b/librelay/src/io/forsta/librelay/notifications/NotificationUpdateReceiver.java @@ -0,0 +1,35 @@ +package io.forsta.librelay.notifications; + +import android.app.PendingIntent; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +import io.forsta.librelay.BuildConfig; + +public class NotificationUpdateReceiver extends BroadcastReceiver { + private static final String TAG = NotificationUpdateReceiver.class.getSimpleName(); + + public static final String UPDATE_ACTION = BuildConfig.APPLICATION_ID + "." + BuildConfig.FLAVOR + ".notifications.UPDATE"; + public static final String THREAD_ID = "thread_id"; + + @Override + public void onReceive(Context context, Intent intent) { + Log.w(TAG, "Notification update received"); + long threadId = intent.getLongExtra(THREAD_ID, -1); + if (threadId > 0) { + MessageNotifier.updateNotification(context, threadId); + } else { + MessageNotifier.updateNotification(context); + } + } + + public static Intent getUpdateIntent(Context context, long threadId) { + Intent intent = new Intent(UPDATE_ACTION); + intent.putExtra(ReplyReceiver.THREAD_ID, threadId); + intent.setPackage(context.getPackageName()); + return intent; + } + +} diff --git a/librelay/src/io/forsta/librelay/notifications/ReplyReceiver.java b/librelay/src/io/forsta/librelay/notifications/ReplyReceiver.java index c9f827b..855ad83 100644 --- a/librelay/src/io/forsta/librelay/notifications/ReplyReceiver.java +++ b/librelay/src/io/forsta/librelay/notifications/ReplyReceiver.java @@ -1,5 +1,6 @@ package io.forsta.librelay.notifications; +import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -10,11 +11,19 @@ public class ReplyReceiver extends BroadcastReceiver { private static final String TAG = ReplyReceiver.class.getSimpleName(); - public static final String REPLY_ACTION = BuildConfig.APPLICATION_ID + "." + BuildConfig.FLAVOR + ".notifications.REPLY"; + public static final String REPLY_ACTION = BuildConfig.APPLICATION_ID + "." + BuildConfig.FLAVOR + ".notifications.REPLY"; public static final String THREAD_ID = "thread_id"; @Override public void onReceive(Context context, Intent intent) { Log.w(TAG, "onReceive"); } + + + public static PendingIntent getReplyIntent(Context context, long threadId) { + Intent intent = new Intent(ReplyReceiver.REPLY_ACTION); + intent.putExtra(ReplyReceiver.THREAD_ID, threadId); + intent.setPackage(context.getPackageName()); + return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + } } diff --git a/librelay/src/io/forsta/librelay/service/WebRtcCallService.java b/librelay/src/io/forsta/librelay/service/WebRtcCallService.java index 5a82772..9c0e75a 100644 --- a/librelay/src/io/forsta/librelay/service/WebRtcCallService.java +++ b/librelay/src/io/forsta/librelay/service/WebRtcCallService.java @@ -1473,8 +1473,7 @@ public Boolean call() throws Exception { } private void startCallCardActivity() { - Intent activityIntent = new Intent(); - activityIntent.setClass(this, WebRtcCallActivity.class); + Intent activityIntent = new Intent(this, WebRtcCallActivity.class); activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(activityIntent); }