Skip to content

Commit

Permalink
Notification action receivers (#9)
Browse files Browse the repository at this point in the history
* Fix bug in media preview activity

* Add reply broascast and receiver to notification reply action button
  • Loading branch information
jlewis13 authored Oct 9, 2019
1 parent b811e80 commit 2e72c29
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app/src/dev/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
android:name="io.forsta.relay.receivers.NotificationReplyReceiver"
android:exported="false">
<intent-filter>
<action android:name="io.forsta.librelay.dev.notifications.REPLY_EVENT"/>
<action android:name="io.forsta.librelay.dev.notifications.REPLY"/>
</intent-filter>
</receiver>
</application>
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/io/forsta/relay/MediaPreviewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,12 @@ public class MediaPreviewActivity extends AuthenticationRequiredActionBarActivit
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
this.setTheme(R.style.Application_LightNoActionBar);
dynamicLanguage.onCreate(this);

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.media_preview_activity);

initializeViews();
Expand All @@ -97,6 +95,7 @@ private void initializeActionBar() {
getSupportActionBar().setTitle(recipient == null ? getString(R.string.MediaPreviewActivity_you)
: recipient.toShortString());
getSupportActionBar().setSubtitle(relativeTimeSpan);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,25 @@
import android.content.Intent;
import android.util.Log;

public class NotificationReplyReceiver extends BroadcastReceiver {
import io.forsta.librelay.notifications.ReplyReceiver;
import io.forsta.relay.ConversationActivity;
import io.forsta.relay.ConversationListActivity;

public class NotificationReplyReceiver extends ReplyReceiver {
private static final String TAG = NotificationReplyReceiver.class.getSimpleName();

@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "notification reply intent received for threadId: " + intent.getLongExtra("thread_id", -1));
long threadId = intent.getLongExtra(ReplyReceiver.THREAD_ID, -1);
Log.d(TAG, "notification reply intent received for threadId: " + threadId);
Intent replyIntent = new Intent();
if (threadId == -1) {
replyIntent.setClassName(context.getPackageName(), ConversationListActivity.class.getName());
} else {
replyIntent.setClassName(context.getPackageName(), ConversationActivity.class.getName());
replyIntent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
}
replyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(replyIntent);
}
}
2 changes: 1 addition & 1 deletion app/src/prod/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
android:name="io.forsta.relay.receivers.NotificationReplyReceiver"
android:exported="false">
<intent-filter>
<action android:name="io.forsta.librelay.notifications.REPLY_EVENT"/>
<action android:name="io.forsta.librelay.notifications.REPLY"/>
</intent-filter>
</receiver>
</application>
Expand Down
8 changes: 5 additions & 3 deletions librelay/dev/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@
<action android:name="io.forsta.librelay.dev.notifications.CLEAR"/>
</intent-filter>
</receiver>

<receiver android:name="io.forsta.librelay.notifications.ReplyReceiver">
<intent-filter>
<action android:name="io.forsta.librelay.dev.notifications.REPLY"/>
</intent-filter>
</receiver>
<receiver
android:name="io.forsta.librelay.service.RegistrationReceiver"
android:exported="false">
Expand All @@ -56,7 +60,5 @@
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<receiver android:name="io.forsta.librelay.notifications.MessageNotifier$DeleteReceiver">
</receiver>
</application>
</manifest>
8 changes: 5 additions & 3 deletions librelay/prod/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@
<action android:name="io.forsta.librelay.notifications.CLEAR"/>
</intent-filter>
</receiver>

<receiver android:name="io.forsta.librelay.notifications.ReplyReceiver">
<intent-filter>
<action android:name="io.forsta.librelay.notifications.REPLY"/>
</intent-filter>
</receiver>
<receiver
android:name="io.forsta.librelay.service.RegistrationReceiver"
android:exported="false">
Expand All @@ -56,7 +60,5 @@
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<receiver android:name="io.forsta.librelay.notifications.MessageNotifier$DeleteReceiver">
</receiver>
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public AbstractNotificationBuilder(Context context, NotificationPrivacyPreferenc
this.context = context;
this.privacy = privacy;

setColor(context.getResources().getColor(R.color.textsecure_primary));
setSmallIcon(R.drawable.icon_notification);
setChannelId(NotificationChannels.getMessagesChannel(context));
setLed();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ public class MarkReadReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent)
{
Log.w(TAG, "Received CLEAR_ACTION");
if (!CLEAR_ACTION.equals(intent.getAction()))
return;

final long[] threadIds = intent.getLongArrayExtra(THREAD_IDS_EXTRA);

if (threadIds != null) {
Log.w("TAG", "threadIds length: " + threadIds.length);

((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE))
.cancel(MessageNotifier.NOTIFICATION_ID);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private static void sendSingleThreadNotification(@NonNull Context context,
if (timestamp != 0) builder.setWhen(timestamp);

builder.addActions(notificationState.getMarkAsReadIntent(context),
notificationState.getQuickReplyIntent(context, notifications.get(0).getThreadId()));
notificationState.getReplyIntent(context, notifications.get(0).getThreadId()));

ListIterator<NotificationItem> iterator = notifications.listIterator(notifications.size());

Expand Down Expand Up @@ -299,14 +299,6 @@ private static void updateBadge(Context context, int count) {
}
}

public static class DeleteReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

}
}

private static boolean showThreadNotification(Context context, long threadId) {
ThreadPreferenceDatabase.ThreadPreference threadPreference = DbFactory.getThreadPreferenceDatabase(context).getThreadPreferences(threadId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@ public class MultipleRecipientNotificationBuilder extends AbstractNotificationBu
public MultipleRecipientNotificationBuilder(Context context, NotificationPrivacyPreference privacy) {
super(context, privacy);

setColor(context.getResources().getColor(R.color.textsecure_primary));
setSmallIcon(R.drawable.icon_notification);
setContentTitle(context.getString(R.string.app_name));
// TODO Reference to ConversationListActivity needs to be removed
// setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, ConversationListActivity.class), 0));
setCategory(NotificationCompat.CATEGORY_MESSAGE);
setPriority(NotificationCompat.PRIORITY_HIGH);
setDeleteIntent(PendingIntent.getBroadcast(context, 0, new Intent(context, MessageNotifier.DeleteReceiver.class), 0));
setContentIntent(PendingIntent.getBroadcast(context, 0, new Intent(context, ReplyReceiver.class), 0));
}

public void setMessageCount(int messageCount, int threadCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
import io.forsta.librelay.database.RecipientPreferenceDatabase;

public class NotificationState {

private static final String REPLY_EVENT = BuildConfig.APPLICATION_ID + "." + BuildConfig.FLAVOR + ".notifications.REPLY_EVENT";

private final LinkedList<NotificationItem> notifications = new LinkedList<>();
private final LinkedHashSet<Long> threads = new LinkedHashSet<>();
private boolean notify = false;
Expand Down Expand Up @@ -119,13 +116,12 @@ public PendingIntent getMarkAsReadIntent(Context context) {
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}

public PendingIntent getQuickReplyIntent(Context context, long threadId) {
public PendingIntent getReplyIntent(Context context, long threadId) {
if (threads.size() != 1) return null;

Intent intent = new Intent(REPLY_EVENT);
intent.putExtra("thread_id", 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);
}

Expand Down
20 changes: 20 additions & 0 deletions librelay/src/io/forsta/librelay/notifications/ReplyReceiver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.forsta.librelay.notifications;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import io.forsta.librelay.BuildConfig;

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 THREAD_ID = "thread_id";

@Override
public void onReceive(Context context, Intent intent) {
Log.w(TAG, "onReceive");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ public SingleRecipientNotificationBuilder(@NonNull Context context,
@NonNull NotificationPrivacyPreference privacy)
{
super(context, privacy);

setSmallIcon(R.drawable.icon_notification);
setColor(context.getResources().getColor(R.color.textsecure_primary));
setCategory(NotificationCompat.CATEGORY_MESSAGE);

if (!NotificationChannels.supported()) {
Expand Down

0 comments on commit 2e72c29

Please sign in to comment.