aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/de/pixart/messenger/entities/Account.java11
-rw-r--r--src/main/java/de/pixart/messenger/services/NotificationService.java39
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java41
3 files changed, 49 insertions, 42 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Account.java b/src/main/java/de/pixart/messenger/entities/Account.java
index 7a825faab..abce5d151 100644
--- a/src/main/java/de/pixart/messenger/entities/Account.java
+++ b/src/main/java/de/pixart/messenger/entities/Account.java
@@ -90,6 +90,17 @@ public class Account extends AbstractEntity {
return pgpDecryptionService != null && pgpDecryptionService.isConnected();
}
+ public boolean setShowErrorNotification(boolean newValue) {
+ boolean oldValue = showErrorNotification();
+ setKey("show_error",Boolean.toString(newValue));
+ return newValue != oldValue;
+ }
+
+ public boolean showErrorNotification() {
+ String key = getKey("show_error");
+ return key == null || Boolean.parseBoolean(key);
+ }
+
public enum State {
DISABLED,
OFFLINE,
diff --git a/src/main/java/de/pixart/messenger/services/NotificationService.java b/src/main/java/de/pixart/messenger/services/NotificationService.java
index 293442662..13ac34cc0 100644
--- a/src/main/java/de/pixart/messenger/services/NotificationService.java
+++ b/src/main/java/de/pixart/messenger/services/NotificationService.java
@@ -504,11 +504,10 @@ public class NotificationService {
return PendingIntent.getService(mXmppConnectionService, 45, intent, 0);
}
- private PendingIntent createDisableAccountIntent(final Account account) {
+ private PendingIntent createDismissErrorIntent() {
final Intent intent = new Intent(mXmppConnectionService, XmppConnectionService.class);
- intent.setAction(XmppConnectionService.ACTION_DISABLE_ACCOUNT);
- intent.putExtra("account", account.getJid().toBareJid().toString());
- return PendingIntent.getService(mXmppConnectionService, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ intent.setAction(XmppConnectionService.ACTION_DISMISS_ERROR_NOTIFICATIONS);
+ return PendingIntent.getService(mXmppConnectionService, 69, intent, 0);
}
private boolean wasHighlightedOrPrivate(final Message message) {
@@ -611,7 +610,7 @@ public class NotificationService {
final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mXmppConnectionService);
final List<Account> errors = new ArrayList<>();
for (final Account account : mXmppConnectionService.getAccounts()) {
- if (account.hasErrorStatus()) {
+ if (account.hasErrorStatus() && account.showErrorNotification()) {
errors.add(account);
}
}
@@ -632,29 +631,13 @@ public class NotificationService {
mBuilder.addAction(R.drawable.ic_autorenew_white_24dp,
mXmppConnectionService.getString(R.string.try_again),
createTryAgainIntent());
- if (errors.size() == 1) {
- if (Config.SHOW_DISABLE_FOREGROUND && !Config.USE_ALWAYS_FOREGROUND) {
- mBuilder.addAction(R.drawable.ic_block_white_24dp,
- mXmppConnectionService.getString(R.string.disable_account),
- createDisableAccountIntent(errors.get(0)));
- }
- }
- mBuilder.setOngoing(true);
- //mBuilder.setLights(0xffffffff, 2000, 4000);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- mBuilder.setSmallIcon(R.drawable.ic_warning_white_24dp);
- } else {
- mBuilder.setSmallIcon(R.drawable.ic_stat_alert_warning);
- }
- final TaskStackBuilder stackBuilder = TaskStackBuilder.create(mXmppConnectionService);
- stackBuilder.addParentStack(ConversationActivity.class);
-
- final Intent manageAccountsIntent = new Intent(mXmppConnectionService, ManageAccountActivity.class);
- stackBuilder.addNextIntent(manageAccountsIntent);
-
- final PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
-
- mBuilder.setContentIntent(resultPendingIntent);
+ mBuilder.setDeleteIntent(createDismissErrorIntent());
+ mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
+ mBuilder.setSmallIcon(R.drawable.ic_warning_white_24dp);
+ mBuilder.setContentIntent(PendingIntent.getActivity(mXmppConnectionService,
+ 145,
+ new Intent(mXmppConnectionService,ManageAccountActivity.class),
+ PendingIntent.FLAG_UPDATE_CURRENT));
notificationManager.notify(ERROR_NOTIFICATION_ID, mBuilder.build());
}
}
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index 2f61ed919..c217cbb47 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -141,7 +141,7 @@ public class XmppConnectionService extends Service {
public static final String ACTION_CLEAR_NOTIFICATION = "clear_notification";
public static final String ACTION_DISABLE_FOREGROUND = "disable_foreground";
public static final String ACTION_TRY_AGAIN = "try_again";
- public static final String ACTION_DISABLE_ACCOUNT = "disable_account";
+ public static final String ACTION_DISMISS_ERROR_NOTIFICATIONS = "dismiss_error";
public static final String ACTION_IDLE_PING = "idle_ping";
private static final String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts";
public static final String ACTION_GCM_TOKEN_REFRESH = "gcm_token_refresh";
@@ -302,6 +302,9 @@ public class XmppConnectionService extends Service {
mOnAccountUpdate.onAccountUpdate();
}
if (account.getStatus() == Account.State.ONLINE) {
+ if (account.setShowErrorNotification(true)) {
+ databaseBackend.updateAccount(account);
+ }
mMessageArchiveService.executePendingQueries(account);
if (connection != null && connection.getFeatures().csi()) {
if (checkListeners()) {
@@ -637,22 +640,13 @@ public class XmppConnectionService extends Service {
mNotificationService.clear();
}
break;
+ case ACTION_DISMISS_ERROR_NOTIFICATIONS:
+ dismissErrorNotifications();
+ break;
case ACTION_TRY_AGAIN:
resetAllAttemptCounts(false);
interactive = true;
break;
- case ACTION_DISABLE_ACCOUNT:
- try {
- String jid = intent.getStringExtra("account");
- Account account = jid == null ? null : findAccountByJid(Jid.fromString(jid));
- if (account != null) {
- account.setOption(Account.OPTION_DISABLED, true);
- updateAccount(account);
- }
- } catch (final InvalidJidException ignored) {
- break;
- }
- break;
case ACTION_REPLY_TO_CONVERSATION:
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
if (remoteInput != null && c != null) {
@@ -894,9 +888,23 @@ public class XmppConnectionService extends Service {
connection.resetAttemptCount();
}
}
+ if (account.setShowErrorNotification(true)) {
+ databaseBackend.updateAccount(account);
+ }
}
}
+ private void dismissErrorNotifications() {
+ for (final Account account : this.accounts) {
+ if (account.hasErrorStatus()) {
+ Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": dismissing error notification");
+ if (account.setShowErrorNotification(false)) {
+ databaseBackend.updateAccount(account);
+ }
+ }
+ }
+ }
+
public boolean hasInternetConnection() {
ConnectivityManager cm = (ConnectivityManager) getApplicationContext()
.getSystemService(Context.CONNECTIVITY_SERVICE);
@@ -1148,7 +1156,11 @@ public class XmppConnectionService extends Service {
private void sendMessage(final Message message, final boolean resend, final boolean delay) {
final Account account = message.getConversation().getAccount();
- final Conversation conversation = message.getConversation();
+ if (account.setShowErrorNotification(true)) {
+ databaseBackend.updateAccount(account);
+ mNotificationService.updateErrorNotification();
+ }
+ final Conversation conversation = message.getConversation();
account.deactivateGracePeriod();
MessagePacket packet = null;
final boolean addToConversation = (conversation.getMode() != Conversation.MODE_MULTI
@@ -1772,6 +1784,7 @@ public class XmppConnectionService extends Service {
public boolean updateAccount(final Account account) {
if (databaseBackend.updateAccount(account)) {
+ account.setShowErrorNotification(true);
this.statusListener.onStatusChanged(account);
databaseBackend.updateAccount(account);
reconnectAccountInBackground(account);