diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-11-23 14:10:16 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-11-23 14:10:16 +0100 |
commit | 0b48b579946448b2de677678be34bb75305f11e8 (patch) | |
tree | fabb9b354d4ff9a757d0391c226d92ad566370da /src/main/java/de/pixart/messenger/services | |
parent | dfb0139a6ca303f23e737d513d50e6789e122573 (diff) |
do not update foreground notification on error if it wasn’t enabled
Diffstat (limited to 'src/main/java/de/pixart/messenger/services')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/NotificationService.java | 23 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/services/XmppConnectionService.java | 4 |
2 files changed, 15 insertions, 12 deletions
diff --git a/src/main/java/de/pixart/messenger/services/NotificationService.java b/src/main/java/de/pixart/messenger/services/NotificationService.java index f93fa7fd4..ca6c8bc42 100644 --- a/src/main/java/de/pixart/messenger/services/NotificationService.java +++ b/src/main/java/de/pixart/messenger/services/NotificationService.java @@ -238,7 +238,7 @@ public class NotificationService { } } - public void pushFromDirectReply(final Message message) { + void pushFromDirectReply(final Message message) { synchronized (notifications) { pushToStack(message); updateNotification(false); @@ -264,8 +264,7 @@ public class NotificationService { private List<String> getBacklogConversations(Account account) { final List<String> conversations = new ArrayList<>(); - for (Iterator<Map.Entry<Conversation, AtomicInteger>> it = mBacklogMessageCounter.entrySet().iterator(); it.hasNext(); ) { - Map.Entry<Conversation, AtomicInteger> entry = it.next(); + for (Map.Entry<Conversation, AtomicInteger> entry : mBacklogMessageCounter.entrySet()) { if (entry.getKey().getAccount() == account) { conversations.add(entry.getKey().getUuid()); } @@ -286,7 +285,7 @@ public class NotificationService { return count; } - public void finishBacklog(boolean notify) { + void finishBacklog(boolean notify) { finishBacklog(notify, null); } @@ -385,7 +384,7 @@ public class NotificationService { updateNotification(notify, null, false); } - public void updateNotification(final boolean notify, final List<String> conversations) { + private void updateNotification(final boolean notify, final List<String> conversations) { updateNotification(notify, conversations, false); } @@ -924,7 +923,7 @@ public class NotificationService { return PendingIntent.getActivity(mXmppConnectionService, 0, new Intent(mXmppConnectionService, ConversationsActivity.class), 0); } - public void updateErrorNotification() { + void updateErrorNotification() { if (Config.SUPPRESS_ERROR_NOTIFICATION) { cancel(ERROR_NOTIFICATION_ID); return; @@ -936,7 +935,7 @@ public class NotificationService { errors.add(account); } } - if (Compatibility.keepForegroundService(mXmppConnectionService)) { + if (mXmppConnectionService.foregroundNotificationNeedsUpdatingWhenErrorStateChanges()) { notify(FOREGROUND_NOTIFICATION_ID, createForegroundNotification()); } final Notification.Builder mBuilder = new Notification.Builder(mXmppConnectionService); @@ -979,7 +978,7 @@ public class NotificationService { notify(ERROR_NOTIFICATION_ID, mBuilder.build()); } - public void updateFileAddingNotification(int current, Message message) { + void updateFileAddingNotification(int current, Message message) { Notification.Builder mBuilder = new Notification.Builder(mXmppConnectionService); mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.transcoding_video)); mBuilder.setProgress(100, current, false); @@ -993,11 +992,11 @@ public class NotificationService { notify(FOREGROUND_NOTIFICATION_ID, notification); } - public void dismissForcedForegroundNotification() { + void dismissForcedForegroundNotification() { cancel(FOREGROUND_NOTIFICATION_ID); } - public Notification exportLogsNotification() { + Notification exportLogsNotification() { Notification.Builder mBuilder = new Notification.Builder(mXmppConnectionService); mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.app_name)); mBuilder.setContentText(mXmppConnectionService.getString(R.string.notification_export_logs_title)); @@ -1010,11 +1009,11 @@ public class NotificationService { return mBuilder.build(); } - public void exportLogsServiceNotification(Notification notification) { + void exportLogsServiceNotification(Notification notification) { notify(FOREGROUND_NOTIFICATION_ID, notification); } - public Notification AppUpdateNotification(PendingIntent intent, String version, String filesize) { + Notification AppUpdateNotification(PendingIntent intent, String version, String filesize) { Notification.Builder mBuilder = new Notification.Builder(mXmppConnectionService); mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.app_name)); mBuilder.setContentText(mXmppConnectionService.getString(R.string.notification_export_logs_title)); diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index d3c7279c2..f8140504e 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -1255,6 +1255,10 @@ public class XmppConnectionService extends Service { Log.d(Config.LOGTAG, "ForegroundService: " + (status ? "on" : "off")); } + public boolean foregroundNotificationNeedsUpdatingWhenErrorStateChanges() { + return !mForceForegroundService.get() && Compatibility.keepForegroundService(this) && hasEnabledAccounts(); + } + @Override public void onTaskRemoved(final Intent rootIntent) { super.onTaskRemoved(rootIntent); |