fixed #321 - delete otr fingerprints
This commit is contained in:
parent
90947597e5
commit
449c2a544b
Binary file not shown.
After Width: | Height: | Size: 448 B |
Binary file not shown.
After Width: | Height: | Size: 282 B |
Binary file not shown.
After Width: | Height: | Size: 513 B |
Binary file not shown.
After Width: | Height: | Size: 681 B |
|
@ -1,7 +1,13 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent" >
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_toLeftOf="@+id/button_remove"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="8dp" >
|
android:padding="8dp" >
|
||||||
|
|
||||||
|
@ -9,14 +15,26 @@
|
||||||
android:id="@+id/key"
|
android:id="@+id/key"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textSize="18sp"
|
|
||||||
android:textColor="@color/primarytext"
|
android:textColor="@color/primarytext"
|
||||||
android:typeface="monospace"
|
android:textSize="18sp"
|
||||||
/>
|
android:typeface="monospace" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/key_type"
|
android:id="@+id/key_type"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textColor="@color/secondarytext"
|
android:textColor="@color/secondarytext" />
|
||||||
/>
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/button_remove"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:padding="8dp"
|
||||||
|
android:background="?android:selectableItemBackground"
|
||||||
|
android:src="@drawable/ic_action_remove"
|
||||||
|
android:visibility="invisible"/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
|
@ -245,5 +245,7 @@
|
||||||
<string name="request_presence_updates">Please request presence updates from your contact first.\n\n<small>This will be used to determine what client(s) your contact is using.</small></string>
|
<string name="request_presence_updates">Please request presence updates from your contact first.\n\n<small>This will be used to determine what client(s) your contact is using.</small></string>
|
||||||
<string name="request_now">Request now</string>
|
<string name="request_now">Request now</string>
|
||||||
<string name="unable_to_decrypt_otr_message">Unable to decrypt OTR message</string>
|
<string name="unable_to_decrypt_otr_message">Unable to decrypt OTR message</string>
|
||||||
|
<string name="delete_fingerprint">Delete Fingerprint</string>
|
||||||
|
<string name="sure_delete_fingerprint">Are you sure you would like to delete this fingerprint?</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
|
@ -351,4 +351,26 @@ public class Contact implements ListItem {
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import android.view.View.OnClickListener;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.ImageButton;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.QuickContactBadge;
|
import android.widget.QuickContactBadge;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
@ -323,16 +324,25 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
for (Iterator<String> iterator = contact.getOtrFingerprints()
|
for (Iterator<String> iterator = contact.getOtrFingerprints()
|
||||||
.iterator(); iterator.hasNext();) {
|
.iterator(); iterator.hasNext();) {
|
||||||
String otrFingerprint = iterator.next();
|
final String otrFingerprint = iterator.next();
|
||||||
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 key = (TextView) view.findViewById(R.id.key);
|
||||||
TextView keyType = (TextView) view.findViewById(R.id.key_type);
|
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");
|
keyType.setText("OTR Fingerprint");
|
||||||
key.setText(otrFingerprint);
|
key.setText(otrFingerprint);
|
||||||
keys.addView(view);
|
keys.addView(view);
|
||||||
|
remove.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
confirmToDeleteFingerprint(otrFingerprint);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (contact.getPgpKeyId() != 0) {
|
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 key = (TextView) view.findViewById(R.id.key);
|
||||||
TextView keyType = (TextView) view.findViewById(R.id.key_type);
|
TextView keyType = (TextView) view.findViewById(R.id.key_type);
|
||||||
keyType.setText("PGP Key ID");
|
keyType.setText("PGP Key ID");
|
||||||
|
@ -361,6 +371,25 @@ public class ContactDetailsActivity extends XmppActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
@Override
|
||||||
public void onBackendConnected() {
|
public void onBackendConnected() {
|
||||||
xmppConnectionService.setOnRosterUpdateListener(this.rosterUpdate);
|
xmppConnectionService.setOnRosterUpdateListener(this.rosterUpdate);
|
||||||
|
|
Loading…
Reference in New Issue