From 4fd8620c6cc1ca88c4496671e6e59c40aba93019 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 4 Feb 2014 21:44:16 +0100 Subject: [PATCH] allow to temporarily disable accounts --- gen/de/gultsch/chat/R.java | 23 ++-- res/drawable-hdpi/ic_action_add_person.png | Bin 0 -> 679 bytes res/drawable-hdpi/ic_action_delete.png | Bin 0 -> 1624 bytes res/drawable-mdpi/ic_action_add_person.png | Bin 0 -> 513 bytes res/drawable-mdpi/ic_action_delete.png | Bin 0 -> 1359 bytes res/drawable-xhdpi/ic_action_add_person.png | Bin 0 -> 884 bytes res/drawable-xhdpi/ic_action_delete.png | Bin 0 -> 1848 bytes res/drawable-xxhdpi/ic_action_add_person.png | Bin 0 -> 1171 bytes res/layout/account_row.xml | 3 +- res/menu/manageaccounts.xml | 3 +- res/menu/manageaccounts_context.xml | 17 +++ res/values/arrays.xml | 4 + src/de/gultsch/chat/entities/Account.java | 23 +++- .../chat/services/XmppConnectionService.java | 13 +- src/de/gultsch/chat/ui/EditAccount.java | 4 +- .../chat/ui/ManageAccountActivity.java | 124 +++++++++++++++--- .../chat/ui/NewConversationActivity.java | 2 +- 17 files changed, 183 insertions(+), 33 deletions(-) create mode 100644 res/drawable-hdpi/ic_action_add_person.png create mode 100644 res/drawable-hdpi/ic_action_delete.png create mode 100644 res/drawable-mdpi/ic_action_add_person.png create mode 100644 res/drawable-mdpi/ic_action_delete.png create mode 100644 res/drawable-xhdpi/ic_action_add_person.png create mode 100644 res/drawable-xhdpi/ic_action_delete.png create mode 100644 res/drawable-xxhdpi/ic_action_add_person.png create mode 100644 res/menu/manageaccounts_context.xml diff --git a/gen/de/gultsch/chat/R.java b/gen/de/gultsch/chat/R.java index 596a2bad..982b1e2e 100644 --- a/gen/de/gultsch/chat/R.java +++ b/gen/de/gultsch/chat/R.java @@ -11,6 +11,7 @@ public final class R { public static final class array { public static final int conversation_encryption_type_entries=0x7f050000; public static final int conversation_encryption_type_values=0x7f050001; + public static final int manage_account_options=0x7f050002; } public static final class attr { } @@ -28,17 +29,20 @@ public final class R { public static final int es_slidingpane_shadow=0x7f020000; public static final int ic_action_add=0x7f020001; public static final int ic_action_add_person=0x7f020002; - public static final int ic_action_send=0x7f020003; - public static final int ic_action_send_now=0x7f020004; - public static final int ic_action_unsecure=0x7f020005; - public static final int ic_launcher=0x7f020006; - public static final int ic_profile=0x7f020007; - public static final int message_border=0x7f020008; - public static final int notification=0x7f020009; - public static final int section_header=0x7f02000a; + public static final int ic_action_delete=0x7f020003; + public static final int ic_action_send=0x7f020004; + public static final int ic_action_send_now=0x7f020005; + public static final int ic_action_unsecure=0x7f020006; + public static final int ic_launcher=0x7f020007; + public static final int ic_profile=0x7f020008; + public static final int message_border=0x7f020009; + public static final int notification=0x7f02000a; + public static final int section_header=0x7f02000b; } public static final class id { public static final int account_confirm_password_desc=0x7f0a0011; + public static final int account_disable=0x7f0a002c; + public static final int account_enable=0x7f0a002d; public static final int account_jid=0x7f0a0000; public static final int account_list=0x7f0a0021; public static final int account_password=0x7f0a000f; @@ -98,7 +102,8 @@ public final class R { public static final class menu { public static final int conversations=0x7f090000; public static final int manageaccounts=0x7f090001; - public static final int newconversation=0x7f090002; + public static final int manageaccounts_context=0x7f090002; + public static final int newconversation=0x7f090003; } public static final class string { public static final int action_accounts=0x7f070003; diff --git a/res/drawable-hdpi/ic_action_add_person.png b/res/drawable-hdpi/ic_action_add_person.png new file mode 100644 index 0000000000000000000000000000000000000000..5ebac97064bbb47fa31bd67f130a9ae3fce34621 GIT binary patch literal 679 zcmV;Y0$BZtP)ShzXq8wyzfqQ#NOpAqK(Hqm z^F=h(fY$Z?@^x&1y? z{vcyZt2B|JbteKvi6#GrI_}A4VgNEkYdeW4jCmtaIUAQz+LpOqnghav3MkG(WR}yFM#yPZH;q0hhkR4O>N5$RXF2jtk=(6<1f59=U6*RS zZ0GFvOFR~lMXU%$Py~;h+%-IV0S@7Lbc+Y3)PqNs95fbP2;m0@3a7IHbq)*^S)b&@ zBW)h&a(zwhsgu$=Z;d-5Q?)=WjQxz)6RrtN+l9_x;9ZrGl9KwIqFFS~DS+AmoO5!_ zEjTzhXb+)+@LJ>T3dh)5o(qvu1E2x$-vM-LrcZoic{CboNDci7FaV8qrty#SYVH64 N002ovPDHLkV1g}oA)f#M literal 0 HcmV?d00001 diff --git a/res/drawable-hdpi/ic_action_delete.png b/res/drawable-hdpi/ic_action_delete.png new file mode 100644 index 0000000000000000000000000000000000000000..e9ce89e0460b368de996f6b1d7ee149ae5fb1315 GIT binary patch literal 1624 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTC$r9IylHmNblJdl&R0hYC{G?O` z&)mfH)S%SFl*+=BsWuD@%qp275hW46K32*3xq68pHF_1f1wh>l3^w)^1&PVosU-?Y zsp*+{wo31J?^jaDOtDo8H}y5}EpSfF$n>ZxN)4{^3rViZPPR-@vbR&PsjvbXkegbP zs8ErclUHn2VXFi-*9yo63F|8hm3bwJ6}oxF$}kgLQj3#|G7CyF^YauyCMG83 zmzLNn0bL65LT&-v*t}wBFaZNhzap_f-%!s00+w{G(#^lGsVip$=JZnz{SMW$-u?X(ACh=#L&{!#L3yw z&D7A`#K{n**Cju>G&eP`1g19ytk=TD+111qr(RHE$SnZc?2=lPS(cjOR+OKs0QR(1 zCT_PF;WQ7bHwCL(!2U4CsaGH97=2LGB1JV!2$+6AOnAZta^OinH4m8Hi+~B+%vbIe z0|V13PZ!6Kid%1H?#{d7Akt=gFXxa}LsLURu0o7zi^jA`<_i`+W?Zm*$s@~*%NH+R zXvlc6{oy5tLrPp7J3JkH%r++T{}ohGWQnO{QGEW{Jdi7HLD-f z+p}1=Fhw!`pV?5iKfX+p<@rIo34TA$YW)aEOEHiL`ILU_VbUB%^8@Q9y`J^Gn(bXv zuDCg`ESCj0pLF-4;}-W>pZ|E7vZIDc(%!zfHJLN8PF=B-GiJU(Trc;9k_zTMvc)a5QEt0Y)$g(v$yFCgT?QxCiS=hvNQAb?{wZXE^IeT%-r3ZrgJKc zyVK&hg_vM4!<| z7sK0JLlV^|7eqgB)M$NBJD({@ZSk5rnd_3m76!a7sPl4~Et?_5c)#NCrsf=V?u2uJ zTW)3;itq67iswChBGuC;T6sQ`nT)xbX0F+-ATy&J)-}eBu~(eCwq2{`@{m) zD~{#lSYCLj%tQV*@4p)6@Y0fu&^BP&THD}u+@Fz+;rN|9?#>?y0zqZHr>mdKI;Vst0H|?TumAu6 literal 0 HcmV?d00001 diff --git a/res/drawable-mdpi/ic_action_add_person.png b/res/drawable-mdpi/ic_action_add_person.png new file mode 100644 index 0000000000000000000000000000000000000000..c43cf6553cf106bfddbfafcfd62f8627bedaa7ee GIT binary patch literal 513 zcmV+c0{;DpP)?!z~|6o=o67@$omzOcre-rP}3P|o4Vj3 z^aQ`ZVf&DPUDycxl*oeMqw!YE{=PYttRkBEZ0Lr5k3fmXw0(K264A5CI0iYngy;LQ%R`iH2Qs>2$$GPq>l% z#iS~oFd6_Z#099BjDF=6)k)yY&`gMwJ0XYv`PV*575arNBLCGky%S~a7(URdr+qC- z+BAW6-v~^SU!-J3I^~PV*qd-NaYpu^SpU)?KLQK@)OmL!XMKio00000NkvXXu0mjf D);{g= literal 0 HcmV?d00001 diff --git a/res/drawable-mdpi/ic_action_delete.png b/res/drawable-mdpi/ic_action_delete.png new file mode 100644 index 0000000000000000000000000000000000000000..cedb1085b85cf28fec0152168da61defb93fd6fa GIT binary patch literal 1359 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz$r9IylHmNblJdl&R0hYC{G?O` z&)mfH)S%SFl*+=BsWuD@%qp275hW46K32*3xq68pHF_1f1wh>l3^w)^1&PVosU-?Y zsp*+{wo31J?^jaDOtDo8H}y5}EpSfF$n>ZxN)4{^3rViZPPR-@vbR&PsjvbXkegbP zs8ErclUHn2VXFi-*9yo63F|8hm3bwJ6}oxF$}kgLQj3#|G7CyF^YauyCMG83 zmzLNn0bL65LT&-v*t}wBFaZNhzap_f-%!s00+w{G(#^lGsVip$->3i)zr|`$-u?X(ACh=#L&{!#L3yw z&D7A`#K{n**Cju>G&eP`1g19yq1OnfUQlAlEdbi=l3J8mmYU*Ll%J~r_Ow+dPPdr2 z;WQ7bHwCv_3~=hz2RcR{6tzfE4HE*U9}p9saDg0n(of9;ruQOX!d}0Wsg!|%@t~)R zV@SoVH`6zIF*^#hy?=C6g-guwsFP#h8kgDHTg9ZM<&U^+5L)9>BXHj#C&z`mTO&zx zT9ae*f(6sxsFwfZ-v2N{FC{-;wN>(m#iln#|IeK}mvhIWZ?0q1LCFogtQCLNe(YP% z=i4ayK#Yce2gqtnB)xR0HN`4y-a-l?twJ8cGA$`yVt0o>EPi&ZH#tDLU}k$&Few z*s>G4nfyL+MJx%P_$Xj2-$b)hTX*(9n3O1+e&R7pR^E~c6XKJCfxTz9hNZ&+UUN8KCg4=bPQ&9;3uO;UDdhwy^~Z4DE2 zHavK7t*grZ`7S1c&zvGKR= zFt4=+eGLWz3OQwmFFfFIn$5(-%-HD5c*vn)gKokC%MZsM1-(%|@>Hfjd(B?X{D|A; zKVE1A*UTx9+30>ksOG5YHI@_Z$1HawOkcgpd77|)(ae(fyKEOoZ+cjNxL*H(djlf_ XdqiO|XOH7mP!Z?p>gTe~DWM4f=>_8H literal 0 HcmV?d00001 diff --git a/res/drawable-xhdpi/ic_action_add_person.png b/res/drawable-xhdpi/ic_action_add_person.png new file mode 100644 index 0000000000000000000000000000000000000000..91434a47b245c06ee7eac2f640e695cee1b7fa0c GIT binary patch literal 884 zcmV-)1B?8LP)0KomZ=DG4d?z+^Sl z0R@c|4cKs{4Gj(rZNbR?h2qirN8@z!C6*R$av&!M_0!l??(88-mAe{ssJFgJJNur%@FB zEsEk_XGD;|Uvl?&6MGvA#vFEn0GjAh6L_A4Wmk5YP#B&gbksuPlgB@zf z;^y43mzk^*NfSUT{cB4Ww@_St%q{rX|A)y_K&c{B6vayvMPngY8Nsy=;On}T9RQCj zKjSXl0l|NqCjbqAqEMZJ9}7i|Pw-gp1%o&fkeTalp7zCcL#^BLP;D@5SG>7K8c zMGM*(l)6J=XQ(89w%rWz)-V#}1u!8|!uhSbZbH@4kf@ZNac?t#y_GnU$(r31g8)z zmAe8eV+0WR#DYdm+9n~Wx$PIsu3d|_gHWO`Wd*oaHb{RmXZCH|0;J$qqcmg~D-uw>m1b6~G0sXZ90t^7JSKFHGD^ptl0000< KMNUMnLSTXgwvcuJ literal 0 HcmV?d00001 diff --git a/res/drawable-xhdpi/ic_action_delete.png b/res/drawable-xhdpi/ic_action_delete.png new file mode 100644 index 0000000000000000000000000000000000000000..98c73da1f35b06932d1a76de6468afb2768998d4 GIT binary patch literal 1848 zcmaJ?X;c$e7!430Q7Iq-qE?2WC|fcU6CsfZSpWkB5h8|CDMK6uuGVt(JlY^Hm)M)k3>q-#f~WCl zpOTVEq5vU^Apn~W`pUtX5HOQPhgcwo#qj}{AOtcXCIj^Ig+MObj|)P;=Z8i_!xYKf zXi>=LSj34(OT}>wm%-5KbadSeI*O$*AP$Ga0GSLX)0gn@)n=-3SnsRWx(_jk5Um_j zYH%g0226}_5}JYYXhf!;N>FKrY1P`#Z6X@R(8C%AL|&4SQ?xXyi-2 z|4FQsW@->dG@?Z_FgY=}WOq|24OfUEFpgqU6ipxMVpJ-MquNwd0|;Z-bO?~Za;4g2 z8AM1VT(Me*XsyHh$;Ub!M~mxm@dIcH_wQ&GUlo*REN8ZQG4iS*pV> z_uN_wGQ^uD%vnW>luoy}+7ewyO7Ht^McnP$AA5Rhjeg;VsSRTjsRzkZ>MBB?ltxV# zWvX^)FoU=q$Z~rniC%NAOHWYo`+B2q!ZQ8gyq8#jryz%x6=XaQ^$RL98W$GWC0O1zdK;VcYRPD`TIxzaYBjIp z-JIhr6Ffilz+%aAqsIDKM!e^y z8ZKOtPLUH=m9zOfYPk-8N=x(9zbKusxh`|F!iSv-er-q#ls= zP`xO22?HLm4rtEg6{g#C&N?dGeZ{FHNZ4?jnh@HoPJA>|UK_vR^y7jpd3}dM zzdsUIJgM}ZSM0%2=I7()o$wfw<5;&WEM}b!@cv_3<&|FYGyDDaE$*jN%v)M6OmpSO zxmflnGWR;|bcl@rg36ECQs+`rD0}RkEM1muywk(CvYnp|BPDG<3+9O|o4V&3ZTC8@ z4>O)MbeJ={i}PL{*08(U)$}WmyN$cvzAqA!FZxJ&-X-<- zj~k~c(_2Qixs(Rhc~2QgwVb3}IR9wnCW99xbxHf1Fk8>+qq#0piF;6U1hpf((0qDT z-463;_vU8NZvM>==gce;mb*_S_T%l9aF=-9Be<8HzQk@=+wP4{c3HUycE zb+zKH_imW6(Xi<}D67qHBj0)=MOTB;)azT{8ypJcP4zDDxvZT|^d=d%i*DhP2BPM(3e|qe(Q^`q83+L?mTpxFbvQVS* z+Z{+rJlsMFUzku0KOD%vWL7eYqcwIsIVm`dj z5H}E2SR7$!zIxB%B;|r^z(0KZ)4sgsNjcqR-P4&?YE_X5+*pt_*;U*3(dO2ow!!NnGxsseSA8UpCnefGaLNVRzcKyG N#KDoG{er|5{{R}rz~}$~ literal 0 HcmV?d00001 diff --git a/res/drawable-xxhdpi/ic_action_add_person.png b/res/drawable-xxhdpi/ic_action_add_person.png new file mode 100644 index 0000000000000000000000000000000000000000..f18aa61444395f573a4b77c0a9abafda7dd85cbb GIT binary patch literal 1171 zcmV;E1Z?|>P)4yaBs z32;F`PfE!J#-t#np)n{aO+kM}aaESmkbs1`G^CMS&;pZ!L~=n*3KGzQ&NLG#y4=P0 zwRijRp0u*1v(LBh?ac1%&R8h`00000003wmfhiBNwY4>rw*zV+wO`a0)UMCZ&o3ZA z^Mo_e3ALe+z6>*JQ*I>40s>Sgo=Ja2tzY9dEXD~5F@pf*T+Cj<(Owj65l1##M9>oX zO#DdG?XN_HGYD{>c%Dq(h@aPu35jrIn*b}C$v>dB(NbSFq9|IM&*xK{1n6nJ_d&z{ zz6cU=cYa%dkPvs&C$@x3vV@;rT7ax}MjiKSUtFM)*CF0?=rS4I2G-tswNp0un>}nD`=qss488ya2Mb972HZEMVQ>K87aG15F9A zX82-b-E{!~2mk>92;i>(zYOo^!gT?RJ`^|k(7xAD2Te{7F*~*xx82feN{I(I`_5$GDy)uKL5@*O}^<#Ta5`IBm8sD z<&m5h=mZ}@rq3fLzQqBP94lb#%dV-8(a(GS>3#p14Y{L@3LsYSDd+P4M6ISp5c1Qm zho9rnhCrz;V+5s zqw0i9-+xVSUuIlBBl3@J*^1DXoO>rXbg(2yDwXFiqkd0ipTIHshsq+fksVzmN0dvD zIKBKLEr#4N1xV_uU&vU1nw!l*$G@9Fi{qw%?g<~XRTfbGa=vFBED8@#Kamn zad$`6%c5YyC$?6_bS6NCMR0pwPz>Hun2N7=rfk)SI$;u{FRtlXMnJ`6U$(KC2LRee z_`v4-+Zu?aeSG7^)v2OyE9Zzn1M$l$;h892v(Ks!C5JBYlAz3*O8TJT5npzlzqp-b zEkB)nd7`D%Qe5HvtM6SA+mtBNdwQxf6CIRRw($d&LmOoC@(4Mr_zS89;Y zq`y<uP&Zr5ePt(Nlm5;is4)6@ ziMgxn$NPttsnpMpWj^1E1<0i90{M)wjV@@c+(BQg*$x3D0v#&1u+wz`Ul|M7R_-BG z9T#%<3XcB1GQ8rv21YhmK&;$Fzsv3Hq5>q!Z6wADAns@2xB#75c##5)YYsvb(2W4H zdpHACW&~mY1aJ$151pii#M=sAOGo_|G9Q+~(&NxoPX<~OTPRglf{)>XFb4o|K}wxg z_)hxVgAet~)*LVWe1I{SJ8_$LA_ia%fB*mlfB*mlfB*mlfB*mlfB--}tb&4Eq&M&u lpacK_00000a0LGZ7y#EUBa6FqPfY*-002ovPDHLkV1gy*4*mcD literal 0 HcmV?d00001 diff --git a/res/layout/account_row.xml b/res/layout/account_row.xml index 92e179f8..402cb965 100644 --- a/res/layout/account_row.xml +++ b/res/layout/account_row.xml @@ -2,7 +2,8 @@ + android:padding="8dp" + android:background="?android:attr/activatedBackgroundIndicator"> diff --git a/res/menu/manageaccounts.xml b/res/menu/manageaccounts.xml index 63441919..1d81ba3c 100644 --- a/res/menu/manageaccounts.xml +++ b/res/menu/manageaccounts.xml @@ -2,7 +2,8 @@ + android:title="@string/action_add_account" + android:icon="@drawable/ic_action_add_person"/> + + + + + + diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 592007ba..b8135cde 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -10,4 +10,8 @@ pgp otr + + Delete + Disable + diff --git a/src/de/gultsch/chat/entities/Account.java b/src/de/gultsch/chat/entities/Account.java index 3dfb298a..6f8daf8d 100644 --- a/src/de/gultsch/chat/entities/Account.java +++ b/src/de/gultsch/chat/entities/Account.java @@ -17,7 +17,9 @@ public class Account extends AbstractEntity{ public static final String ROSTERVERSION = "rosterversion"; public static final int OPTION_USETLS = 0; + public static final int OPTION_DISABLED = 1; + public static final int STATUS_DISABLED = -1; public static final int STATUS_OFFLINE = 0; public static final int STATUS_ONLINE = 1; public static final int STATUS_UNAUTHORIZED = 2; @@ -55,6 +57,20 @@ public class Account extends AbstractEntity{ return ((options & (1 << option)) != 0); } + public void setOption(int option, boolean value) { + if (value) { + Log.d("xmppService","options: "+options); + this.options = (this.options | 1 << option); + Log.d("xmppService","setting option "+option+" to 1"); + Log.d("xmppService","options: "+options); + } else { + Log.d("xmppService","options: "+options); + Log.d("xmppService","setting option "+option+" to 0"); + this.options = (this.options ^ 1 << option); + Log.d("xmppService","options: "+options); + } + } + public String getUsername() { return username; } @@ -84,7 +100,11 @@ public class Account extends AbstractEntity{ } public int getStatus() { - return this.status; + if (isOptionSet(OPTION_DISABLED)) { + return STATUS_DISABLED; + } else { + return this.status; + } } public void setResource(String resource) { @@ -102,6 +122,7 @@ public class Account extends AbstractEntity{ values.put(USERNAME, username); values.put(SERVER, server); values.put(PASSWORD, password); + values.put(OPTIONS,options); return values; } diff --git a/src/de/gultsch/chat/services/XmppConnectionService.java b/src/de/gultsch/chat/services/XmppConnectionService.java index fbbaca5c..ae1140ee 100644 --- a/src/de/gultsch/chat/services/XmppConnectionService.java +++ b/src/de/gultsch/chat/services/XmppConnectionService.java @@ -95,8 +95,11 @@ public class XmppConnectionService extends Service { public int onStartCommand(Intent intent, int flags, int startId) { for (Account account : accounts) { if (!connections.containsKey(account)) { - - this.connections.put(account, this.createConnection(account)); + if (!account.isOptionSet(Account.OPTION_DISABLED)) { + this.connections.put(account, this.createConnection(account)); + } else { + Log.d(LOGTAG,account.getJid()+": not starting because it's disabled"); + } } } return START_STICKY; @@ -253,7 +256,11 @@ public class XmppConnectionService extends Service { connection.disconnect(); this.connections.remove(account); } - this.connections.put(account, this.createConnection(account)); + if (!account.isOptionSet(Account.OPTION_DISABLED)) { + this.connections.put(account, this.createConnection(account)); + } else { + Log.d(LOGTAG,account.getJid()+": not starting because it's disabled"); + } if (accountChangedListener!=null) accountChangedListener.onAccountListChangedListener(); } diff --git a/src/de/gultsch/chat/ui/EditAccount.java b/src/de/gultsch/chat/ui/EditAccount.java index 7cb48472..f8d70981 100644 --- a/src/de/gultsch/chat/ui/EditAccount.java +++ b/src/de/gultsch/chat/ui/EditAccount.java @@ -92,7 +92,7 @@ public class EditAccount extends DialogFragment { usernameText.setText(account.getUsername()); serverText.setText(account.getServer()); okButtonDesc = "Edit"; - builder.setNegativeButton("Delete Account", new OnClickListener() { + /*builder.setNegativeButton("Delete Account", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { @@ -112,7 +112,7 @@ public class EditAccount extends DialogFragment { builder.setNegativeButton("Cancel",null); builder.create().show(); } - }); + });*/ } else { builder.setTitle("Add account"); okButtonDesc = "Add"; diff --git a/src/de/gultsch/chat/ui/ManageAccountActivity.java b/src/de/gultsch/chat/ui/ManageAccountActivity.java index 0a9b03de..33469acd 100644 --- a/src/de/gultsch/chat/ui/ManageAccountActivity.java +++ b/src/de/gultsch/chat/ui/ManageAccountActivity.java @@ -7,23 +7,32 @@ import de.gultsch.chat.R; import de.gultsch.chat.entities.Account; import de.gultsch.chat.ui.EditAccount.EditAccountListener; import android.app.Activity; +import android.app.AlertDialog; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; +import android.view.ActionMode; +import android.view.ActionMode.Callback; import android.view.LayoutInflater; import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; +import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; -public class ManageAccountActivity extends XmppActivity { +public class ManageAccountActivity extends XmppActivity implements ActionMode.Callback { + protected boolean isActionMode = false; + protected ActionMode actionMode; + protected Account selectedAccountForActionMode = null; + protected List accountList = new ArrayList(); protected ListView accountListView; protected ArrayAdapter accountListViewAdapter; @@ -70,6 +79,10 @@ public class ManageAccountActivity extends XmppActivity { TextView statusView = (TextView) view .findViewById(R.id.account_status); switch (account.getStatus()) { + case Account.STATUS_DISABLED: + statusView.setText("temporarily disabled"); + statusView.setTextColor(0xFF1da9da); + break; case Account.STATUS_ONLINE: statusView.setText("online"); statusView.setTextColor(0xFF83b600); @@ -93,27 +106,49 @@ public class ManageAccountActivity extends XmppActivity { return view; } }; + final Activity activity = this; accountListView.setAdapter(this.accountListViewAdapter); accountListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView arg0, View view, int position, long arg3) { - EditAccount dialog = new EditAccount(); - dialog.setAccount(accountList.get(position)); - dialog.setEditAccountListener(new EditAccountListener() { + if (!isActionMode) { + EditAccount dialog = new EditAccount(); + dialog.setAccount(accountList.get(position)); + dialog.setEditAccountListener(new EditAccountListener() { + + @Override + public void onAccountEdited(Account account) { + xmppConnectionService.updateAccount(account); + } + + @Override + public void onAccountDelete(Account account) { + xmppConnectionService.deleteAccount(account); + } + }); + dialog.show(getFragmentManager(), "edit_account"); + } else { + selectedAccountForActionMode = accountList.get(position); + actionMode.invalidate(); + } + } + }); + accountListView.setOnItemLongClickListener(new OnItemLongClickListener() { - @Override - public void onAccountEdited(Account account) { - xmppConnectionService.updateAccount(account); - } - - @Override - public void onAccountDelete(Account account) { - xmppConnectionService.deleteAccount(account); - } - }); - dialog.show(getFragmentManager(), "edit_account"); + @Override + public boolean onItemLongClick(AdapterView arg0, View view, + int position, long arg3) { + if (!isActionMode) { + accountListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); + accountListView.setItemChecked(position,true); + selectedAccountForActionMode = accountList.get(position); + actionMode = activity.startActionMode((Callback) activity); + return true; + } else { + return false; + } } }); } @@ -180,4 +215,63 @@ public class ManageAccountActivity extends XmppActivity { }); dialog.show(getFragmentManager(), "add_account"); } + + @Override + public boolean onActionItemClicked(ActionMode mode, MenuItem item) { + if (item.getItemId()==R.id.account_disable) { + selectedAccountForActionMode.setOption(Account.OPTION_DISABLED, true); + xmppConnectionService.updateAccount(selectedAccountForActionMode); + mode.finish(); + } else if (item.getItemId()==R.id.account_enable) { + selectedAccountForActionMode.setOption(Account.OPTION_DISABLED, false); + xmppConnectionService.updateAccount(selectedAccountForActionMode); + mode.finish(); + } + return true; + } + + @Override + public boolean onCreateActionMode(ActionMode mode, Menu menu) { + MenuInflater inflater = mode.getMenuInflater(); + inflater.inflate(R.menu.manageaccounts_context, menu); + return true; + } + + @Override + public void onDestroyActionMode(ActionMode mode) { + // TODO Auto-generated method stub + + } + + @Override + public boolean onPrepareActionMode(ActionMode mode, Menu menu) { + if (selectedAccountForActionMode.isOptionSet(Account.OPTION_DISABLED)) { + menu.findItem(R.id.account_enable).setVisible(true); + menu.findItem(R.id.account_disable).setVisible(false); + } else { + menu.findItem(R.id.account_disable).setVisible(true); + menu.findItem(R.id.account_enable).setVisible(false); + } + return true; + } + + @Override + public void onActionModeStarted(ActionMode mode) { + super.onActionModeStarted(mode); + this.isActionMode = true; + } + + @Override + public void onActionModeFinished(ActionMode mode) { + super.onActionModeFinished(mode); + this.isActionMode = false; + accountListView.clearChoices(); + accountListView.requestLayout(); + accountListView.post(new Runnable() { + @Override + public void run() { + accountListView.setChoiceMode(ListView.CHOICE_MODE_NONE); + } + }); + } } diff --git a/src/de/gultsch/chat/ui/NewConversationActivity.java b/src/de/gultsch/chat/ui/NewConversationActivity.java index 71c377dd..3bfb4e2a 100644 --- a/src/de/gultsch/chat/ui/NewConversationActivity.java +++ b/src/de/gultsch/chat/ui/NewConversationActivity.java @@ -185,7 +185,7 @@ public class NewConversationActivity extends XmppActivity { AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle("Choose account"); - builder.setSingleChoiceItems(accountList,0,new OnClickListener() { + builder.setItems(accountList,new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) {