From 66087cb3608ec70fd04248591b8531a0f4705a2f Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Tue, 18 Nov 2014 15:26:28 +0100 Subject: [PATCH] put error notification into notification service --- .../services/NotificationService.java | 39 ++++++++++++++++ .../services/XmppConnectionService.java | 7 ++- .../siacs/conversations/utils/UIHelper.java | 42 ------------------ .../drawable-hdpi/ic_stat_alert_warning.png | Bin 0 -> 757 bytes .../drawable-mdpi/ic_stat_alert_warning.png | Bin 0 -> 425 bytes .../drawable-xhdpi/ic_stat_alert_warning.png | Bin 0 -> 1175 bytes .../drawable-xxhdpi/ic_stat_alert_warning.png | Bin 0 -> 2276 bytes 7 files changed, 42 insertions(+), 46 deletions(-) create mode 100644 src/main/res/drawable-hdpi/ic_stat_alert_warning.png create mode 100644 src/main/res/drawable-mdpi/ic_stat_alert_warning.png create mode 100644 src/main/res/drawable-xhdpi/ic_stat_alert_warning.png create mode 100644 src/main/res/drawable-xxhdpi/ic_stat_alert_warning.png diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index c23a95b9e..f649f9d40 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 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 2ff29b196..d181fac33 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(); } } diff --git a/src/main/java/eu/siacs/conversations/utils/UIHelper.java b/src/main/java/eu/siacs/conversations/utils/UIHelper.java index 0d43450d1..ed6efd069 100644 --- a/src/main/java/eu/siacs/conversations/utils/UIHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/UIHelper.java @@ -106,48 +106,6 @@ public class UIHelper { } } - public static void showErrorNotification(Context context, - List accounts) { - NotificationManager mNotificationManager = (NotificationManager) context - .getSystemService(Context.NOTIFICATION_SERVICE); - List accountsWproblems = new ArrayList<>(); - for (Account account : accounts) { - if (account.hasErrorStatus()) { - accountsWproblems.add(account); - } - } - NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( - context); - if (accountsWproblems.size() == 0) { - mNotificationManager.cancel(1111); - return; - } else if (accountsWproblems.size() == 1) { - mBuilder.setContentTitle(context - .getString(R.string.problem_connecting_to_account)); - mBuilder.setContentText(accountsWproblems.get(0).getJid().toBareJid().toString()); - } else { - mBuilder.setContentTitle(context - .getString(R.string.problem_connecting_to_accounts)); - mBuilder.setContentText(context.getString(R.string.touch_to_fix)); - } - mBuilder.setOngoing(true); - mBuilder.setLights(0xffffffff, 2000, 4000); - mBuilder.setSmallIcon(R.drawable.ic_notification); - TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); - stackBuilder.addParentStack(ConversationActivity.class); - - Intent manageAccountsIntent = new Intent(context, - ManageAccountActivity.class); - stackBuilder.addNextIntent(manageAccountsIntent); - - PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, - PendingIntent.FLAG_UPDATE_CURRENT); - - mBuilder.setContentIntent(resultPendingIntent); - Notification notification = mBuilder.build(); - mNotificationManager.notify(1111, notification); - } - private final static class EmoticonPattern { Pattern pattern; String replacement; diff --git a/src/main/res/drawable-hdpi/ic_stat_alert_warning.png b/src/main/res/drawable-hdpi/ic_stat_alert_warning.png new file mode 100644 index 0000000000000000000000000000000000000000..a1f9917f11a798f968fa46b0bd59b7e3ad677991 GIT binary patch literal 757 zcmVwX~Hi0&OD*;j+MGt%4Rk$VFse zAk`+M$07r>7C~fKjWf=_@8f*K+^*hx9lLX<#eDGNaPGP1{QvWx@0@e1sw%3e%rdjp zU<23!*0W#kgqpwsa8hkkIg?>^TER7NPi<>is)V4cz;@6H9)quH+26+Tq!X$I$G{En z9xSM3|0u_kOr{!a1ed@o@ZFr)zSMJ$S0|NFJva{TfFG)kshtJ4HC~@YGBol|a2>n> zS^HZVJs;3}r8T&=IX&_S`~*2)LODHu2#%Ee7|^!v1Me(cZ^31-t5k{5$ZJ6dcp|Ta zX;$xbXkNSq$AXREpu96<1tZUcFW`gPc|GU&CwYnU8skichu~JwqhCGesl+rG1YK&U zJ!5lvzen@qIV`bI12_amR0Z$Ongl06o!UvySXS?kXnsQ+$*?+mz*X=9qWZz-X3%Z!zt02&DOOzPDYyVO*>b9+WLVPu;Ff-s-^gD522y(wn>U{#clH^)C>-r n+hJV^(y6%3A*WGA|F8Z4LoS7Zb`j>X00000NkvXXu0mjf;B{nY literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-mdpi/ic_stat_alert_warning.png b/src/main/res/drawable-mdpi/ic_stat_alert_warning.png new file mode 100644 index 0000000000000000000000000000000000000000..2e62841a02250422229ee7da7516ef028a18a974 GIT binary patch literal 425 zcmV;a0apHrP)(lkG?MFWP*w(z!rD_LyC342I4QC#5@TH;MuW4R}E~_*nOFNLc|od02<)K5$v}E zVQhn12|Ix{)d_fU1O_qHsEFNs_$Y%r`F<_K+K5_ZJ3$c~gVTsmt>Vm{_%rqe0ucwS TK56_a00000NkvXXu0mjfFwwcN literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-xhdpi/ic_stat_alert_warning.png b/src/main/res/drawable-xhdpi/ic_stat_alert_warning.png new file mode 100644 index 0000000000000000000000000000000000000000..952a857f62ef06023e16040dd8a84efcc6a67a99 GIT binary patch literal 1175 zcmV;I1Zew-P)v4w;05u9l?owOIlYXgV3R%4lDp`!~&HKO{;f7?ouLL{RbUL52iAfE;HEgBvU#dg zm9*abOyWm?r@;r{J8&MP#CesyuR0^jDu}GK`8@a%oC7yNKj_o%vtX<0lvi4Xm`A`2 z@E-UHTnD|DG5)>=_N&fxwnagy!YFnLT08E<`%r~k%;Bv_52WNqGc7r$6Ho3HFo)TZth#r!_ zLdH73sSVqXNkVv)md`}+k@?5@mwC!8WGU6%ueKBAYw*4Y^E^Hl%mv%P8S~837a@Q? z)jgxObLDIJUX47k@=4zV z_bq7jxnAD{d%+b8Pn#Us<>nWgQTlx{P$!*MugDjDK0aWxpwVaEe-3;Bj)3kE@lgXv z2hlBGpPPSIwI!bgiRWd6+y5eP7+kg7Stn`$CLdSjbCLR}DQOVqONZ0T_53mDH2(<0 zM!(nq`sJ%rzMHJnOUeA>nr5Ezcx1@6bm9b%4&t_aH-o8Gs(rySXZ=^fcJr)JXvd9` zg@Trn@9paA;qMIQOXo53Cz6%mSM&9nZ}e$V_JN?$=iln%L-onN<1Z!i(SHieH@{8s zf*$p_kZ&i>*X|FnMSV`NxU*oHwD}_V4EzGRB8Yfc>r!8zf)^}KTDAMr<`S?ETr~f9 zqZmiL9h?&F7VW5Q>Vtj#puUSwtLDdBHsrJ5M)RxSzZQPe3Ns4+#yq1m>vwy^w!P|$ zeQp3RNlUbwn`K6ymvlanaGU2uiQ1^KF)V=D=I8NmL7REnD<|5djT&c%1;7Vdo;~>Fx70j$ pmlI2+jT-B7rqYU4tYZH!y9dZ2RT8zM$KC({002ovPDHLkV1gaIL<;}_ literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-xxhdpi/ic_stat_alert_warning.png b/src/main/res/drawable-xxhdpi/ic_stat_alert_warning.png new file mode 100644 index 0000000000000000000000000000000000000000..eb5dc029cb187ec89a59feb112f5ad87d93c57e4 GIT binary patch literal 2276 zcmVp0jk*>S3HyyGBU>wZ&B#_8$k>lp1g&2gjSF5yPCjn+LqyOoi$zMjn- zV;$Ex7CK%R7OHKm?&)4%kya}F%Sguwjt3lHI2H?EsO<#Z!@Ygd*1O$Agm-Zq?zqG; zUxxWdSgba#9j1E+rLA|nh^E(Y$Dxk19Cth3cC2vxEAaa*U7MnNhj-~|mgRQ{0(W(s z?6}48jN>aut!1QEZG1&HJ5JIwT{nOfF;=93ighk?Jni_@vD8tYWuSVseWH6V(=!9r z$EIoXDZA+H4{&VdnBcg_@wsEUV~wLR%Rr54Tjuyo_fF8W^wB$QK4ljtwYg&l#{rJ> z9ZxxyIO-hh98FmU;&+2%t?qeJ&m5pWHcy*R*~Li>vxu0_blmB9RbNkozL<>-)TnFA zbnhLGGt|ehwE2`xEE6@8gie;zov-P&TE@sWPPUOijqaVNXOCB3oj2?jTI%(i5BGx9P=VabrHr%q*{H zE|N~eq+|O#Y>TCIYbi3xq9jUO!j?^IzNg#CG6;DV^&R%%$*CR{ z=BRCn<<7-&2|D~OozQKXblq0Ex1Gbbh%2^q?CChxB42_C%WS@mIa_$+|LXbWBKEg_ zSL<4#<=MnxS4+2>9LGp!d|TUWTU%y&?W6%Yn)0~gODnAi)>eW}=!TB?NfKbrJ(ho( zS*F%QOhIvqsr88CO^fPYKHE3#E$D=9==iXO&g5xuC~wWkGBsxQxTw1jXArfL1K|`) zsS@(0SF4{YVTIaC`7#^T&yN;U?RE>@;jq4jT`uEbZIV$AFcEm2?RdiRjfG<-I4fow z2f+ceEWc-Q%w?|dwAz+h;Z8b{Ch3NbUt3JIsTRHnE^sRSE3z<9l1|{5ud@i?{!lZ4aN_K6k$6(uJ`YNabWUn>qt8d92pEK@0@Qg^iDLW}u~;%hAT z!GnB-An;|2qbdvcXR z3z2fA8m$SsqBD^>+5R~eoZwcRkt}m$j{T-1EOs(Er$bqRIHg$MkS*ET6T=X^15{ zV$M~lz=6^%{|CWsz>&HZoY((xrX>R<=>(3FfQ@CHLjr{V%->Q{ijE?1fD4@9#u^b{G$*Z!$ z%BY<|lJYFv;0RYZ!+pz^48);Gwr_D>IA)T(8g%;`pFA!+o2U48-AVmUm(U3g;Xtp{9Fb7sWJjJW-tCKCmSNvCQ|Ap@^i} y-`=W=W2m?e6!)(8SF4Itq#_lmNJT2rocsrpphK{<7?ffF0000