Commit 8e732d88 authored by akwizgran's avatar akwizgran

Merge branch '47-sign-in-reminder' into 'master'

Do not show sign-in reminder once PasswordActivity was opened

Closes #47

See merge request !879
parents 7e009cea 0b2594a6
......@@ -10,6 +10,7 @@ import android.content.Intent;
import android.net.Uri;
import android.support.annotation.StringRes;
import android.support.annotation.UiThread;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.support.v4.content.ContextCompat;
......@@ -33,8 +34,10 @@ import org.briarproject.bramble.util.StringUtils;
import org.briarproject.briar.R;
import org.briarproject.briar.android.contact.ConversationActivity;
import org.briarproject.briar.android.forum.ForumActivity;
import org.briarproject.briar.android.login.SignInReminderReceiver;
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
import org.briarproject.briar.android.privategroup.conversation.GroupActivity;
import org.briarproject.briar.android.splash.SplashScreenActivity;
import org.briarproject.briar.android.util.BriarNotificationBuilder;
import org.briarproject.briar.api.android.AndroidNotificationManager;
import org.briarproject.briar.api.blog.event.BlogPostAddedEvent;
......@@ -64,11 +67,14 @@ import static android.app.Notification.DEFAULT_SOUND;
import static android.app.Notification.DEFAULT_VIBRATE;
import static android.app.Notification.VISIBILITY_SECRET;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.content.Context.NOTIFICATION_SERVICE;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.os.Build.VERSION.SDK_INT;
import static android.support.v4.app.NotificationCompat.CATEGORY_MESSAGE;
import static android.support.v4.app.NotificationCompat.CATEGORY_SOCIAL;
import static android.support.v4.app.NotificationCompat.PRIORITY_LOW;
import static java.util.logging.Level.WARNING;
import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
......@@ -107,6 +113,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
private int nextRequestId = 0;
private ContactId blockedContact = null;
private GroupId blockedGroup = null;
private boolean blockSignInReminder = false;
private boolean blockContacts = false, blockGroups = false;
private boolean blockForums = false, blockBlogs = false;
private boolean blockIntroductions = false;
......@@ -612,6 +619,58 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
this::clearIntroductionSuccessNotification);
}
@Override
public void showSignInNotification() {
if (blockSignInReminder) return;
if (SDK_INT >= 26) {
NotificationChannel channel =
new NotificationChannel(REMINDER_CHANNEL_ID, appContext
.getString(
R.string.reminder_notification_channel_title),
IMPORTANCE_LOW);
channel.setLockscreenVisibility(
NotificationCompat.VISIBILITY_SECRET);
notificationManager.createNotificationChannel(channel);
}
NotificationCompat.Builder b =
new NotificationCompat.Builder(appContext, REMINDER_CHANNEL_ID);
b.setSmallIcon(R.drawable.ic_signout);
b.setColor(ContextCompat.getColor(appContext, R.color.briar_primary));
b.setContentTitle(
appContext.getText(R.string.reminder_notification_title));
b.setContentText(
appContext.getText(R.string.reminder_notification_text));
b.setAutoCancel(true);
b.setWhen(0); // Don't show the time
b.setPriority(PRIORITY_LOW);
// Add a 'Dismiss' action
String actionTitle =
appContext.getString(R.string.reminder_notification_dismiss);
Intent i1 = new Intent(appContext, SignInReminderReceiver.class);
i1.setAction(ACTION_DISMISS_REMINDER);
PendingIntent actionIntent =
PendingIntent.getBroadcast(appContext, 0, i1, 0);
b.addAction(0, actionTitle, actionIntent);
Intent i = new Intent(appContext, SplashScreenActivity.class);
i.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP);
b.setContentIntent(PendingIntent.getActivity(appContext, 0, i, 0));
notificationManager.notify(REMINDER_NOTIFICATION_ID, b.build());
}
@Override
public void clearSignInNotification() {
notificationManager.cancel(REMINDER_NOTIFICATION_ID);
}
@Override
public void blockSignInNotification() {
blockSignInReminder = true;
}
@Override
public void blockNotification(GroupId g) {
androidExecutor.runOnUiThread((Runnable) () -> blockedGroup = g);
......
package org.briarproject.briar.android.login;
import android.app.NotificationManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
......@@ -20,6 +19,7 @@ import org.briarproject.briar.android.activity.BaseActivity;
import org.briarproject.briar.android.controller.BriarController;
import org.briarproject.briar.android.controller.handler.UiResultHandler;
import org.briarproject.briar.android.util.UiUtils;
import org.briarproject.briar.api.android.AndroidNotificationManager;
import javax.inject.Inject;
......@@ -29,13 +29,15 @@ import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;
import static org.briarproject.briar.api.android.AndroidNotificationManager.REMINDER_NOTIFICATION_ID;
public class PasswordActivity extends BaseActivity {
@Inject
AccountManager accountManager;
@Inject
AndroidNotificationManager notificationManager;
@Inject
PasswordController passwordController;
......@@ -95,10 +97,8 @@ public class PasswordActivity extends BaseActivity {
setResult(RESULT_OK);
finish();
} else {
// Remove sign-in reminder notification
NotificationManager nm = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
nm.cancel(REMINDER_NOTIFICATION_ID);
notificationManager.blockSignInNotification();
notificationManager.clearSignInNotification();
}
}
......
package org.briarproject.briar.android.login;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.ContextCompat;
import org.briarproject.bramble.api.account.AccountManager;
import org.briarproject.briar.R;
import org.briarproject.briar.android.AndroidComponent;
import org.briarproject.briar.android.BriarApplication;
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
import org.briarproject.briar.api.android.AndroidNotificationManager;
import javax.inject.Inject;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.content.Context.NOTIFICATION_SERVICE;
import static android.content.Intent.ACTION_BOOT_COMPLETED;
import static android.content.Intent.ACTION_MY_PACKAGE_REPLACED;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.os.Build.VERSION.SDK_INT;
import static android.support.v4.app.NotificationCompat.PRIORITY_LOW;
import static android.support.v4.app.NotificationCompat.VISIBILITY_SECRET;
import static org.briarproject.briar.android.TestingConstants.FEATURE_FLAG_SIGN_IN_REMINDER;
import static org.briarproject.briar.android.settings.SettingsFragment.NOTIFY_SIGN_IN;
import static org.briarproject.briar.api.android.AndroidNotificationManager.REMINDER_CHANNEL_ID;
import static org.briarproject.briar.api.android.AndroidNotificationManager.REMINDER_NOTIFICATION_ID;
import static org.briarproject.briar.api.android.AndroidNotificationManager.ACTION_DISMISS_REMINDER;
public class SignInReminderReceiver extends BroadcastReceiver {
public static final String DISMISS_REMINDER = "dismissReminder";
@Inject
AccountManager accountManager;
@Inject
AndroidNotificationManager notificationManager;
@Override
public void onReceive(Context ctx, Intent intent) {
......@@ -55,58 +41,12 @@ public class SignInReminderReceiver extends BroadcastReceiver {
!accountManager.hasDatabaseKey()) {
SharedPreferences prefs = app.getDefaultSharedPreferences();
if (prefs.getBoolean(NOTIFY_SIGN_IN, true)) {
showSignInNotification(ctx);
notificationManager.showSignInNotification();
}
}
} else if (action.equals(DISMISS_REMINDER)) {
dismissReminder(ctx);
}
}
private void showSignInNotification(Context ctx) {
NotificationManager nm = (NotificationManager)
ctx.getSystemService(NOTIFICATION_SERVICE);
if (nm == null) return;
if (SDK_INT >= 26) {
NotificationChannel channel =
new NotificationChannel(REMINDER_CHANNEL_ID, ctx.getString(
R.string.reminder_notification_channel_title),
IMPORTANCE_LOW);
channel.setLockscreenVisibility(VISIBILITY_SECRET);
nm.createNotificationChannel(channel);
} else if (action.equals(ACTION_DISMISS_REMINDER)) {
notificationManager.clearSignInNotification();
}
NotificationCompat.Builder b =
new NotificationCompat.Builder(ctx, REMINDER_CHANNEL_ID);
b.setSmallIcon(R.drawable.ic_signout);
b.setColor(ContextCompat.getColor(ctx, R.color.briar_primary));
b.setContentTitle(ctx.getText(R.string.reminder_notification_title));
b.setContentText(ctx.getText(R.string.reminder_notification_text));
b.setAutoCancel(true);
b.setWhen(0); // Don't show the time
b.setPriority(PRIORITY_LOW);
// Add a 'Dismiss' action
String actionTitle =
ctx.getString(R.string.reminder_notification_dismiss);
Intent i1 = new Intent(ctx, SignInReminderReceiver.class);
i1.setAction(DISMISS_REMINDER);
PendingIntent actionIntent = PendingIntent.getBroadcast(ctx, 0, i1, 0);
b.addAction(0, actionTitle, actionIntent);
Intent i = new Intent(ctx, NavDrawerActivity.class);
i.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP);
b.setContentIntent(PendingIntent.getActivity(ctx, 0, i, 0));
nm.notify(REMINDER_NOTIFICATION_ID, b.build());
}
private void dismissReminder(Context ctx) {
NotificationManager nm = (NotificationManager)
ctx.getSystemService(NOTIFICATION_SERVICE);
if (nm == null) return;
nm.cancel(REMINDER_NOTIFICATION_ID);
}
}
......@@ -49,6 +49,9 @@ public interface AndroidNotificationManager {
String BLOG_URI = "content://org.briarproject.briar/blog";
String INTRODUCTION_URI = "content://org.briarproject.briar/introduction";
// Actions for pending intents
String ACTION_DISMISS_REMINDER = "dismissReminder";
void clearContactNotification(ContactId c);
void clearAllContactNotifications();
......@@ -67,6 +70,12 @@ public interface AndroidNotificationManager {
void clearAllIntroductionNotifications();
void showSignInNotification();
void clearSignInNotification();
void blockSignInNotification();
void blockContactNotification(ContactId c);
void unblockContactNotification(ContactId c);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment