From 44ee7466816378eb4fc6b2bff2e4fa001c3b08a0 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Tue, 10 Feb 2015 17:13:34 +0100 Subject: added actions to error notification --- .../services/NotificationService.java | 24 ++++++++++++++++++++- .../services/XmppConnectionService.java | 24 +++++++++++++++++++++ .../siacs/conversations/xmpp/XmppConnection.java | 5 +++++ .../res/drawable-hdpi/ic_autorenew_white_24dp.png | Bin 0 -> 489 bytes src/main/res/drawable-hdpi/ic_block_white_24dp.png | Bin 0 -> 606 bytes .../res/drawable-mdpi/ic_autorenew_white_24dp.png | Bin 0 -> 353 bytes src/main/res/drawable-mdpi/ic_block_white_24dp.png | Bin 0 -> 428 bytes .../res/drawable-xhdpi/ic_autorenew_white_24dp.png | Bin 0 -> 604 bytes .../res/drawable-xhdpi/ic_block_white_24dp.png | Bin 0 -> 796 bytes .../drawable-xxhdpi/ic_autorenew_white_24dp.png | Bin 0 -> 869 bytes .../res/drawable-xxhdpi/ic_block_white_24dp.png | Bin 0 -> 1194 bytes .../drawable-xxxhdpi/ic_autorenew_white_24dp.png | Bin 0 -> 1114 bytes .../res/drawable-xxxhdpi/ic_block_white_24dp.png | Bin 0 -> 1497 bytes src/main/res/values/strings.xml | 1 + 14 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/main/res/drawable-hdpi/ic_autorenew_white_24dp.png create mode 100644 src/main/res/drawable-hdpi/ic_block_white_24dp.png create mode 100644 src/main/res/drawable-mdpi/ic_autorenew_white_24dp.png create mode 100644 src/main/res/drawable-mdpi/ic_block_white_24dp.png create mode 100644 src/main/res/drawable-xhdpi/ic_autorenew_white_24dp.png create mode 100644 src/main/res/drawable-xhdpi/ic_block_white_24dp.png create mode 100644 src/main/res/drawable-xxhdpi/ic_autorenew_white_24dp.png create mode 100644 src/main/res/drawable-xxhdpi/ic_block_white_24dp.png create mode 100644 src/main/res/drawable-xxxhdpi/ic_autorenew_white_24dp.png create mode 100644 src/main/res/drawable-xxxhdpi/ic_block_white_24dp.png (limited to 'src') diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index 2ea0904f..203cda49 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -41,6 +41,7 @@ import eu.siacs.conversations.ui.ConversationActivity; import eu.siacs.conversations.ui.ManageAccountActivity; import eu.siacs.conversations.ui.TimePreference; import eu.siacs.conversations.utils.UIHelper; +import eu.siacs.conversations.xmpp.XmppConnection; public class NotificationService { @@ -395,7 +396,20 @@ public class NotificationService { final Intent intent = new Intent(mXmppConnectionService, XmppConnectionService.class); intent.setAction(XmppConnectionService.ACTION_DISABLE_FOREGROUND); - return PendingIntent.getService(mXmppConnectionService, 0, intent, 0); + return PendingIntent.getService(mXmppConnectionService, 34, intent, 0); + } + + private PendingIntent createTryAgainIntent() { + final Intent intent = new Intent(mXmppConnectionService, XmppConnectionService.class); + intent.setAction(XmppConnectionService.ACTION_TRY_AGAIN); + return PendingIntent.getService(mXmppConnectionService, 45, intent, 0); + } + + private PendingIntent createDisableAccountIntent(final Account account) { + 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); } private boolean wasHighlightedOrPrivate(final Message message) { @@ -492,6 +506,14 @@ public class NotificationService { mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_accounts)); mBuilder.setContentText(mXmppConnectionService.getString(R.string.touch_to_fix)); } + mBuilder.addAction(R.drawable.ic_autorenew_white_24dp, + mXmppConnectionService.getString(R.string.try_again), + createTryAgainIntent()); + if (errors.size() == 1) { + 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) { diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index e34f9bd7..c08e2c02 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -102,6 +102,8 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa public static final String ACTION_CLEAR_NOTIFICATION = "clear_notification"; public static final String ACTION_DISABLE_FOREGROUND = "disable_foreground"; private static final String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts"; + public static final String ACTION_TRY_AGAIN = "try_again"; + public static final String ACTION_DISABLE_ACCOUNT = "disable_account"; private ContentObserver contactObserver = new ContentObserver(null) { @Override public void onChange(boolean selfChange) { @@ -398,6 +400,28 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa getPreferences().edit().putBoolean("keep_foreground_service",false).commit(); toggleForegroundService(); break; + case ACTION_TRY_AGAIN: + for(Account account : accounts) { + if (account.hasErrorStatus()) { + final XmppConnection connection = account.getXmppConnection(); + if (connection != null) { + connection.resetAttemptCount(); + } + } + } + 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; } } this.wakeLock.acquire(); diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 5c252097..4d6695a5 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -1028,6 +1028,11 @@ public class XmppConnection implements Runnable { this.sendPacket(new InactivePacket()); } + public void resetAttemptCount() { + this.attempt = 0; + this.lastConnect = 0; + } + public class Features { XmppConnection connection; private boolean carbonsEnabled = false; diff --git a/src/main/res/drawable-hdpi/ic_autorenew_white_24dp.png b/src/main/res/drawable-hdpi/ic_autorenew_white_24dp.png new file mode 100644 index 00000000..b1ee2974 Binary files /dev/null and b/src/main/res/drawable-hdpi/ic_autorenew_white_24dp.png differ diff --git a/src/main/res/drawable-hdpi/ic_block_white_24dp.png b/src/main/res/drawable-hdpi/ic_block_white_24dp.png new file mode 100644 index 00000000..13f716d7 Binary files /dev/null and b/src/main/res/drawable-hdpi/ic_block_white_24dp.png differ diff --git a/src/main/res/drawable-mdpi/ic_autorenew_white_24dp.png b/src/main/res/drawable-mdpi/ic_autorenew_white_24dp.png new file mode 100644 index 00000000..86b71938 Binary files /dev/null and b/src/main/res/drawable-mdpi/ic_autorenew_white_24dp.png differ diff --git a/src/main/res/drawable-mdpi/ic_block_white_24dp.png b/src/main/res/drawable-mdpi/ic_block_white_24dp.png new file mode 100644 index 00000000..4e5093f7 Binary files /dev/null and b/src/main/res/drawable-mdpi/ic_block_white_24dp.png differ diff --git a/src/main/res/drawable-xhdpi/ic_autorenew_white_24dp.png b/src/main/res/drawable-xhdpi/ic_autorenew_white_24dp.png new file mode 100644 index 00000000..e8462223 Binary files /dev/null and b/src/main/res/drawable-xhdpi/ic_autorenew_white_24dp.png differ diff --git a/src/main/res/drawable-xhdpi/ic_block_white_24dp.png b/src/main/res/drawable-xhdpi/ic_block_white_24dp.png new file mode 100644 index 00000000..b86e6c47 Binary files /dev/null and b/src/main/res/drawable-xhdpi/ic_block_white_24dp.png differ diff --git a/src/main/res/drawable-xxhdpi/ic_autorenew_white_24dp.png b/src/main/res/drawable-xxhdpi/ic_autorenew_white_24dp.png new file mode 100644 index 00000000..b871381a Binary files /dev/null and b/src/main/res/drawable-xxhdpi/ic_autorenew_white_24dp.png differ diff --git a/src/main/res/drawable-xxhdpi/ic_block_white_24dp.png b/src/main/res/drawable-xxhdpi/ic_block_white_24dp.png new file mode 100644 index 00000000..d2be2d61 Binary files /dev/null and b/src/main/res/drawable-xxhdpi/ic_block_white_24dp.png differ diff --git a/src/main/res/drawable-xxxhdpi/ic_autorenew_white_24dp.png b/src/main/res/drawable-xxxhdpi/ic_autorenew_white_24dp.png new file mode 100644 index 00000000..569bafe2 Binary files /dev/null and b/src/main/res/drawable-xxxhdpi/ic_autorenew_white_24dp.png differ diff --git a/src/main/res/drawable-xxxhdpi/ic_block_white_24dp.png b/src/main/res/drawable-xxxhdpi/ic_block_white_24dp.png new file mode 100644 index 00000000..b538af61 Binary files /dev/null and b/src/main/res/drawable-xxxhdpi/ic_block_white_24dp.png differ diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 9d3300d8..ebf25604 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -444,4 +444,5 @@ Sending %s Offering %s Hide offline + Disable Account -- cgit v1.2.3