From 449c2a544b48a2b9adf0df094eb1ac0d49531ebe Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Sun, 7 Sep 2014 23:08:40 +0200 Subject: [PATCH] fixed #321 - delete otr fingerprints --- res/drawable-hdpi/ic_action_remove.png | Bin 0 -> 448 bytes res/drawable-mdpi/ic_action_remove.png | Bin 0 -> 282 bytes res/drawable-xhdpi/ic_action_remove.png | Bin 0 -> 513 bytes res/drawable-xxhdpi/ic_action_remove.png | Bin 0 -> 681 bytes res/layout/contact_key.xml | 46 ++++++++++++------ res/values/strings.xml | 2 + .../siacs/conversations/entities/Contact.java | 22 +++++++++ .../ui/ContactDetailsActivity.java | 35 +++++++++++-- 8 files changed, 88 insertions(+), 17 deletions(-) create mode 100644 res/drawable-hdpi/ic_action_remove.png create mode 100644 res/drawable-mdpi/ic_action_remove.png create mode 100644 res/drawable-xhdpi/ic_action_remove.png create mode 100644 res/drawable-xxhdpi/ic_action_remove.png diff --git a/res/drawable-hdpi/ic_action_remove.png b/res/drawable-hdpi/ic_action_remove.png new file mode 100644 index 0000000000000000000000000000000000000000..58a56e457b0bc39aade617acddcf52b501d495e7 GIT binary patch literal 448 zcmV;x0YCnUP)P4JAQ8dR_a&lVlZKy!ug}vT`lWF+@e-?m3aEez zsDKLml|Y)NTd8w2h>dAu`+jFU8`;ZcCv}}9$+52M2MS&;xzvrsT}s>&T)_3t&OI(r z5)Js3d$p3dcZqvOPoYxkrSWVV%tNMA3w-3-DB&Yud)oH6?Rhr>K_k%tUsP3fqpSgx z1Pb0;03m^dA0!YWfrcL}Fhqg@A0*%-!GgDC2HuEX0Np(W9wyKu5wYNdr_hJfX~BYr z3Uo-&;C~{WhK|6Sbr7KwK#D-eBEBMWC#pctZ?r@ufE0ngO$wdGLIpnEVVM$!4bPS^ zW56>d%vkU&2{R@Ao#mPCGKjsl?eHI=Kd5iCN1?loIzqOP;>% qXmRpIkJnW|1yn!TpO6{U?C(jk_j4kWfkngEf(U{J>J_0T!D@Ue32A%s&x%(XKg8;9rG zqm(yRc%t|ei4vhyd`cXI8rV55iHS`7N*q`VN`$3$NOGGEv=SrY%?4@$sJO^LrN5B4 z*g(Mqq2iE%7ZZevw~V3gChV>Ss+Ul83{@AA>MBMEr8TuN6u;7x^Z1JX*#jQA*_jD% g|9u8S*SG~30I0v97|?&!(*OVf07*qoM6N<$f?e`)$^ZZW literal 0 HcmV?d00001 diff --git a/res/drawable-xhdpi/ic_action_remove.png b/res/drawable-xhdpi/ic_action_remove.png new file mode 100644 index 0000000000000000000000000000000000000000..58e2e3b4d86d43293595bfbcdf7aa14d462d7dfd GIT binary patch literal 513 zcmV+c0{;DpP)2M=_pR@i* zPEjZcR^hV+AS76ZFCxHFf_3;}0xTpT!WR`#QUWS`aRDVHAj6vo$dP~!Zzf=k1ds5h z0`8IE6+U}6SYkz=AE7zA$Wy1p8|=~!7V&gK%#^meXz0%8wWZ964n9e$r4n+ z9g84Tf;flor_-F)OM-ZYj|(39WC)(|r>v-Oq66AmapP&R+I|NHM}^O&8P#J-=iwAdNbrpXGl5g7zooZfe! zXy=~Q^508s)?R;|&#w7(p8l)j$+D}f&aa<&y-Vlf4wmJ z{m;$!KDWm<)IWJYp?`yVy?a)Rgy+7R7WpU3-7WlQo&Q_^@0!|=9dkD{|8ah%BK}}y zUwJzR`>Fc-=T0VbW}WtqPP|eM_FyzT{_JE!R zD)mzsyaca2=@)ZQY+Cdukl9DlG4$UH#$_D~bm}KDB)bJnw~uTvRI)fR-^3w}Mf~Sv z_7fcsRN|EmXe#eGIi0hhi=*$;Ql>v@O{@PLixhm)QT}Dxr&MO1o`9IAr*$3O_1veg z`?Qpqrz1f--tK_DQpAbv90e{c(m#7YGyP$o^P)53LpC?loVb0lEiVH0g|-+>zh76d zzw5&@{nHH0@veKsKFU^vF}CfCD89*-Dfr;V_F3ly55?}QZh7Ijuejxf>%Q!k7oPi) zTVD9?i*9)lxG%WnMd&{7mKTxxoLgSR?yG8<(OmPC!%+O^D#0YbPom04?mSuT+F^Mr zylcW%?L%qnpM8_#v%0PH_*W!j7~dy$w}_iMj&Eb;mhJQVTeVv6|AD73EMLFabmp+t zH{}!WBYrC$Dt@-J@Me4I8>JZ0$#0vg1>-jHzhy>_Y6gY|m493Y3}5QcuZR|#@EIiM M>FVdQ&MBb@07pA8tN;K2 literal 0 HcmV?d00001 diff --git a/res/layout/contact_key.xml b/res/layout/contact_key.xml index 0c457c25d..fdd1ddba0 100644 --- a/res/layout/contact_key.xml +++ b/res/layout/contact_key.xml @@ -1,22 +1,40 @@ - + + - + + + + + - - \ No newline at end of file + android:layout_alignParentRight="true" + android:layout_centerVertical="true" + android:padding="8dp" + android:background="?android:selectableItemBackground" + android:src="@drawable/ic_action_remove" + android:visibility="invisible"/> + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 0d5a75d52..75e2ee3aa 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -245,5 +245,7 @@ Please request presence updates from your contact first.\n\nThis will be used to determine what client(s) your contact is using. Request now Unable to decrypt OTR message + Delete Fingerprint + Are you sure you would like to delete this fingerprint? \ No newline at end of file diff --git a/src/eu/siacs/conversations/entities/Contact.java b/src/eu/siacs/conversations/entities/Contact.java index 8a6fd99c7..dfd6c0592 100644 --- a/src/eu/siacs/conversations/entities/Contact.java +++ b/src/eu/siacs/conversations/entities/Contact.java @@ -351,4 +351,26 @@ public class Contact implements ListItem { return true; } } + + public boolean deleteOtrFingerprint(String fingerprint) { + boolean success = false; + try { + if (this.keys.has("otr_fingerprints")) { + JSONArray newPrints = new JSONArray(); + JSONArray oldPrints = this.keys + .getJSONArray("otr_fingerprints"); + for (int i = 0; i < oldPrints.length(); ++i) { + if (!oldPrints.getString(i).equals(fingerprint)) { + newPrints.put(oldPrints.getString(i)); + } else { + success = true; + } + } + this.keys.put("otr_fingerprints", newPrints); + } + return success; + } catch (JSONException e) { + return false; + } + } } diff --git a/src/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/eu/siacs/conversations/ui/ContactDetailsActivity.java index a9153db1b..17ea5f98b 100644 --- a/src/eu/siacs/conversations/ui/ContactDetailsActivity.java +++ b/src/eu/siacs/conversations/ui/ContactDetailsActivity.java @@ -23,6 +23,7 @@ import android.view.View.OnClickListener; import android.widget.CheckBox; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.CompoundButton; +import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.QuickContactBadge; import android.widget.TextView; @@ -323,16 +324,25 @@ public class ContactDetailsActivity extends XmppActivity { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); for (Iterator iterator = contact.getOtrFingerprints() .iterator(); iterator.hasNext();) { - String otrFingerprint = iterator.next(); - View view = (View) inflater.inflate(R.layout.contact_key, null); + final String otrFingerprint = iterator.next(); + View view = (View) inflater.inflate(R.layout.contact_key, keys,false); TextView key = (TextView) view.findViewById(R.id.key); TextView keyType = (TextView) view.findViewById(R.id.key_type); + ImageButton remove = (ImageButton) view.findViewById(R.id.button_remove); + remove.setVisibility(View.VISIBLE); keyType.setText("OTR Fingerprint"); key.setText(otrFingerprint); keys.addView(view); + remove.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + confirmToDeleteFingerprint(otrFingerprint); + } + }); } if (contact.getPgpKeyId() != 0) { - View view = (View) inflater.inflate(R.layout.contact_key, null); + View view = (View) inflater.inflate(R.layout.contact_key, keys,false); TextView key = (TextView) view.findViewById(R.id.key); TextView keyType = (TextView) view.findViewById(R.id.key_type); keyType.setText("PGP Key ID"); @@ -360,6 +370,25 @@ public class ContactDetailsActivity extends XmppActivity { keys.addView(view); } } + + protected void confirmToDeleteFingerprint(final String fingerprint) { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.delete_fingerprint); + builder.setMessage(R.string.sure_delete_fingerprint); + builder.setNegativeButton(R.string.cancel, null); + builder.setPositiveButton(R.string.delete,new android.content.DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + if (contact.deleteOtrFingerprint(fingerprint)) { + populateView(); + xmppConnectionService.syncRosterToDisk(contact.getAccount()); + } + } + + }); + builder.create().show(); + } @Override public void onBackendConnected() {