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

View File

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

View File

@@ -101,7 +101,7 @@ public class GroupListFragment extends BaseFragment implements
@Override
public void onStart() {
super.onStart();
// TODO should we block all group message notifications as well?
viewModel.blockAllGroupMessageNotifications();
viewModel.clearAllGroupMessageNotifications();
// 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
@@ -117,6 +117,7 @@ public class GroupListFragment extends BaseFragment implements
public void onStop() {
super.onStop();
list.stopPeriodicUpdate();
viewModel.unblockAllGroupMessageNotifications();
}
@Override

View File

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

View File

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