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.QuickContactBadge;
import android.widget.TextView;
import android.widget.Toast;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Presences;
@ -123,18 +124,20 @@ public class ContactDetailsActivity extends XmppActivity {
break;
case R.id.action_delete_contact:
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()
.show();
break;
case R.id.action_edit_contact:
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.setText(contact.getDisplayName());
builder.setView(view)
.setTitle(contact.getJid())
builder.setView(view).setTitle(contact.getJid())
.setPositiveButton("Edit", editContactNameListener)
.create().show();
@ -175,8 +178,7 @@ public class ContactDetailsActivity extends XmppActivity {
receive.setChecked(true);
} else {
receive.setText("Request presence updates");
if (contact
.getSubscriptionOption(Contact.Subscription.ASKING)) {
if (contact.getSubscriptionOption(Contact.Subscription.ASKING)) {
receive.setChecked(true);
} else {
receive.setChecked(false);
@ -224,8 +226,8 @@ public class ContactDetailsActivity extends XmppActivity {
keys.removeAllViews();
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for (Iterator<String> iterator = contact.getOtrFingerprints().iterator(); iterator
.hasNext();) {
for (Iterator<String> iterator = contact.getOtrFingerprints()
.iterator(); iterator.hasNext();) {
String otrFingerprint = iterator.next();
View view = (View) inflater.inflate(R.layout.contact_key, null);
TextView key = (TextView) view.findViewById(R.id.key);
@ -241,7 +243,8 @@ public class ContactDetailsActivity extends XmppActivity {
TextView keyType = (TextView) view.findViewById(R.id.key_type);
keyType.setText("PGP Key ID");
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, " ");
key.setText(builder.toString());
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()));
sha.setText(humanReadableSha.toString());
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.setPositiveButton("Trust certificate", new OnClickListener() {