mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
@@ -134,8 +134,10 @@
|
|||||||
<string name="introduction_response_accepted_received">%1$s accepted the introduction to %2$s.</string>
|
<string name="introduction_response_accepted_received">%1$s accepted the introduction to %2$s.</string>
|
||||||
<string name="introduction_response_declined_received">%1$s declined the introduction to %2$s.</string>
|
<string name="introduction_response_declined_received">%1$s declined the introduction to %2$s.</string>
|
||||||
<string name="introduction_response_declined_received_by_introducee">%1$s says that %2$s declined the introduction.</string>
|
<string name="introduction_response_declined_received_by_introducee">%1$s says that %2$s declined the introduction.</string>
|
||||||
<string name="introduction_success_title">Introduced contact was added</string>
|
<plurals name="introduction_notification_text">
|
||||||
<string name="introduction_success_text">You have been introduced to %1$s.</string>
|
<item quantity="one">New contact added.</item>
|
||||||
|
<item quantity="other">%d new contacts added.</item>
|
||||||
|
</plurals>
|
||||||
|
|
||||||
<!-- Forums -->
|
<!-- Forums -->
|
||||||
<string name="no_forums">You don\'t have any forums yet.\n\nWhy don\'t you create a new one yourself by tapping the + icon at the top?\n\nYou can also ask your contacts to share forums with you.</string>
|
<string name="no_forums">You don\'t have any forums yet.\n\nWhy don\'t you create a new one yourself by tapping the + icon at the top?\n\nYou can also ask your contacts to share forums with you.</string>
|
||||||
|
|||||||
@@ -2,8 +2,11 @@ package org.briarproject.android;
|
|||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
@@ -14,7 +17,6 @@ import org.briarproject.android.api.AndroidExecutor;
|
|||||||
import org.briarproject.android.api.AndroidNotificationManager;
|
import org.briarproject.android.api.AndroidNotificationManager;
|
||||||
import org.briarproject.android.contact.ConversationActivity;
|
import org.briarproject.android.contact.ConversationActivity;
|
||||||
import org.briarproject.android.forum.ForumActivity;
|
import org.briarproject.android.forum.ForumActivity;
|
||||||
import org.briarproject.api.contact.Contact;
|
|
||||||
import org.briarproject.api.contact.ContactId;
|
import org.briarproject.api.contact.ContactId;
|
||||||
import org.briarproject.api.db.DatabaseExecutor;
|
import org.briarproject.api.db.DatabaseExecutor;
|
||||||
import org.briarproject.api.db.DbException;
|
import org.briarproject.api.db.DbException;
|
||||||
@@ -59,20 +61,38 @@ import static android.support.v4.app.NotificationCompat.CATEGORY_SOCIAL;
|
|||||||
import static android.support.v4.app.NotificationCompat.VISIBILITY_SECRET;
|
import static android.support.v4.app.NotificationCompat.VISIBILITY_SECRET;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static org.briarproject.android.BriarActivity.GROUP_ID;
|
import static org.briarproject.android.BriarActivity.GROUP_ID;
|
||||||
|
import static org.briarproject.android.NavDrawerActivity.INTENT_BLOGS;
|
||||||
|
import static org.briarproject.android.NavDrawerActivity.INTENT_CONTACTS;
|
||||||
|
import static org.briarproject.android.NavDrawerActivity.INTENT_FORUMS;
|
||||||
import static org.briarproject.android.fragment.SettingsFragment.PREF_NOTIFY_BLOG;
|
import static org.briarproject.android.fragment.SettingsFragment.PREF_NOTIFY_BLOG;
|
||||||
import static org.briarproject.android.fragment.SettingsFragment.SETTINGS_NAMESPACE;
|
import static org.briarproject.android.fragment.SettingsFragment.SETTINGS_NAMESPACE;
|
||||||
|
|
||||||
class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||||
Service, EventListener {
|
Service, EventListener {
|
||||||
|
|
||||||
|
// Notification IDs
|
||||||
private static final int PRIVATE_MESSAGE_NOTIFICATION_ID = 3;
|
private static final int PRIVATE_MESSAGE_NOTIFICATION_ID = 3;
|
||||||
private static final int FORUM_POST_NOTIFICATION_ID = 4;
|
private static final int FORUM_POST_NOTIFICATION_ID = 4;
|
||||||
private static final int BLOG_POST_NOTIFICATION_ID = 5;
|
private static final int BLOG_POST_NOTIFICATION_ID = 5;
|
||||||
private static final int INTRODUCTION_SUCCESS_NOTIFICATION_ID = 6;
|
private static final int INTRODUCTION_SUCCESS_NOTIFICATION_ID = 6;
|
||||||
|
|
||||||
|
// Content URIs to differentiate between pending intents
|
||||||
private static final String CONTACT_URI =
|
private static final String CONTACT_URI =
|
||||||
"content://org.briarproject/contact";
|
"content://org.briarproject/contact";
|
||||||
private static final String FORUM_URI =
|
private static final String FORUM_URI =
|
||||||
"content://org.briarproject/forum";
|
"content://org.briarproject/forum";
|
||||||
|
private static final String BLOG_URI =
|
||||||
|
"content://org.briarproject/blog";
|
||||||
|
|
||||||
|
// Actions for intents that are broadcast when notifications are dismissed
|
||||||
|
private static final String CLEAR_PRIVATE_MESSAGE_ACTION =
|
||||||
|
"org.briarproject.briar.CLEAR_PRIVATE_MESSAGE_NOTIFICATION";
|
||||||
|
private static final String CLEAR_FORUM_ACTION =
|
||||||
|
"org.briarproject.briar.CLEAR_FORUM_NOTIFICATION";
|
||||||
|
private static final String CLEAR_BLOG_ACTION =
|
||||||
|
"org.briarproject.briar.CLEAR_BLOG_NOTIFICATION";
|
||||||
|
private static final String CLEAR_INTRODUCTION_ACTION =
|
||||||
|
"org.briarproject.briar.CLEAR_INTRODUCTION_NOTIFICATION";
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(AndroidNotificationManagerImpl.class.getName());
|
Logger.getLogger(AndroidNotificationManagerImpl.class.getName());
|
||||||
@@ -82,16 +102,19 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
private final MessagingManager messagingManager;
|
private final MessagingManager messagingManager;
|
||||||
private final AndroidExecutor androidExecutor;
|
private final AndroidExecutor androidExecutor;
|
||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
|
private final BroadcastReceiver receiver = new DeleteIntentReceiver();
|
||||||
// The following must only be accessed on the main UI thread
|
|
||||||
private final Map<GroupId, Integer> contactCounts = new HashMap<>();
|
|
||||||
private final Map<GroupId, Integer> forumCounts = new HashMap<>();
|
|
||||||
private final AtomicBoolean used = new AtomicBoolean(false);
|
private final AtomicBoolean used = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
// The following must only be accessed on the AndroidExecutor thread
|
||||||
|
private final Map<GroupId, Integer> contactCounts = new HashMap<>();
|
||||||
|
private final Map<GroupId, Integer> forumCounts = new HashMap<>();
|
||||||
|
private final Map<GroupId, Integer> blogCounts = new HashMap<>();
|
||||||
private int contactTotal = 0, forumTotal = 0, blogTotal = 0;
|
private int contactTotal = 0, forumTotal = 0, blogTotal = 0;
|
||||||
|
private int introductionTotal = 0;
|
||||||
private int nextRequestId = 0;
|
private int nextRequestId = 0;
|
||||||
private GroupId visibleGroup = null;
|
private GroupId blockedGroup = null;
|
||||||
private boolean blogBlocked = false;
|
private boolean blockContacts = false, blockForums = false;
|
||||||
|
private boolean blockBlogs = false, blockIntroductions = false;
|
||||||
|
|
||||||
private volatile Settings settings = new Settings();
|
private volatile Settings settings = new Settings();
|
||||||
|
|
||||||
@@ -109,21 +132,43 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
@Override
|
@Override
|
||||||
public void startService() throws ServiceException {
|
public void startService() throws ServiceException {
|
||||||
if (used.getAndSet(true)) throw new IllegalStateException();
|
if (used.getAndSet(true)) throw new IllegalStateException();
|
||||||
|
// Load settings
|
||||||
try {
|
try {
|
||||||
settings = settingsManager.getSettings(SETTINGS_NAMESPACE);
|
settings = settingsManager.getSettings(SETTINGS_NAMESPACE);
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
throw new ServiceException(e);
|
throw new ServiceException(e);
|
||||||
}
|
}
|
||||||
|
// Register a broadcast receiver for notifications being dismissed
|
||||||
|
Future<Void> f = androidExecutor.submit(new Callable<Void>() {
|
||||||
|
@Override
|
||||||
|
public Void call() {
|
||||||
|
IntentFilter filter = new IntentFilter();
|
||||||
|
filter.addAction(CLEAR_PRIVATE_MESSAGE_ACTION);
|
||||||
|
filter.addAction(CLEAR_FORUM_ACTION);
|
||||||
|
filter.addAction(CLEAR_BLOG_ACTION);
|
||||||
|
filter.addAction(CLEAR_INTRODUCTION_ACTION);
|
||||||
|
appContext.registerReceiver(receiver, filter);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
f.get();
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
throw new ServiceException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopService() throws ServiceException {
|
public void stopService() throws ServiceException {
|
||||||
|
// Clear all notifications and unregister the broadcast receiver
|
||||||
Future<Void> f = androidExecutor.submit(new Callable<Void>() {
|
Future<Void> f = androidExecutor.submit(new Callable<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public Void call() {
|
public Void call() {
|
||||||
clearPrivateMessageNotification();
|
clearPrivateMessageNotification();
|
||||||
clearForumPostNotification();
|
clearForumPostNotification();
|
||||||
|
clearBlogPostNotification();
|
||||||
clearIntroductionSuccessNotification();
|
clearIntroductionSuccessNotification();
|
||||||
|
appContext.unregisterReceiver(receiver);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -135,18 +180,31 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void clearPrivateMessageNotification() {
|
private void clearPrivateMessageNotification() {
|
||||||
|
contactCounts.clear();
|
||||||
|
contactTotal = 0;
|
||||||
Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
|
Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
|
||||||
NotificationManager nm = (NotificationManager) o;
|
NotificationManager nm = (NotificationManager) o;
|
||||||
nm.cancel(PRIVATE_MESSAGE_NOTIFICATION_ID);
|
nm.cancel(PRIVATE_MESSAGE_NOTIFICATION_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearForumPostNotification() {
|
private void clearForumPostNotification() {
|
||||||
|
forumCounts.clear();
|
||||||
|
forumTotal = 0;
|
||||||
Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
|
Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
|
||||||
NotificationManager nm = (NotificationManager) o;
|
NotificationManager nm = (NotificationManager) o;
|
||||||
nm.cancel(FORUM_POST_NOTIFICATION_ID);
|
nm.cancel(FORUM_POST_NOTIFICATION_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void clearBlogPostNotification() {
|
||||||
|
blogCounts.clear();
|
||||||
|
blogTotal = 0;
|
||||||
|
Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
|
||||||
|
NotificationManager nm = (NotificationManager) o;
|
||||||
|
nm.cancel(BLOG_POST_NOTIFICATION_ID);
|
||||||
|
}
|
||||||
|
|
||||||
private void clearIntroductionSuccessNotification() {
|
private void clearIntroductionSuccessNotification() {
|
||||||
|
introductionTotal = 0;
|
||||||
Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
|
Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
|
||||||
NotificationManager nm = (NotificationManager) o;
|
NotificationManager nm = (NotificationManager) o;
|
||||||
nm.cancel(INTRODUCTION_SUCCESS_NOTIFICATION_ID);
|
nm.cancel(INTRODUCTION_SUCCESS_NOTIFICATION_ID);
|
||||||
@@ -158,29 +216,28 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
SettingsUpdatedEvent s = (SettingsUpdatedEvent) e;
|
SettingsUpdatedEvent s = (SettingsUpdatedEvent) e;
|
||||||
if (s.getNamespace().equals(SETTINGS_NAMESPACE)) loadSettings();
|
if (s.getNamespace().equals(SETTINGS_NAMESPACE)) loadSettings();
|
||||||
} else if (e instanceof PrivateMessageReceivedEvent) {
|
} else if (e instanceof PrivateMessageReceivedEvent) {
|
||||||
PrivateMessageReceivedEvent m = (PrivateMessageReceivedEvent) e;
|
PrivateMessageReceivedEvent p = (PrivateMessageReceivedEvent) e;
|
||||||
showPrivateMessageNotification(m.getGroupId());
|
showPrivateMessageNotification(p.getGroupId());
|
||||||
} else if (e instanceof ForumPostReceivedEvent) {
|
} else if (e instanceof ForumPostReceivedEvent) {
|
||||||
ForumPostReceivedEvent m = (ForumPostReceivedEvent) e;
|
ForumPostReceivedEvent f = (ForumPostReceivedEvent) e;
|
||||||
showForumPostNotification(m.getGroupId());
|
showForumPostNotification(f.getGroupId());
|
||||||
} else if (e instanceof BlogPostAddedEvent) {
|
} else if (e instanceof BlogPostAddedEvent) {
|
||||||
BlogPostAddedEvent be = (BlogPostAddedEvent) e;
|
BlogPostAddedEvent b = (BlogPostAddedEvent) e;
|
||||||
showBlogPostNotification(be.getGroupId());
|
showBlogPostNotification(b.getGroupId());
|
||||||
} else if (e instanceof IntroductionRequestReceivedEvent) {
|
} else if (e instanceof IntroductionRequestReceivedEvent) {
|
||||||
ContactId c = ((IntroductionRequestReceivedEvent) e).getContactId();
|
ContactId c = ((IntroductionRequestReceivedEvent) e).getContactId();
|
||||||
showNotificationForPrivateConversation(c);
|
showNotificationForPrivateConversation(c);
|
||||||
} else if (e instanceof IntroductionResponseReceivedEvent) {
|
} else if (e instanceof IntroductionResponseReceivedEvent) {
|
||||||
ContactId c = ((IntroductionResponseReceivedEvent) e).getContactId();
|
ContactId c = ((IntroductionResponseReceivedEvent) e).getContactId();
|
||||||
showNotificationForPrivateConversation(c);
|
showNotificationForPrivateConversation(c);
|
||||||
} else if (e instanceof IntroductionSucceededEvent) {
|
|
||||||
Contact c = ((IntroductionSucceededEvent) e).getContact();
|
|
||||||
showIntroductionSucceededNotification(c);
|
|
||||||
} else if (e instanceof InvitationReceivedEvent) {
|
} else if (e instanceof InvitationReceivedEvent) {
|
||||||
ContactId c = ((InvitationReceivedEvent) e).getContactId();
|
ContactId c = ((InvitationReceivedEvent) e).getContactId();
|
||||||
showNotificationForPrivateConversation(c);
|
showNotificationForPrivateConversation(c);
|
||||||
} else if (e instanceof InvitationResponseReceivedEvent) {
|
} else if (e instanceof InvitationResponseReceivedEvent) {
|
||||||
ContactId c = ((InvitationResponseReceivedEvent) e).getContactId();
|
ContactId c = ((InvitationResponseReceivedEvent) e).getContactId();
|
||||||
showNotificationForPrivateConversation(c);
|
showNotificationForPrivateConversation(c);
|
||||||
|
} else if (e instanceof IntroductionSucceededEvent) {
|
||||||
|
showIntroductionNotification();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,17 +255,17 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void showPrivateMessageNotification(final GroupId g) {
|
||||||
public void showPrivateMessageNotification(final GroupId g) {
|
|
||||||
androidExecutor.execute(new Runnable() {
|
androidExecutor.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
if (blockContacts) return;
|
||||||
|
if (g.equals(blockedGroup)) return;
|
||||||
Integer count = contactCounts.get(g);
|
Integer count = contactCounts.get(g);
|
||||||
if (count == null) contactCounts.put(g, 1);
|
if (count == null) contactCounts.put(g, 1);
|
||||||
else contactCounts.put(g, count + 1);
|
else contactCounts.put(g, count + 1);
|
||||||
contactTotal++;
|
contactTotal++;
|
||||||
if (!g.equals(visibleGroup))
|
updatePrivateMessageNotification();
|
||||||
updatePrivateMessageNotification();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -221,7 +278,6 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
Integer count = contactCounts.remove(g);
|
Integer count = contactCounts.remove(g);
|
||||||
if (count == null) return; // Already cleared
|
if (count == null) return; // Already cleared
|
||||||
contactTotal -= count;
|
contactTotal -= count;
|
||||||
// FIXME: If the notification isn't showing, this may show it
|
|
||||||
updatePrivateMessageNotification();
|
updatePrivateMessageNotification();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -245,7 +301,13 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
b.setDefaults(getDefaults());
|
b.setDefaults(getDefaults());
|
||||||
b.setOnlyAlertOnce(true);
|
b.setOnlyAlertOnce(true);
|
||||||
b.setAutoCancel(true);
|
b.setAutoCancel(true);
|
||||||
|
// Clear the counters if the notification is dismissed
|
||||||
|
Intent clear = new Intent(CLEAR_PRIVATE_MESSAGE_ACTION);
|
||||||
|
PendingIntent delete = PendingIntent.getBroadcast(appContext, 0,
|
||||||
|
clear, 0);
|
||||||
|
b.setDeleteIntent(delete);
|
||||||
if (contactCounts.size() == 1) {
|
if (contactCounts.size() == 1) {
|
||||||
|
// Touching the notification shows the relevant conversation
|
||||||
Intent i = new Intent(appContext, ConversationActivity.class);
|
Intent i = new Intent(appContext, ConversationActivity.class);
|
||||||
GroupId g = contactCounts.keySet().iterator().next();
|
GroupId g = contactCounts.keySet().iterator().next();
|
||||||
i.putExtra(GROUP_ID, g.getBytes());
|
i.putExtra(GROUP_ID, g.getBytes());
|
||||||
@@ -257,9 +319,11 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
t.addNextIntent(i);
|
t.addNextIntent(i);
|
||||||
b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
|
b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
|
||||||
} else {
|
} else {
|
||||||
|
// Touching the notification shows the contact list
|
||||||
Intent i = new Intent(appContext, NavDrawerActivity.class);
|
Intent i = new Intent(appContext, NavDrawerActivity.class);
|
||||||
i.putExtra(NavDrawerActivity.INTENT_CONTACTS, true);
|
i.putExtra(INTENT_CONTACTS, true);
|
||||||
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
|
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
|
i.setData(Uri.parse(CONTACT_URI));
|
||||||
TaskStackBuilder t = TaskStackBuilder.create(appContext);
|
TaskStackBuilder t = TaskStackBuilder.create(appContext);
|
||||||
t.addParentStack(NavDrawerActivity.class);
|
t.addParentStack(NavDrawerActivity.class);
|
||||||
t.addNextIntent(i);
|
t.addNextIntent(i);
|
||||||
@@ -287,16 +351,27 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showForumPostNotification(final GroupId g) {
|
public void clearAllContactNotifications() {
|
||||||
androidExecutor.execute(new Runnable() {
|
androidExecutor.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
clearPrivateMessageNotification();
|
||||||
|
clearIntroductionSuccessNotification();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showForumPostNotification(final GroupId g) {
|
||||||
|
androidExecutor.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (blockForums) return;
|
||||||
|
if (g.equals(blockedGroup)) return;
|
||||||
Integer count = forumCounts.get(g);
|
Integer count = forumCounts.get(g);
|
||||||
if (count == null) forumCounts.put(g, 1);
|
if (count == null) forumCounts.put(g, 1);
|
||||||
else forumCounts.put(g, count + 1);
|
else forumCounts.put(g, count + 1);
|
||||||
forumTotal++;
|
forumTotal++;
|
||||||
if (!g.equals(visibleGroup))
|
updateForumPostNotification();
|
||||||
updateForumPostNotification();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -309,7 +384,6 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
Integer count = forumCounts.remove(g);
|
Integer count = forumCounts.remove(g);
|
||||||
if (count == null) return; // Already cleared
|
if (count == null) return; // Already cleared
|
||||||
forumTotal -= count;
|
forumTotal -= count;
|
||||||
// FIXME: If the notification isn't showing, this may show it
|
|
||||||
updateForumPostNotification();
|
updateForumPostNotification();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -332,7 +406,13 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
b.setDefaults(getDefaults());
|
b.setDefaults(getDefaults());
|
||||||
b.setOnlyAlertOnce(true);
|
b.setOnlyAlertOnce(true);
|
||||||
b.setAutoCancel(true);
|
b.setAutoCancel(true);
|
||||||
|
// Clear the counters if the notification is dismissed
|
||||||
|
Intent clear = new Intent(CLEAR_FORUM_ACTION);
|
||||||
|
PendingIntent delete = PendingIntent.getBroadcast(appContext, 0,
|
||||||
|
clear, 0);
|
||||||
|
b.setDeleteIntent(delete);
|
||||||
if (forumCounts.size() == 1) {
|
if (forumCounts.size() == 1) {
|
||||||
|
// Touching the notification shows the relevant forum
|
||||||
Intent i = new Intent(appContext, ForumActivity.class);
|
Intent i = new Intent(appContext, ForumActivity.class);
|
||||||
GroupId g = forumCounts.keySet().iterator().next();
|
GroupId g = forumCounts.keySet().iterator().next();
|
||||||
i.putExtra(GROUP_ID, g.getBytes());
|
i.putExtra(GROUP_ID, g.getBytes());
|
||||||
@@ -344,9 +424,11 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
t.addNextIntent(i);
|
t.addNextIntent(i);
|
||||||
b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
|
b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
|
||||||
} else {
|
} else {
|
||||||
|
// Touching the notification shows the forum list
|
||||||
Intent i = new Intent(appContext, NavDrawerActivity.class);
|
Intent i = new Intent(appContext, NavDrawerActivity.class);
|
||||||
i.putExtra(NavDrawerActivity.INTENT_FORUMS, true);
|
i.putExtra(INTENT_FORUMS, true);
|
||||||
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
|
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
|
i.setData(Uri.parse(FORUM_URI));
|
||||||
TaskStackBuilder t = TaskStackBuilder.create(appContext);
|
TaskStackBuilder t = TaskStackBuilder.create(appContext);
|
||||||
t.addParentStack(NavDrawerActivity.class);
|
t.addParentStack(NavDrawerActivity.class);
|
||||||
t.addNextIntent(i);
|
t.addNextIntent(i);
|
||||||
@@ -363,28 +445,47 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showBlogPostNotification(final GroupId g) {
|
public void clearAllForumPostNotifications() {
|
||||||
androidExecutor.execute(new Runnable() {
|
androidExecutor.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!blogBlocked) {
|
clearForumPostNotification();
|
||||||
blogTotal++;
|
}
|
||||||
updateBlogPostNotification();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showBlogPostNotification(final GroupId g) {
|
||||||
|
androidExecutor.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (blockBlogs) return;
|
||||||
|
if (g.equals(blockedGroup)) return;
|
||||||
|
Integer count = blogCounts.get(g);
|
||||||
|
if (count == null) blogCounts.put(g, 1);
|
||||||
|
else blogCounts.put(g, count + 1);
|
||||||
|
blogTotal++;
|
||||||
|
updateBlogPostNotification();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearBlogPostNotification() {
|
public void clearBlogPostNotification(final GroupId g) {
|
||||||
blogTotal = 0;
|
androidExecutor.execute(new Runnable() {
|
||||||
Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
|
@Override
|
||||||
NotificationManager nm = (NotificationManager) o;
|
public void run() {
|
||||||
nm.cancel(BLOG_POST_NOTIFICATION_ID);
|
Integer count = blogCounts.remove(g);
|
||||||
|
if (count == null) return; // Already cleared
|
||||||
|
blogTotal -= count;
|
||||||
|
updateBlogPostNotification();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateBlogPostNotification() {
|
private void updateBlogPostNotification() {
|
||||||
if (settings.getBoolean(PREF_NOTIFY_BLOG, true)) {
|
if (blogTotal == 0) {
|
||||||
|
clearBlogPostNotification();
|
||||||
|
} else if (settings.getBoolean(PREF_NOTIFY_BLOG, true)) {
|
||||||
NotificationCompat.Builder b =
|
NotificationCompat.Builder b =
|
||||||
new NotificationCompat.Builder(appContext);
|
new NotificationCompat.Builder(appContext);
|
||||||
b.setSmallIcon(R.drawable.message_notification_icon);
|
b.setSmallIcon(R.drawable.message_notification_icon);
|
||||||
@@ -398,15 +499,20 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
b.setDefaults(getDefaults());
|
b.setDefaults(getDefaults());
|
||||||
b.setOnlyAlertOnce(true);
|
b.setOnlyAlertOnce(true);
|
||||||
b.setAutoCancel(true);
|
b.setAutoCancel(true);
|
||||||
|
// Clear the counters if the notification is dismissed
|
||||||
|
Intent clear = new Intent(CLEAR_BLOG_ACTION);
|
||||||
|
PendingIntent delete = PendingIntent.getBroadcast(appContext, 0,
|
||||||
|
clear, 0);
|
||||||
|
b.setDeleteIntent(delete);
|
||||||
|
// Touching the notification shows the combined blog feed
|
||||||
Intent i = new Intent(appContext, NavDrawerActivity.class);
|
Intent i = new Intent(appContext, NavDrawerActivity.class);
|
||||||
i.putExtra(NavDrawerActivity.INTENT_BLOGS, true);
|
i.putExtra(INTENT_BLOGS, true);
|
||||||
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
|
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
|
i.setData(Uri.parse(BLOG_URI));
|
||||||
TaskStackBuilder t = TaskStackBuilder.create(appContext);
|
TaskStackBuilder t = TaskStackBuilder.create(appContext);
|
||||||
t.addParentStack(NavDrawerActivity.class);
|
t.addParentStack(NavDrawerActivity.class);
|
||||||
t.addNextIntent(i);
|
t.addNextIntent(i);
|
||||||
b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
|
b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= 21) {
|
if (Build.VERSION.SDK_INT >= 21) {
|
||||||
b.setCategory(CATEGORY_SOCIAL);
|
b.setCategory(CATEGORY_SOCIAL);
|
||||||
b.setVisibility(VISIBILITY_SECRET);
|
b.setVisibility(VISIBILITY_SECRET);
|
||||||
@@ -417,12 +523,70 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearAllBlogPostNotifications() {
|
||||||
|
androidExecutor.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
clearBlogPostNotification();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showIntroductionNotification() {
|
||||||
|
androidExecutor.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (blockIntroductions) return;
|
||||||
|
introductionTotal++;
|
||||||
|
updateIntroductionNotification();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateIntroductionNotification() {
|
||||||
|
NotificationCompat.Builder b =
|
||||||
|
new NotificationCompat.Builder(appContext);
|
||||||
|
b.setSmallIcon(R.drawable.introduction_notification);
|
||||||
|
b.setContentTitle(appContext.getText(R.string.app_name));
|
||||||
|
b.setContentText(appContext.getResources().getQuantityString(
|
||||||
|
R.plurals.introduction_notification_text, introductionTotal,
|
||||||
|
introductionTotal));
|
||||||
|
String ringtoneUri = settings.get("notifyRingtoneUri");
|
||||||
|
if (!StringUtils.isNullOrEmpty(ringtoneUri))
|
||||||
|
b.setSound(Uri.parse(ringtoneUri));
|
||||||
|
b.setDefaults(getDefaults());
|
||||||
|
b.setOnlyAlertOnce(true);
|
||||||
|
b.setAutoCancel(true);
|
||||||
|
// Clear the counter if the notification is dismissed
|
||||||
|
Intent clear = new Intent(CLEAR_INTRODUCTION_ACTION);
|
||||||
|
PendingIntent delete = PendingIntent.getBroadcast(appContext, 0,
|
||||||
|
clear, 0);
|
||||||
|
b.setDeleteIntent(delete);
|
||||||
|
// Touching the notification shows the contact list
|
||||||
|
Intent i = new Intent(appContext, NavDrawerActivity.class);
|
||||||
|
i.putExtra(INTENT_CONTACTS, true);
|
||||||
|
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
|
i.setData(Uri.parse(CONTACT_URI));
|
||||||
|
TaskStackBuilder t = TaskStackBuilder.create(appContext);
|
||||||
|
t.addParentStack(NavDrawerActivity.class);
|
||||||
|
t.addNextIntent(i);
|
||||||
|
b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
|
||||||
|
if (Build.VERSION.SDK_INT >= 21) {
|
||||||
|
b.setCategory(CATEGORY_MESSAGE);
|
||||||
|
b.setVisibility(VISIBILITY_SECRET);
|
||||||
|
}
|
||||||
|
Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
|
||||||
|
NotificationManager nm = (NotificationManager) o;
|
||||||
|
nm.notify(INTRODUCTION_SUCCESS_NOTIFICATION_ID, b.build());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void blockNotification(final GroupId g) {
|
public void blockNotification(final GroupId g) {
|
||||||
androidExecutor.execute(new Runnable() {
|
androidExecutor.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
visibleGroup = g;
|
blockedGroup = g;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -432,38 +596,80 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
androidExecutor.execute(new Runnable() {
|
androidExecutor.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (g.equals(visibleGroup)) visibleGroup = null;
|
if (g.equals(blockedGroup)) blockedGroup = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void blockBlogNotification() {
|
public void blockAllContactNotifications() {
|
||||||
androidExecutor.execute(new Runnable() {
|
androidExecutor.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
blogBlocked = true;
|
blockContacts = true;
|
||||||
|
blockIntroductions = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unblockBlogNotification() {
|
public void unblockAllContactNotifications() {
|
||||||
androidExecutor.execute(new Runnable() {
|
androidExecutor.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
blogBlocked = false;
|
blockContacts = false;
|
||||||
|
blockIntroductions = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void blockAllForumPostNotifications() {
|
||||||
|
androidExecutor.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
blockForums = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unblockAllForumPostNotifications() {
|
||||||
|
androidExecutor.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
blockForums = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void blockAllBlogPostNotifications() {
|
||||||
|
androidExecutor.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
blockBlogs = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unblockAllBlogPostNotifications() {
|
||||||
|
androidExecutor.execute(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
blockBlogs = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showNotificationForPrivateConversation(final ContactId c) {
|
private void showNotificationForPrivateConversation(final ContactId c) {
|
||||||
androidExecutor.execute(new Runnable() {
|
dbExecutor.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
GroupId group = messagingManager.getConversationId(c);
|
GroupId g = messagingManager.getConversationId(c);
|
||||||
showPrivateMessageNotification(group);
|
showPrivateMessageNotification(g);
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
if (LOG.isLoggable(WARNING))
|
if (LOG.isLoggable(WARNING))
|
||||||
LOG.log(WARNING, e.toString(), e);
|
LOG.log(WARNING, e.toString(), e);
|
||||||
@@ -472,35 +678,25 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showIntroductionSucceededNotification(final Contact c) {
|
private class DeleteIntentReceiver extends BroadcastReceiver {
|
||||||
androidExecutor.execute(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
NotificationCompat.Builder b =
|
|
||||||
new NotificationCompat.Builder(appContext);
|
|
||||||
b.setSmallIcon(R.drawable.introduction_notification);
|
|
||||||
|
|
||||||
b.setContentTitle(appContext
|
@Override
|
||||||
.getString(R.string.introduction_success_title));
|
public void onReceive(Context context, Intent intent) {
|
||||||
b.setContentText(appContext
|
final String action = intent.getAction();
|
||||||
.getString(R.string.introduction_success_text,
|
androidExecutor.execute(new Runnable() {
|
||||||
c.getAuthor().getName()));
|
@Override
|
||||||
b.setDefaults(getDefaults());
|
public void run() {
|
||||||
b.setAutoCancel(true);
|
if (CLEAR_PRIVATE_MESSAGE_ACTION.equals(action)) {
|
||||||
|
clearPrivateMessageNotification();
|
||||||
Intent i = new Intent(appContext, NavDrawerActivity.class);
|
} else if (CLEAR_FORUM_ACTION.equals(action)) {
|
||||||
i.putExtra(NavDrawerActivity.INTENT_CONTACTS, true);
|
clearForumPostNotification();
|
||||||
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
|
} else if (CLEAR_BLOG_ACTION.equals(action)) {
|
||||||
TaskStackBuilder t = TaskStackBuilder.create(appContext);
|
clearBlogPostNotification();
|
||||||
t.addParentStack(NavDrawerActivity.class);
|
} else if (CLEAR_INTRODUCTION_ACTION.equals(action)) {
|
||||||
t.addNextIntent(i);
|
clearIntroductionSuccessNotification();
|
||||||
b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
|
}
|
||||||
|
}
|
||||||
Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
|
});
|
||||||
NotificationManager nm = (NotificationManager) o;
|
}
|
||||||
nm.notify(INTRODUCTION_SUCCESS_NOTIFICATION_ID, b.build());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,26 +2,37 @@ package org.briarproject.android.api;
|
|||||||
|
|
||||||
import org.briarproject.api.sync.GroupId;
|
import org.briarproject.api.sync.GroupId;
|
||||||
|
|
||||||
/** Manages notifications for private messages and forum posts. */
|
/**
|
||||||
|
* Manages notifications for private messages, forum posts, blog posts and
|
||||||
|
* introductions.
|
||||||
|
*/
|
||||||
public interface AndroidNotificationManager {
|
public interface AndroidNotificationManager {
|
||||||
|
|
||||||
void showPrivateMessageNotification(GroupId g);
|
|
||||||
|
|
||||||
void clearPrivateMessageNotification(GroupId g);
|
void clearPrivateMessageNotification(GroupId g);
|
||||||
|
|
||||||
void showForumPostNotification(GroupId g);
|
void clearAllContactNotifications();
|
||||||
|
|
||||||
void clearForumPostNotification(GroupId g);
|
void clearForumPostNotification(GroupId g);
|
||||||
|
|
||||||
void showBlogPostNotification(GroupId g);
|
void clearAllForumPostNotifications();
|
||||||
|
|
||||||
void clearBlogPostNotification();
|
void clearBlogPostNotification(GroupId g);
|
||||||
|
|
||||||
|
void clearAllBlogPostNotifications();
|
||||||
|
|
||||||
void blockNotification(GroupId g);
|
void blockNotification(GroupId g);
|
||||||
|
|
||||||
void unblockNotification(GroupId g);
|
void unblockNotification(GroupId g);
|
||||||
|
|
||||||
void blockBlogNotification();
|
void blockAllContactNotifications();
|
||||||
|
|
||||||
void unblockBlogNotification();
|
void unblockAllContactNotifications();
|
||||||
|
|
||||||
|
void blockAllForumPostNotifications();
|
||||||
|
|
||||||
|
void unblockAllForumPostNotifications();
|
||||||
|
|
||||||
|
void blockAllBlogPostNotifications();
|
||||||
|
|
||||||
|
void unblockAllBlogPostNotifications();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.briarproject.android.blogs;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
|
||||||
|
import org.briarproject.android.api.AndroidNotificationManager;
|
||||||
import org.briarproject.android.controller.DbControllerImpl;
|
import org.briarproject.android.controller.DbControllerImpl;
|
||||||
import org.briarproject.android.controller.handler.ResultExceptionHandler;
|
import org.briarproject.android.controller.handler.ResultExceptionHandler;
|
||||||
import org.briarproject.api.blogs.Blog;
|
import org.briarproject.api.blogs.Blog;
|
||||||
@@ -38,6 +39,8 @@ public class BlogControllerImpl extends DbControllerImpl
|
|||||||
protected Activity activity;
|
protected Activity activity;
|
||||||
@Inject
|
@Inject
|
||||||
protected EventBus eventBus;
|
protected EventBus eventBus;
|
||||||
|
@Inject
|
||||||
|
protected AndroidNotificationManager notificationManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected volatile BlogManager blogManager;
|
protected volatile BlogManager blogManager;
|
||||||
@@ -69,11 +72,14 @@ public class BlogControllerImpl extends DbControllerImpl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResume() {
|
public void onActivityResume() {
|
||||||
|
notificationManager.blockNotification(groupId);
|
||||||
|
notificationManager.clearBlogPostNotification(groupId);
|
||||||
eventBus.addListener(this);
|
eventBus.addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityPause() {
|
public void onActivityPause() {
|
||||||
|
notificationManager.unblockNotification(groupId);
|
||||||
eventBus.removeListener(this);
|
eventBus.removeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ public class BlogFragment extends BaseFragment implements BlogPostListener {
|
|||||||
@Override
|
@Override
|
||||||
public void injectFragment(ActivityComponent component) {
|
public void injectFragment(ActivityComponent component) {
|
||||||
component.inject(this);
|
component.inject(this);
|
||||||
|
blogController.setGroupId(groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -33,12 +33,13 @@ public class FeedControllerImpl extends DbControllerImpl
|
|||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
@Inject
|
@Inject
|
||||||
AndroidNotificationManager notificationManager;
|
AndroidNotificationManager notificationManager;
|
||||||
|
@Inject
|
||||||
|
protected EventBus eventBus;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected volatile BlogManager blogManager;
|
protected volatile BlogManager blogManager;
|
||||||
@Inject
|
@Inject
|
||||||
protected volatile IdentityManager identityManager;
|
protected volatile IdentityManager identityManager;
|
||||||
@Inject
|
|
||||||
protected volatile EventBus eventBus;
|
|
||||||
|
|
||||||
private volatile OnBlogPostAddedListener listener;
|
private volatile OnBlogPostAddedListener listener;
|
||||||
|
|
||||||
@@ -48,14 +49,14 @@ public class FeedControllerImpl extends DbControllerImpl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
notificationManager.blockBlogNotification();
|
notificationManager.blockAllBlogPostNotifications();
|
||||||
notificationManager.clearBlogPostNotification();
|
notificationManager.clearAllBlogPostNotifications();
|
||||||
eventBus.addListener(this);
|
eventBus.addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
notificationManager.unblockBlogNotification();
|
notificationManager.unblockAllBlogPostNotifications();
|
||||||
eventBus.removeListener(this);
|
eventBus.removeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import android.widget.TextView.OnEditorActionListener;
|
|||||||
import org.briarproject.R;
|
import org.briarproject.R;
|
||||||
import org.briarproject.android.ActivityComponent;
|
import org.briarproject.android.ActivityComponent;
|
||||||
import org.briarproject.android.BriarActivity;
|
import org.briarproject.android.BriarActivity;
|
||||||
|
import org.briarproject.android.api.AndroidNotificationManager;
|
||||||
import org.briarproject.api.FormatException;
|
import org.briarproject.api.FormatException;
|
||||||
import org.briarproject.api.blogs.BlogManager;
|
import org.briarproject.api.blogs.BlogManager;
|
||||||
import org.briarproject.api.blogs.BlogPost;
|
import org.briarproject.api.blogs.BlogPost;
|
||||||
@@ -47,6 +48,9 @@ public class WriteBlogPostActivity extends BriarActivity
|
|||||||
Logger.getLogger(WriteBlogPostActivity.class.getName());
|
Logger.getLogger(WriteBlogPostActivity.class.getName());
|
||||||
private static final String contentType = "text/plain";
|
private static final String contentType = "text/plain";
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected AndroidNotificationManager notificationManager;
|
||||||
|
|
||||||
private TextInputEditText titleInput;
|
private TextInputEditText titleInput;
|
||||||
private EditText bodyInput;
|
private EditText bodyInput;
|
||||||
private Button publishButton;
|
private Button publishButton;
|
||||||
@@ -69,13 +73,8 @@ public class WriteBlogPostActivity extends BriarActivity
|
|||||||
byte[] b = i.getByteArrayExtra(GROUP_ID);
|
byte[] b = i.getByteArrayExtra(GROUP_ID);
|
||||||
if (b == null) throw new IllegalStateException("No Group in intent.");
|
if (b == null) throw new IllegalStateException("No Group in intent.");
|
||||||
groupId = new GroupId(b);
|
groupId = new GroupId(b);
|
||||||
// String blogName = i.getStringExtra(BLOG_NAME);
|
|
||||||
// if (blogName != null) setTitle(blogName);
|
|
||||||
|
|
||||||
setContentView(R.layout.activity_write_blog_post);
|
setContentView(R.layout.activity_write_blog_post);
|
||||||
// String title =
|
|
||||||
// getTitle() + ": " + getString(R.string.blogs_write_blog_post);
|
|
||||||
// setTitle(title);
|
|
||||||
|
|
||||||
TextInputLayout titleLayout =
|
TextInputLayout titleLayout =
|
||||||
(TextInputLayout) findViewById(R.id.titleLayout);
|
(TextInputLayout) findViewById(R.id.titleLayout);
|
||||||
@@ -116,6 +115,18 @@ public class WriteBlogPostActivity extends BriarActivity
|
|||||||
progressBar = (ProgressBar) findViewById(R.id.progressBar);
|
progressBar = (ProgressBar) findViewById(R.id.progressBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
notificationManager.unblockNotification(groupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
notificationManager.blockNotification(groupId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import android.view.ViewGroup;
|
|||||||
|
|
||||||
import org.briarproject.R;
|
import org.briarproject.R;
|
||||||
import org.briarproject.android.ActivityComponent;
|
import org.briarproject.android.ActivityComponent;
|
||||||
|
import org.briarproject.android.api.AndroidNotificationManager;
|
||||||
import org.briarproject.android.fragment.BaseFragment;
|
import org.briarproject.android.fragment.BaseFragment;
|
||||||
import org.briarproject.android.keyagreement.KeyAgreementActivity;
|
import org.briarproject.android.keyagreement.KeyAgreementActivity;
|
||||||
import org.briarproject.android.util.BriarRecyclerView;
|
import org.briarproject.android.util.BriarRecyclerView;
|
||||||
@@ -75,6 +76,8 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
|||||||
ConnectionRegistry connectionRegistry;
|
ConnectionRegistry connectionRegistry;
|
||||||
@Inject
|
@Inject
|
||||||
protected EventBus eventBus;
|
protected EventBus eventBus;
|
||||||
|
@Inject
|
||||||
|
protected AndroidNotificationManager notificationManager;
|
||||||
|
|
||||||
private ContactListAdapter adapter = null;
|
private ContactListAdapter adapter = null;
|
||||||
private BriarRecyclerView list = null;
|
private BriarRecyclerView list = null;
|
||||||
@@ -184,6 +187,8 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
notificationManager.blockAllContactNotifications();
|
||||||
|
notificationManager.clearAllContactNotifications();
|
||||||
eventBus.addListener(this);
|
eventBus.addListener(this);
|
||||||
loadContacts();
|
loadContacts();
|
||||||
list.startPeriodicUpdate();
|
list.startPeriodicUpdate();
|
||||||
@@ -193,6 +198,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
|
|||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
eventBus.removeListener(this);
|
eventBus.removeListener(this);
|
||||||
|
notificationManager.unblockAllContactNotifications();
|
||||||
adapter.clear();
|
adapter.clear();
|
||||||
list.showProgressBar();
|
list.showProgressBar();
|
||||||
list.stopPeriodicUpdate();
|
list.stopPeriodicUpdate();
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import android.view.ViewGroup;
|
|||||||
|
|
||||||
import org.briarproject.R;
|
import org.briarproject.R;
|
||||||
import org.briarproject.android.ActivityComponent;
|
import org.briarproject.android.ActivityComponent;
|
||||||
|
import org.briarproject.android.api.AndroidNotificationManager;
|
||||||
import org.briarproject.android.fragment.BaseEventFragment;
|
import org.briarproject.android.fragment.BaseEventFragment;
|
||||||
import org.briarproject.android.sharing.InvitationsForumActivity;
|
import org.briarproject.android.sharing.InvitationsForumActivity;
|
||||||
import org.briarproject.android.util.BriarRecyclerView;
|
import org.briarproject.android.util.BriarRecyclerView;
|
||||||
@@ -55,9 +56,14 @@ public class ForumListFragment extends BaseEventFragment implements
|
|||||||
private ForumListAdapter adapter;
|
private ForumListAdapter adapter;
|
||||||
private Snackbar snackbar;
|
private Snackbar snackbar;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected AndroidNotificationManager notificationManager;
|
||||||
|
|
||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
@Inject protected volatile ForumManager forumManager;
|
@Inject
|
||||||
@Inject protected volatile ForumSharingManager forumSharingManager;
|
protected volatile ForumManager forumManager;
|
||||||
|
@Inject
|
||||||
|
protected volatile ForumSharingManager forumSharingManager;
|
||||||
|
|
||||||
public static ForumListFragment newInstance() {
|
public static ForumListFragment newInstance() {
|
||||||
|
|
||||||
@@ -109,6 +115,8 @@ public class ForumListFragment extends BaseEventFragment implements
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
|
notificationManager.blockAllForumPostNotifications();
|
||||||
|
notificationManager.clearAllForumPostNotifications();
|
||||||
loadForumHeaders();
|
loadForumHeaders();
|
||||||
loadAvailableForums();
|
loadAvailableForums();
|
||||||
list.startPeriodicUpdate();
|
list.startPeriodicUpdate();
|
||||||
@@ -118,6 +126,7 @@ public class ForumListFragment extends BaseEventFragment implements
|
|||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
|
||||||
|
notificationManager.unblockAllForumPostNotifications();
|
||||||
adapter.clear();
|
adapter.clear();
|
||||||
list.showProgressBar();
|
list.showProgressBar();
|
||||||
list.stopPeriodicUpdate();
|
list.stopPeriodicUpdate();
|
||||||
|
|||||||
Reference in New Issue
Block a user