ported subscription stuff from old contact dialog

This commit is contained in:
Daniel Gultsch 2014-03-07 20:36:04 +01:00
parent 93d11b3c99
commit 100059b530
2 changed files with 76 additions and 20 deletions

View File

@ -24,6 +24,7 @@ import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.QuickContactBadge; import android.widget.QuickContactBadge;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Presences; import eu.siacs.conversations.entities.Presences;
@ -123,18 +124,20 @@ public class ContactDetailsActivity extends XmppActivity {
break; break;
case R.id.action_delete_contact: case R.id.action_delete_contact:
builder.setTitle("Delete from roster") builder.setTitle("Delete from roster")
.setMessage(getString(R.string.remove_contact_text, contact.getJid())) .setMessage(
getString(R.string.remove_contact_text,
contact.getJid()))
.setPositiveButton("Delete", removeFromRoster).create() .setPositiveButton("Delete", removeFromRoster).create()
.show(); .show();
break; break;
case R.id.action_edit_contact: case R.id.action_edit_contact:
if (contact.getSystemAccount() == null) { if (contact.getSystemAccount() == null) {
View view = (View) getLayoutInflater().inflate(R.layout.edit_contact_name, null); View view = (View) getLayoutInflater().inflate(
R.layout.edit_contact_name, null);
name = (EditText) view.findViewById(R.id.editText1); name = (EditText) view.findViewById(R.id.editText1);
name.setText(contact.getDisplayName()); name.setText(contact.getDisplayName());
builder.setView(view) builder.setView(view).setTitle(contact.getJid())
.setTitle(contact.getJid())
.setPositiveButton("Edit", editContactNameListener) .setPositiveButton("Edit", editContactNameListener)
.create().show(); .create().show();
@ -143,9 +146,9 @@ public class ContactDetailsActivity extends XmppActivity {
String[] systemAccount = contact.getSystemAccount().split("#"); String[] systemAccount = contact.getSystemAccount().split("#");
long id = Long.parseLong(systemAccount[0]); long id = Long.parseLong(systemAccount[0]);
Uri uri = Contacts.getLookupUri(id, systemAccount[1]); Uri uri = Contacts.getLookupUri(id, systemAccount[1]);
intent.setDataAndType(uri,Contacts.CONTENT_ITEM_TYPE); intent.setDataAndType(uri, Contacts.CONTENT_ITEM_TYPE);
intent.putExtra("finishActivityOnSaveCompleted", true); intent.putExtra("finishActivityOnSaveCompleted", true);
startActivity(intent); startActivity(intent);
} }
break; break;
} }
@ -157,7 +160,7 @@ public class ContactDetailsActivity extends XmppActivity {
getMenuInflater().inflate(R.menu.contact_details, menu); getMenuInflater().inflate(R.menu.contact_details, menu);
return true; return true;
} }
private void populateView() { private void populateView() {
setTitle(contact.getDisplayName()); setTitle(contact.getDisplayName());
if (contact.getSubscriptionOption(Contact.Subscription.FROM)) { if (contact.getSubscriptionOption(Contact.Subscription.FROM)) {
@ -175,8 +178,7 @@ public class ContactDetailsActivity extends XmppActivity {
receive.setChecked(true); receive.setChecked(true);
} else { } else {
receive.setText("Request presence updates"); receive.setText("Request presence updates");
if (contact if (contact.getSubscriptionOption(Contact.Subscription.ASKING)) {
.getSubscriptionOption(Contact.Subscription.ASKING)) {
receive.setChecked(true); receive.setChecked(true);
} else { } else {
receive.setChecked(false); receive.setChecked(false);
@ -221,27 +223,28 @@ public class ContactDetailsActivity extends XmppActivity {
if (contact.getSystemAccount() == null) { if (contact.getSystemAccount() == null) {
badge.setOnClickListener(onBadgeClick); badge.setOnClickListener(onBadgeClick);
} }
keys.removeAllViews(); keys.removeAllViews();
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for (Iterator<String> iterator = contact.getOtrFingerprints().iterator(); iterator for (Iterator<String> iterator = contact.getOtrFingerprints()
.hasNext();) { .iterator(); iterator.hasNext();) {
String otrFingerprint = iterator.next(); String otrFingerprint = iterator.next();
View view = (View) inflater.inflate(R.layout.contact_key, null); View view = (View) inflater.inflate(R.layout.contact_key, null);
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("OTR Fingerprint"); keyType.setText("OTR Fingerprint");
key.setText(otrFingerprint); key.setText(otrFingerprint);
keys.addView(view); keys.addView(view);
} }
Log.d("gultsch","pgp key id "+contact.getPgpKeyId()); Log.d("gultsch", "pgp key id " + contact.getPgpKeyId());
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, null);
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");
BigInteger bi = new BigInteger(""+contact.getPgpKeyId()); BigInteger bi = new BigInteger("" + contact.getPgpKeyId());
StringBuilder builder = new StringBuilder(bi.toString(16).toUpperCase()); StringBuilder builder = new StringBuilder(bi.toString(16)
.toUpperCase());
builder.insert(8, " "); builder.insert(8, " ");
key.setText(builder.toString()); key.setText(builder.toString());
keys.addView(view); keys.addView(view);
@ -258,4 +261,58 @@ public class ContactDetailsActivity extends XmppActivity {
} }
} }
@Override
protected void onStop() {
super.onStop();
boolean needsUpdating = false;
if (contact.getSubscriptionOption(Contact.Subscription.FROM)) {
if (!send.isChecked()) {
contact.resetSubscriptionOption(Contact.Subscription.FROM);
contact.resetSubscriptionOption(Contact.Subscription.PREEMPTIVE_GRANT);
activity.xmppConnectionService.stopPresenceUpdatesTo(contact);
needsUpdating = true;
}
} else {
if (contact
.getSubscriptionOption(Contact.Subscription.PREEMPTIVE_GRANT)) {
if (!send.isChecked()) {
contact.resetSubscriptionOption(Contact.Subscription.PREEMPTIVE_GRANT);
needsUpdating = true;
}
} else {
if (send.isChecked()) {
contact.setSubscriptionOption(Contact.Subscription.PREEMPTIVE_GRANT);
needsUpdating = true;
}
}
}
if (contact.getSubscriptionOption(Contact.Subscription.TO)) {
if (!receive.isChecked()) {
contact.resetSubscriptionOption(Contact.Subscription.TO);
activity.xmppConnectionService.stopPresenceUpdatesFrom(contact);
needsUpdating = true;
}
} else {
if (contact.getSubscriptionOption(Contact.Subscription.ASKING)) {
if (!receive.isChecked()) {
contact.resetSubscriptionOption(Contact.Subscription.ASKING);
activity.xmppConnectionService
.stopPresenceUpdatesFrom(contact);
needsUpdating = true;
}
} else {
if (receive.isChecked()) {
contact.setSubscriptionOption(Contact.Subscription.ASKING);
activity.xmppConnectionService
.requestPresenceUpdatesFrom(contact);
needsUpdating = true;
}
}
}
if (needsUpdating) {
Toast.makeText(getApplicationContext(), "Subscription updated", Toast.LENGTH_SHORT).show();
activity.xmppConnectionService.updateContact(contact);
}
}
} }

View File

@ -89,7 +89,6 @@ public class ManageAccountActivity extends XmppActivity {
hint.setText(getString(R.string.untrusted_cert_hint,account.getServer())); hint.setText(getString(R.string.untrusted_cert_hint,account.getServer()));
sha.setText(humanReadableSha.toString()); sha.setText(humanReadableSha.toString());
builder.setView(view); builder.setView(view);
//builder.setMessage(server+" presented you with an unstrusted, possible self signed, certificate. The SHA1 fingerprint is "+fingerprint+" Do not connect unless you know exactly what you are doing");
builder.setNegativeButton("Don't connect", null); builder.setNegativeButton("Don't connect", null);
builder.setPositiveButton("Trust certificate", new OnClickListener() { builder.setPositiveButton("Trust certificate", new OnClickListener() {