Block all group message notifications while viewing list of private groups

This commit is contained in:
Torsten Grote
2021-01-04 15:56:37 -03:00
parent 6409a3b179
commit f197243273
5 changed files with 30 additions and 4 deletions

View File

@@ -109,7 +109,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
@Nullable @Nullable
private GroupId blockedGroup = null; private GroupId blockedGroup = null;
private boolean blockSignInReminder = false; private boolean blockSignInReminder = false;
private boolean blockBlogs = false; private boolean blockGroups = false, blockBlogs = false;
private long lastSound = 0; private long lastSound = 0;
private volatile Settings settings = new Settings(); private volatile Settings settings = new Settings();
@@ -223,8 +223,8 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
if (s.getNamespace().equals(SETTINGS_NAMESPACE)) if (s.getNamespace().equals(SETTINGS_NAMESPACE))
settings = s.getSettings(); settings = s.getSettings();
} else if (e instanceof ConversationMessageReceivedEvent) { } else if (e instanceof ConversationMessageReceivedEvent) {
ConversationMessageReceivedEvent p = ConversationMessageReceivedEvent<?> p =
(ConversationMessageReceivedEvent) e; (ConversationMessageReceivedEvent<?>) e;
showContactNotification(p.getContactId()); showContactNotification(p.getContactId());
} else if (e instanceof GroupMessageAddedEvent) { } else if (e instanceof GroupMessageAddedEvent) {
GroupMessageAddedEvent g = (GroupMessageAddedEvent) e; GroupMessageAddedEvent g = (GroupMessageAddedEvent) e;
@@ -385,6 +385,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
@UiThread @UiThread
private void showGroupMessageNotification(GroupId g) { private void showGroupMessageNotification(GroupId g) {
if (blockGroups) return;
if (g.equals(blockedGroup)) return; if (g.equals(blockedGroup)) return;
groupCounts.add(g); groupCounts.add(g);
updateGroupMessageNotification(true); updateGroupMessageNotification(true);
@@ -681,6 +682,17 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
}); });
} }
@Override
public void blockAllGroupMessageNotifications() {
androidExecutor.runOnUiThread((Runnable) () -> blockGroups = true);
}
@Override
public void unblockAllGroupMessageNotifications() {
androidExecutor.runOnUiThread((Runnable) () -> blockGroups = false);
}
@Override @Override
public void blockAllBlogPostNotifications() { public void blockAllBlogPostNotifications() {
androidExecutor.runOnUiThread((Runnable) () -> blockBlogs = true); androidExecutor.runOnUiThread((Runnable) () -> blockBlogs = true);

View File

@@ -121,6 +121,7 @@ public class ForumListFragment extends BaseEventFragment implements
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
// TODO block all forum post notifications as well
notificationManager.clearAllForumPostNotifications(); notificationManager.clearAllForumPostNotifications();
loadForums(); loadForums();
loadAvailableForums(); loadAvailableForums();

View File

@@ -101,7 +101,7 @@ public class GroupListFragment extends BaseFragment implements
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
// TODO should we block all group message notifications as well? viewModel.blockAllGroupMessageNotifications();
viewModel.clearAllGroupMessageNotifications(); viewModel.clearAllGroupMessageNotifications();
// The attributes and sorting of the groups may have changed while we // The attributes and sorting of the groups may have changed while we
// were stopped and we have no way finding out about them, so re-load // were stopped and we have no way finding out about them, so re-load
@@ -117,6 +117,7 @@ public class GroupListFragment extends BaseFragment implements
public void onStop() { public void onStop() {
super.onStop(); super.onStop();
list.stopPeriodicUpdate(); list.stopPeriodicUpdate();
viewModel.unblockAllGroupMessageNotifications();
} }
@Override @Override

View File

@@ -103,6 +103,14 @@ class GroupListViewModel extends DbViewModel implements EventListener {
notificationManager.clearAllGroupMessageNotifications(); notificationManager.clearAllGroupMessageNotifications();
} }
void blockAllGroupMessageNotifications() {
notificationManager.blockAllGroupMessageNotifications();
}
void unblockAllGroupMessageNotifications() {
notificationManager.unblockAllGroupMessageNotifications();
}
@Override @Override
public void eventOccurred(Event e) { public void eventOccurred(Event e) {
if (e instanceof GroupMessageAddedEvent) { if (e instanceof GroupMessageAddedEvent) {

View File

@@ -82,6 +82,10 @@ public interface AndroidNotificationManager {
void unblockNotification(GroupId g); void unblockNotification(GroupId g);
void blockAllGroupMessageNotifications();
void unblockAllGroupMessageNotifications();
void blockAllBlogPostNotifications(); void blockAllBlogPostNotifications();
void unblockAllBlogPostNotifications(); void unblockAllBlogPostNotifications();