aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/services
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-11-18 15:26:28 +0100
committeriNPUTmice <daniel@gultsch.de>2014-11-18 15:26:28 +0100
commit66087cb3608ec70fd04248591b8531a0f4705a2f (patch)
tree731ebdaa368e14c6386193cc6e643577fafa035d /src/main/java/eu/siacs/conversations/services
parent1122e084a0dc6327ea2ab75072211062e3077311 (diff)
put error notification into notification service
Diffstat (limited to 'src/main/java/eu/siacs/conversations/services')
-rw-r--r--src/main/java/eu/siacs/conversations/services/NotificationService.java39
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java7
2 files changed, 42 insertions, 4 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java
index c23a95b9..f649f9d4 100644
--- a/src/main/java/eu/siacs/conversations/services/NotificationService.java
+++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java
@@ -20,6 +20,7 @@ import android.util.DisplayMetrics;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -31,6 +32,7 @@ import eu.siacs.conversations.entities.Downloadable;
import eu.siacs.conversations.entities.DownloadableFile;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.ui.ConversationActivity;
+import eu.siacs.conversations.ui.ManageAccountActivity;
public class NotificationService {
@@ -40,6 +42,8 @@ public class NotificationService {
public static int NOTIFICATION_ID = 0x2342;
public static int FOREGROUND_NOTIFICATION_ID = 0x8899;
+ public static int ERROR_NOTIFICATION_ID = 0x5678;
+
private Conversation mOpenConversation;
private boolean mIsInForeground;
private long mLastNotification;
@@ -380,4 +384,39 @@ public class NotificationService {
mBuilder.setPriority(NotificationCompat.PRIORITY_MIN);
return mBuilder.build();
}
+
+ public void updateErrorNotification() {
+ NotificationManager mNotificationManager = (NotificationManager) mXmppConnectionService.getSystemService(Context.NOTIFICATION_SERVICE);
+ List<Account> errors = new ArrayList<>();
+ for (Account account : mXmppConnectionService.getAccounts()) {
+ if (account.hasErrorStatus()) {
+ errors.add(account);
+ }
+ }
+ NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
+ if (errors.size() == 0) {
+ mNotificationManager.cancel(ERROR_NOTIFICATION_ID);
+ return;
+ } else if (errors.size() == 1) {
+ mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_account));
+ mBuilder.setContentText(errors.get(0).getJid().toBareJid().toString());
+ } else {
+ mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_accounts));
+ mBuilder.setContentText(mXmppConnectionService.getString(R.string.touch_to_fix));
+ }
+ mBuilder.setOngoing(true);
+ mBuilder.setLights(0xffffffff, 2000, 4000);
+ mBuilder.setSmallIcon(R.drawable.ic_stat_alert_warning);
+ TaskStackBuilder stackBuilder = TaskStackBuilder.create(mXmppConnectionService);
+ stackBuilder.addParentStack(ConversationActivity.class);
+
+ Intent manageAccountsIntent = new Intent(mXmppConnectionService,ManageAccountActivity.class);
+ stackBuilder.addNextIntent(manageAccountsIntent);
+
+ PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
+
+ mBuilder.setContentIntent(resultPendingIntent);
+ Notification notification = mBuilder.build();
+ mNotificationManager.notify(ERROR_NOTIFICATION_ID, notification);
+ }
}
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index 2ff29b19..d181fac3 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -204,8 +204,7 @@ public class XmppConnectionService extends Service {
scheduleWakeupCall((int) (next * 1.2), false);
}
}
- UIHelper.showErrorNotification(getApplicationContext(),
- getAccounts());
+ getNotificationService().updateErrorNotification();
}
};
private Integer accountChangedListenerCount = 0;
@@ -1071,7 +1070,7 @@ public class XmppConnectionService extends Service {
databaseBackend.updateAccount(account);
reconnectAccount(account, false);
updateAccountUi();
- UIHelper.showErrorNotification(getApplicationContext(), getAccounts());
+ getNotificationService().updateErrorNotification();
}
public void deleteAccount(Account account) {
@@ -1092,7 +1091,7 @@ public class XmppConnectionService extends Service {
databaseBackend.deleteAccount(account);
this.accounts.remove(account);
updateAccountUi();
- UIHelper.showErrorNotification(getApplicationContext(), getAccounts());
+ getNotificationService().updateErrorNotification();
}
}