2014-03-05 14:41:14 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
|
|
|
import android.app.AlertDialog;
|
2014-05-09 18:47:03 +00:00
|
|
|
import android.app.PendingIntent;
|
2014-03-06 19:00:46 +00:00
|
|
|
import android.content.Context;
|
2014-03-05 14:41:14 +00:00
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
2014-05-09 18:47:03 +00:00
|
|
|
import android.content.IntentSender.SendIntentException;
|
2014-11-18 13:24:06 +00:00
|
|
|
import android.content.SharedPreferences;
|
2014-03-05 14:41:14 +00:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
2014-11-18 13:24:06 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2014-03-05 14:41:14 +00:00
|
|
|
import android.provider.ContactsContract.CommonDataKinds;
|
|
|
|
import android.provider.ContactsContract.Contacts;
|
|
|
|
import android.provider.ContactsContract.Intents;
|
2014-03-06 19:00:46 +00:00
|
|
|
import android.view.LayoutInflater;
|
2014-03-05 14:41:14 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View.OnClickListener;
|
2015-01-21 14:31:40 +00:00
|
|
|
import android.widget.Button;
|
2014-03-05 14:41:14 +00:00
|
|
|
import android.widget.CheckBox;
|
2014-07-20 01:14:47 +00:00
|
|
|
import android.widget.CompoundButton;
|
2014-11-11 16:39:28 +00:00
|
|
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
2014-09-07 21:08:40 +00:00
|
|
|
import android.widget.ImageButton;
|
2014-03-06 19:00:46 +00:00
|
|
|
import android.widget.LinearLayout;
|
2014-03-05 14:41:14 +00:00
|
|
|
import android.widget.QuickContactBadge;
|
|
|
|
import android.widget.TextView;
|
2015-12-23 21:30:14 +00:00
|
|
|
import android.widget.Toast;
|
2014-11-11 16:39:28 +00:00
|
|
|
|
2016-08-26 14:34:42 +00:00
|
|
|
import com.wefika.flowlayout.FlowLayout;
|
|
|
|
|
2014-11-11 16:39:28 +00:00
|
|
|
import org.openintents.openpgp.util.OpenPgpUtils;
|
|
|
|
|
2015-12-23 18:18:53 +00:00
|
|
|
import java.security.cert.X509Certificate;
|
2014-11-18 13:24:06 +00:00
|
|
|
import java.util.List;
|
2014-11-11 16:39:28 +00:00
|
|
|
|
2015-08-03 20:58:17 +00:00
|
|
|
import eu.siacs.conversations.Config;
|
2014-03-05 14:41:14 +00:00
|
|
|
import eu.siacs.conversations.R;
|
2014-05-09 18:47:03 +00:00
|
|
|
import eu.siacs.conversations.crypto.PgpEngine;
|
2015-10-17 12:09:26 +00:00
|
|
|
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
|
2015-12-23 18:18:53 +00:00
|
|
|
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
|
2014-05-19 13:15:09 +00:00
|
|
|
import eu.siacs.conversations.entities.Account;
|
2014-03-05 14:41:14 +00:00
|
|
|
import eu.siacs.conversations.entities.Contact;
|
2014-11-18 13:24:06 +00:00
|
|
|
import eu.siacs.conversations.entities.ListItem;
|
2016-04-23 10:19:00 +00:00
|
|
|
import eu.siacs.conversations.entities.Presence;
|
2014-07-20 11:21:21 +00:00
|
|
|
import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
|
2014-07-18 13:35:31 +00:00
|
|
|
import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
|
2015-01-02 00:21:14 +00:00
|
|
|
import eu.siacs.conversations.utils.CryptoHelper;
|
2014-03-05 14:41:14 +00:00
|
|
|
import eu.siacs.conversations.utils.UIHelper;
|
2015-07-21 12:18:16 +00:00
|
|
|
import eu.siacs.conversations.xmpp.OnKeyStatusUpdated;
|
2014-12-21 20:43:58 +00:00
|
|
|
import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
|
2015-01-21 14:31:40 +00:00
|
|
|
import eu.siacs.conversations.xmpp.XmppConnection;
|
2014-11-06 19:33:13 +00:00
|
|
|
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
|
|
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
2014-03-05 14:41:14 +00:00
|
|
|
|
2015-07-21 12:18:16 +00:00
|
|
|
public class ContactDetailsActivity extends XmppActivity implements OnAccountUpdate, OnRosterUpdate, OnUpdateBlocklist, OnKeyStatusUpdated {
|
2014-03-05 14:41:14 +00:00
|
|
|
public static final String ACTION_VIEW_CONTACT = "view_contact";
|
|
|
|
|
|
|
|
private Contact contact;
|
|
|
|
private DialogInterface.OnClickListener removeFromRoster = new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2015-01-21 14:31:40 +00:00
|
|
|
xmppConnectionService.deleteContactOnServer(contact);
|
2014-03-05 14:41:14 +00:00
|
|
|
}
|
|
|
|
};
|
2014-07-20 01:14:47 +00:00
|
|
|
private OnCheckedChangeListener mOnSendCheckedChange = new OnCheckedChangeListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView,
|
2014-12-21 20:43:58 +00:00
|
|
|
boolean isChecked) {
|
2014-07-20 01:14:47 +00:00
|
|
|
if (isChecked) {
|
2014-08-31 14:28:21 +00:00
|
|
|
if (contact
|
|
|
|
.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
|
2014-07-20 01:14:47 +00:00
|
|
|
xmppConnectionService.sendPresencePacket(contact
|
2014-12-21 20:43:58 +00:00
|
|
|
.getAccount(),
|
2014-07-20 01:14:47 +00:00
|
|
|
xmppConnectionService.getPresenceGenerator()
|
2014-12-21 20:43:58 +00:00
|
|
|
.sendPresenceUpdatesTo(contact));
|
2014-07-20 01:14:47 +00:00
|
|
|
} else {
|
|
|
|
contact.setOption(Contact.Options.PREEMPTIVE_GRANT);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
|
|
|
|
xmppConnectionService.sendPresencePacket(contact.getAccount(),
|
|
|
|
xmppConnectionService.getPresenceGenerator()
|
2014-12-21 20:43:58 +00:00
|
|
|
.stopPresenceUpdatesTo(contact));
|
2014-07-20 01:14:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
private OnCheckedChangeListener mOnReceiveCheckedChange = new OnCheckedChangeListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView,
|
2014-12-21 20:43:58 +00:00
|
|
|
boolean isChecked) {
|
2014-07-20 01:14:47 +00:00
|
|
|
if (isChecked) {
|
|
|
|
xmppConnectionService.sendPresencePacket(contact.getAccount(),
|
|
|
|
xmppConnectionService.getPresenceGenerator()
|
2014-12-21 20:43:58 +00:00
|
|
|
.requestPresenceUpdatesFrom(contact));
|
2014-07-20 01:14:47 +00:00
|
|
|
} else {
|
|
|
|
xmppConnectionService.sendPresencePacket(contact.getAccount(),
|
|
|
|
xmppConnectionService.getPresenceGenerator()
|
2014-12-21 20:43:58 +00:00
|
|
|
.stopPresenceUpdatesFrom(contact));
|
2014-07-20 01:14:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-11-11 16:39:28 +00:00
|
|
|
private Jid accountJid;
|
2016-06-04 14:16:14 +00:00
|
|
|
private TextView lastseen;
|
2014-11-11 16:39:28 +00:00
|
|
|
private Jid contactJid;
|
|
|
|
private TextView contactJidTv;
|
|
|
|
private TextView accountJidTv;
|
2016-04-23 10:19:00 +00:00
|
|
|
private TextView statusMessage;
|
2014-11-11 16:39:28 +00:00
|
|
|
private CheckBox send;
|
|
|
|
private CheckBox receive;
|
2015-01-21 14:31:40 +00:00
|
|
|
private Button addContactButton;
|
2014-11-11 16:39:28 +00:00
|
|
|
private QuickContactBadge badge;
|
2014-11-18 13:24:06 +00:00
|
|
|
private LinearLayout keys;
|
2016-08-26 14:34:42 +00:00
|
|
|
private FlowLayout tags;
|
2016-06-04 14:16:14 +00:00
|
|
|
private boolean showDynamicTags = false;
|
|
|
|
private boolean showLastSeen = false;
|
2015-07-29 18:21:37 +00:00
|
|
|
private String messageFingerprint;
|
2014-11-18 13:24:06 +00:00
|
|
|
|
2014-11-11 16:39:28 +00:00
|
|
|
private DialogInterface.OnClickListener addToPhonebook = new DialogInterface.OnClickListener() {
|
2014-08-31 14:28:21 +00:00
|
|
|
|
2014-07-20 11:21:21 +00:00
|
|
|
@Override
|
2014-11-11 16:39:28 +00:00
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
|
|
|
|
intent.setType(Contacts.CONTENT_ITEM_TYPE);
|
|
|
|
intent.putExtra(Intents.Insert.IM_HANDLE, contact.getJid().toString());
|
|
|
|
intent.putExtra(Intents.Insert.IM_PROTOCOL,
|
|
|
|
CommonDataKinds.Im.PROTOCOL_JABBER);
|
|
|
|
intent.putExtra("finishActivityOnSaveCompleted", true);
|
|
|
|
ContactDetailsActivity.this.startActivityForResult(intent, 0);
|
|
|
|
}
|
|
|
|
};
|
2014-11-18 13:24:06 +00:00
|
|
|
|
2014-11-11 16:39:28 +00:00
|
|
|
private OnClickListener onBadgeClick = new OnClickListener() {
|
2014-07-20 11:21:21 +00:00
|
|
|
|
2014-11-11 16:39:28 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2016-08-26 11:35:01 +00:00
|
|
|
Uri systemAccount = contact.getSystemAccount();
|
|
|
|
if (systemAccount == null) {
|
2015-06-03 12:05:54 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(
|
|
|
|
ContactDetailsActivity.this);
|
|
|
|
builder.setTitle(getString(R.string.action_add_phone_book));
|
|
|
|
builder.setMessage(getString(R.string.add_phone_book_text,
|
2016-02-24 15:53:19 +00:00
|
|
|
contact.getDisplayJid()));
|
2015-06-03 12:05:54 +00:00
|
|
|
builder.setNegativeButton(getString(R.string.cancel), null);
|
|
|
|
builder.setPositiveButton(getString(R.string.add), addToPhonebook);
|
|
|
|
builder.create().show();
|
|
|
|
} else {
|
2016-08-26 11:35:01 +00:00
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.setData(systemAccount);
|
|
|
|
startActivity(intent);
|
2015-06-03 12:05:54 +00:00
|
|
|
}
|
2014-07-20 11:21:21 +00:00
|
|
|
}
|
|
|
|
};
|
2014-11-11 16:39:28 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRosterUpdate() {
|
2015-02-17 13:18:35 +00:00
|
|
|
refreshUi();
|
2014-11-11 16:39:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAccountUpdate() {
|
2015-02-17 13:18:35 +00:00
|
|
|
refreshUi();
|
|
|
|
}
|
2014-11-11 16:39:28 +00:00
|
|
|
|
2015-07-20 13:48:58 +00:00
|
|
|
@Override
|
|
|
|
public void OnUpdateBlocklist(final Status status) {
|
|
|
|
refreshUi();
|
|
|
|
}
|
|
|
|
|
2015-02-17 13:18:35 +00:00
|
|
|
@Override
|
|
|
|
protected void refreshUiReal() {
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
populateView();
|
2014-11-11 16:39:28 +00:00
|
|
|
}
|
2014-07-20 11:21:21 +00:00
|
|
|
|
2014-11-04 11:15:14 +00:00
|
|
|
@Override
|
|
|
|
protected String getShareableUri() {
|
2014-11-11 16:39:28 +00:00
|
|
|
if (contact != null) {
|
2016-06-24 13:16:01 +00:00
|
|
|
return "xmpp:"+contact.getJid().toBareJid().toString();
|
2014-11-04 11:15:14 +00:00
|
|
|
} else {
|
2014-11-04 16:10:35 +00:00
|
|
|
return "";
|
2014-11-04 11:15:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-05 14:41:14 +00:00
|
|
|
@Override
|
2014-12-21 20:43:58 +00:00
|
|
|
protected void onCreate(final Bundle savedInstanceState) {
|
2014-03-05 14:41:14 +00:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
if (getIntent().getAction().equals(ACTION_VIEW_CONTACT)) {
|
2014-11-11 16:39:28 +00:00
|
|
|
try {
|
2016-01-22 19:46:24 +00:00
|
|
|
this.accountJid = Jid.fromString(getIntent().getExtras().getString(EXTRA_ACCOUNT));
|
2014-11-11 16:39:28 +00:00
|
|
|
} catch (final InvalidJidException ignored) {
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
this.contactJid = Jid.fromString(getIntent().getExtras().getString("contact"));
|
|
|
|
} catch (final InvalidJidException ignored) {
|
|
|
|
}
|
|
|
|
}
|
2015-07-29 18:21:37 +00:00
|
|
|
this.messageFingerprint = getIntent().getStringExtra("fingerprint");
|
2014-03-05 14:41:14 +00:00
|
|
|
setContentView(R.layout.activity_contact_details);
|
|
|
|
|
2014-05-19 13:15:09 +00:00
|
|
|
contactJidTv = (TextView) findViewById(R.id.details_contactjid);
|
|
|
|
accountJidTv = (TextView) findViewById(R.id.details_account);
|
2016-06-04 14:16:14 +00:00
|
|
|
lastseen = (TextView) findViewById(R.id.details_lastseen);
|
2016-04-23 10:19:00 +00:00
|
|
|
statusMessage = (TextView) findViewById(R.id.status_message);
|
2014-03-05 14:41:14 +00:00
|
|
|
send = (CheckBox) findViewById(R.id.details_send_presence);
|
|
|
|
receive = (CheckBox) findViewById(R.id.details_receive_presence);
|
|
|
|
badge = (QuickContactBadge) findViewById(R.id.details_contact_badge);
|
2015-01-21 14:31:40 +00:00
|
|
|
addContactButton = (Button) findViewById(R.id.add_contact_button);
|
|
|
|
addContactButton.setOnClickListener(new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
showAddToRosterDialog(contact);
|
|
|
|
}
|
|
|
|
});
|
2014-03-06 19:00:46 +00:00
|
|
|
keys = (LinearLayout) findViewById(R.id.details_contact_keys);
|
2016-08-26 14:34:42 +00:00
|
|
|
tags = (FlowLayout) findViewById(R.id.tags);
|
2014-12-21 20:43:58 +00:00
|
|
|
if (getActionBar() != null) {
|
|
|
|
getActionBar().setHomeButtonEnabled(true);
|
|
|
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
}
|
2016-06-04 14:16:14 +00:00
|
|
|
}
|
2014-03-05 14:41:14 +00:00
|
|
|
|
2016-06-04 14:16:14 +00:00
|
|
|
@Override
|
|
|
|
public void onStart() {
|
|
|
|
super.onStart();
|
2014-12-21 20:43:58 +00:00
|
|
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
2014-11-18 13:24:06 +00:00
|
|
|
this.showDynamicTags = preferences.getBoolean("show_dynamic_tags",false);
|
2016-06-04 14:16:14 +00:00
|
|
|
this.showLastSeen = preferences.getBoolean("last_activity", false);
|
2014-03-05 14:41:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-12-21 20:43:58 +00:00
|
|
|
public boolean onOptionsItemSelected(final MenuItem menuItem) {
|
2015-01-16 00:08:12 +00:00
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
2014-05-22 20:58:25 +00:00
|
|
|
builder.setNegativeButton(getString(R.string.cancel), null);
|
2014-03-05 14:41:14 +00:00
|
|
|
switch (menuItem.getItemId()) {
|
2014-11-11 16:39:28 +00:00
|
|
|
case android.R.id.home:
|
|
|
|
finish();
|
|
|
|
break;
|
2016-06-24 13:16:01 +00:00
|
|
|
case R.id.action_share:
|
|
|
|
shareUri();
|
|
|
|
break;
|
2014-11-11 16:39:28 +00:00
|
|
|
case R.id.action_delete_contact:
|
|
|
|
builder.setTitle(getString(R.string.action_delete_contact))
|
2014-12-21 20:43:58 +00:00
|
|
|
.setMessage(
|
|
|
|
getString(R.string.remove_contact_text,
|
2016-02-24 15:53:19 +00:00
|
|
|
contact.getDisplayJid()))
|
2014-12-21 20:43:58 +00:00
|
|
|
.setPositiveButton(getString(R.string.delete),
|
|
|
|
removeFromRoster).create().show();
|
2014-11-11 16:39:28 +00:00
|
|
|
break;
|
|
|
|
case R.id.action_edit_contact:
|
2016-08-26 11:35:01 +00:00
|
|
|
Uri systemAccount = contact.getSystemAccount();
|
|
|
|
if (systemAccount == null) {
|
2016-05-22 16:20:57 +00:00
|
|
|
quickEdit(contact.getDisplayName(), 0, new OnValueEdited() {
|
2014-11-11 16:39:28 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onValueEdited(String value) {
|
|
|
|
contact.setServerName(value);
|
|
|
|
ContactDetailsActivity.this.xmppConnectionService
|
2014-12-21 20:43:58 +00:00
|
|
|
.pushContactToServer(contact);
|
2014-11-11 16:39:28 +00:00
|
|
|
populateView();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_EDIT);
|
2016-08-26 11:35:01 +00:00
|
|
|
intent.setDataAndType(systemAccount, Contacts.CONTENT_ITEM_TYPE);
|
2014-11-11 16:39:28 +00:00
|
|
|
intent.putExtra("finishActivityOnSaveCompleted", true);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
break;
|
2015-01-16 00:08:12 +00:00
|
|
|
case R.id.action_block:
|
|
|
|
BlockContactDialog.show(this, xmppConnectionService, contact);
|
|
|
|
break;
|
|
|
|
case R.id.action_unblock:
|
|
|
|
BlockContactDialog.show(this, xmppConnectionService, contact);
|
|
|
|
break;
|
2014-03-05 14:41:14 +00:00
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(menuItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-16 00:08:12 +00:00
|
|
|
public boolean onCreateOptionsMenu(final Menu menu) {
|
2014-03-05 14:41:14 +00:00
|
|
|
getMenuInflater().inflate(R.menu.contact_details, menu);
|
2015-01-21 14:31:40 +00:00
|
|
|
MenuItem block = menu.findItem(R.id.action_block);
|
|
|
|
MenuItem unblock = menu.findItem(R.id.action_unblock);
|
|
|
|
MenuItem edit = menu.findItem(R.id.action_edit_contact);
|
|
|
|
MenuItem delete = menu.findItem(R.id.action_delete_contact);
|
2015-04-28 11:31:33 +00:00
|
|
|
if (contact == null) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-01-21 14:31:40 +00:00
|
|
|
final XmppConnection connection = contact.getAccount().getXmppConnection();
|
|
|
|
if (connection != null && connection.getFeatures().blocking()) {
|
|
|
|
if (this.contact.isBlocked()) {
|
2015-04-28 11:31:33 +00:00
|
|
|
block.setVisible(false);
|
2015-01-21 14:31:40 +00:00
|
|
|
} else {
|
2015-04-28 11:31:33 +00:00
|
|
|
unblock.setVisible(false);
|
2015-01-21 14:31:40 +00:00
|
|
|
}
|
2015-01-16 00:08:12 +00:00
|
|
|
} else {
|
2015-04-28 11:31:33 +00:00
|
|
|
unblock.setVisible(false);
|
|
|
|
block.setVisible(false);
|
2015-01-21 14:31:40 +00:00
|
|
|
}
|
|
|
|
if (!contact.showInRoster()) {
|
|
|
|
edit.setVisible(false);
|
|
|
|
delete.setVisible(false);
|
2015-01-16 00:08:12 +00:00
|
|
|
}
|
2016-02-27 09:25:31 +00:00
|
|
|
return super.onCreateOptionsMenu(menu);
|
2014-03-05 14:41:14 +00:00
|
|
|
}
|
2014-03-07 19:36:04 +00:00
|
|
|
|
2014-03-05 14:41:14 +00:00
|
|
|
private void populateView() {
|
2016-08-20 08:44:50 +00:00
|
|
|
if (contact == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-04-28 11:31:33 +00:00
|
|
|
invalidateOptionsMenu();
|
2014-03-05 14:41:14 +00:00
|
|
|
setTitle(contact.getDisplayName());
|
2015-01-21 14:31:40 +00:00
|
|
|
if (contact.showInRoster()) {
|
|
|
|
send.setVisibility(View.VISIBLE);
|
|
|
|
receive.setVisibility(View.VISIBLE);
|
|
|
|
addContactButton.setVisibility(View.GONE);
|
|
|
|
send.setOnCheckedChangeListener(null);
|
|
|
|
receive.setOnCheckedChangeListener(null);
|
|
|
|
|
2016-04-23 10:19:00 +00:00
|
|
|
List<String> statusMessages = contact.getPresences().getStatusMessages();
|
|
|
|
if (statusMessages.size() == 0) {
|
|
|
|
statusMessage.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
statusMessage.setVisibility(View.VISIBLE);
|
|
|
|
int s = statusMessages.size();
|
|
|
|
for(int i = 0; i < s; ++i) {
|
|
|
|
if (s > 1) {
|
|
|
|
builder.append("• ");
|
|
|
|
}
|
|
|
|
builder.append(statusMessages.get(i));
|
|
|
|
if (i < s - 1) {
|
|
|
|
builder.append("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
statusMessage.setText(builder);
|
|
|
|
}
|
|
|
|
|
2015-01-21 14:31:40 +00:00
|
|
|
if (contact.getOption(Contact.Options.FROM)) {
|
|
|
|
send.setText(R.string.send_presence_updates);
|
2014-03-05 14:41:14 +00:00
|
|
|
send.setChecked(true);
|
2015-01-21 14:31:40 +00:00
|
|
|
} else if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
|
2014-03-05 14:41:14 +00:00
|
|
|
send.setChecked(false);
|
2015-01-21 14:31:40 +00:00
|
|
|
send.setText(R.string.send_presence_updates);
|
|
|
|
} else {
|
|
|
|
send.setText(R.string.preemptively_grant);
|
|
|
|
if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
|
|
|
|
send.setChecked(true);
|
|
|
|
} else {
|
|
|
|
send.setChecked(false);
|
|
|
|
}
|
2014-03-05 14:41:14 +00:00
|
|
|
}
|
2015-01-21 14:31:40 +00:00
|
|
|
if (contact.getOption(Contact.Options.TO)) {
|
|
|
|
receive.setText(R.string.receive_presence_updates);
|
2014-03-05 14:41:14 +00:00
|
|
|
receive.setChecked(true);
|
|
|
|
} else {
|
2015-01-21 14:31:40 +00:00
|
|
|
receive.setText(R.string.ask_for_presence_updates);
|
|
|
|
if (contact.getOption(Contact.Options.ASKING)) {
|
|
|
|
receive.setChecked(true);
|
|
|
|
} else {
|
|
|
|
receive.setChecked(false);
|
|
|
|
}
|
2014-03-05 14:41:14 +00:00
|
|
|
}
|
2015-01-21 14:31:40 +00:00
|
|
|
if (contact.getAccount().isOnlineAndConnected()) {
|
|
|
|
receive.setEnabled(true);
|
|
|
|
send.setEnabled(true);
|
|
|
|
} else {
|
|
|
|
receive.setEnabled(false);
|
|
|
|
send.setEnabled(false);
|
|
|
|
}
|
|
|
|
send.setOnCheckedChangeListener(this.mOnSendCheckedChange);
|
|
|
|
receive.setOnCheckedChangeListener(this.mOnReceiveCheckedChange);
|
2014-07-20 11:21:21 +00:00
|
|
|
} else {
|
2015-01-21 14:31:40 +00:00
|
|
|
addContactButton.setVisibility(View.VISIBLE);
|
|
|
|
send.setVisibility(View.GONE);
|
|
|
|
receive.setVisibility(View.GONE);
|
2016-04-23 10:19:00 +00:00
|
|
|
statusMessage.setVisibility(View.GONE);
|
2014-07-20 11:21:21 +00:00
|
|
|
}
|
2014-07-20 01:14:47 +00:00
|
|
|
|
2016-06-04 14:16:14 +00:00
|
|
|
if (contact.isBlocked() && !this.showDynamicTags) {
|
|
|
|
lastseen.setVisibility(View.VISIBLE);
|
|
|
|
lastseen.setText(R.string.contact_blocked);
|
|
|
|
} else {
|
|
|
|
if (showLastSeen && contact.getLastseen() > 0) {
|
|
|
|
lastseen.setVisibility(View.VISIBLE);
|
|
|
|
lastseen.setText(UIHelper.lastseen(getApplicationContext(), contact.isActive(), contact.getLastseen()));
|
|
|
|
} else {
|
|
|
|
lastseen.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-16 17:14:20 +00:00
|
|
|
if (contact.getPresences().size() > 1) {
|
2016-02-24 15:53:19 +00:00
|
|
|
contactJidTv.setText(contact.getDisplayJid() + " ("
|
2014-07-20 01:14:47 +00:00
|
|
|
+ contact.getPresences().size() + ")");
|
2014-04-16 17:14:20 +00:00
|
|
|
} else {
|
2016-02-24 15:53:19 +00:00
|
|
|
contactJidTv.setText(contact.getDisplayJid());
|
2014-04-16 17:14:20 +00:00
|
|
|
}
|
2015-08-03 20:58:17 +00:00
|
|
|
String account;
|
|
|
|
if (Config.DOMAIN_LOCK != null) {
|
|
|
|
account = contact.getAccount().getJid().getLocalpart();
|
|
|
|
} else {
|
|
|
|
account = contact.getAccount().getJid().toBareJid().toString();
|
|
|
|
}
|
|
|
|
accountJidTv.setText(getString(R.string.using_account, account));
|
2015-06-03 12:05:54 +00:00
|
|
|
badge.setImageBitmap(avatarService().get(contact, getPixel(72)));
|
|
|
|
badge.setOnClickListener(this.onBadgeClick);
|
2014-03-07 19:36:04 +00:00
|
|
|
|
2014-03-06 19:00:46 +00:00
|
|
|
keys.removeAllViews();
|
2014-10-13 10:36:41 +00:00
|
|
|
boolean hasKeys = false;
|
2014-03-06 19:00:46 +00:00
|
|
|
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
2016-05-25 20:12:13 +00:00
|
|
|
if (Config.supportOtr()) {
|
|
|
|
for (final String otrFingerprint : contact.getOtrFingerprints()) {
|
|
|
|
hasKeys = true;
|
|
|
|
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 removeButton = (ImageButton) view
|
|
|
|
.findViewById(R.id.button_remove);
|
|
|
|
removeButton.setVisibility(View.VISIBLE);
|
|
|
|
key.setText(CryptoHelper.prettifyFingerprint(otrFingerprint));
|
2016-06-16 10:12:24 +00:00
|
|
|
if (otrFingerprint != null && otrFingerprint.equals(messageFingerprint)) {
|
|
|
|
keyType.setText(R.string.otr_fingerprint_selected_message);
|
|
|
|
keyType.setTextColor(getResources().getColor(R.color.accent));
|
|
|
|
} else {
|
|
|
|
keyType.setText(R.string.otr_fingerprint);
|
|
|
|
}
|
2016-05-25 20:12:13 +00:00
|
|
|
keys.addView(view);
|
|
|
|
removeButton.setOnClickListener(new OnClickListener() {
|
2014-09-08 21:58:37 +00:00
|
|
|
|
2016-05-25 20:12:13 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
confirmToDeleteFingerprint(otrFingerprint);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-03-06 19:00:46 +00:00
|
|
|
}
|
2016-05-25 20:12:13 +00:00
|
|
|
if (Config.supportOmemo()) {
|
|
|
|
for (final String fingerprint : contact.getAccount().getAxolotlService().getFingerprintsForContact(contact)) {
|
|
|
|
boolean highlight = fingerprint.equals(messageFingerprint);
|
|
|
|
hasKeys |= addFingerprintRow(keys, contact.getAccount(), fingerprint, highlight, new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
onOmemoKeyClicked(contact.getAccount(), fingerprint);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-06-25 15:01:42 +00:00
|
|
|
}
|
2016-05-25 20:12:13 +00:00
|
|
|
if (Config.supportOpenPgp() && contact.getPgpKeyId() != 0) {
|
2014-10-13 10:36:41 +00:00
|
|
|
hasKeys = true;
|
2014-10-26 17:54:10 +00:00
|
|
|
View view = inflater.inflate(R.layout.contact_key, keys, false);
|
2014-03-06 19:00:46 +00:00
|
|
|
TextView key = (TextView) view.findViewById(R.id.key);
|
2014-03-07 19:36:04 +00:00
|
|
|
TextView keyType = (TextView) view.findViewById(R.id.key_type);
|
2016-06-16 10:12:24 +00:00
|
|
|
keyType.setText(R.string.openpgp_key_id);
|
|
|
|
if ("pgp".equals(messageFingerprint)) {
|
|
|
|
keyType.setTextColor(getResources().getColor(R.color.accent));
|
|
|
|
}
|
2014-05-09 18:47:03 +00:00
|
|
|
key.setText(OpenPgpUtils.convertKeyIdToHex(contact.getPgpKeyId()));
|
|
|
|
view.setOnClickListener(new OnClickListener() {
|
2014-07-20 01:14:47 +00:00
|
|
|
|
2014-05-09 18:47:03 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2014-10-08 14:37:43 +00:00
|
|
|
PgpEngine pgp = ContactDetailsActivity.this.xmppConnectionService
|
2014-12-21 20:43:58 +00:00
|
|
|
.getPgpEngine();
|
2014-07-20 01:14:47 +00:00
|
|
|
if (pgp != null) {
|
2014-05-09 18:47:03 +00:00
|
|
|
PendingIntent intent = pgp.getIntentForKey(contact);
|
2014-07-20 01:14:47 +00:00
|
|
|
if (intent != null) {
|
2014-05-09 18:47:03 +00:00
|
|
|
try {
|
2014-07-20 01:14:47 +00:00
|
|
|
startIntentSenderForResult(
|
|
|
|
intent.getIntentSender(), 0, null, 0,
|
|
|
|
0, 0);
|
2014-05-09 18:47:03 +00:00
|
|
|
} catch (SendIntentException e) {
|
2014-07-20 01:14:47 +00:00
|
|
|
|
2014-05-09 18:47:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-03-06 19:00:46 +00:00
|
|
|
keys.addView(view);
|
|
|
|
}
|
2014-10-13 10:36:41 +00:00
|
|
|
if (hasKeys) {
|
|
|
|
keys.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
keys.setVisibility(View.GONE);
|
|
|
|
}
|
2014-11-18 13:24:06 +00:00
|
|
|
|
2016-04-22 19:25:06 +00:00
|
|
|
List<ListItem.Tag> tagList = contact.getTags(this);
|
2014-11-18 13:24:06 +00:00
|
|
|
if (tagList.size() == 0 || !this.showDynamicTags) {
|
|
|
|
tags.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
tags.setVisibility(View.VISIBLE);
|
|
|
|
tags.removeAllViewsInLayout();
|
2014-12-21 20:43:58 +00:00
|
|
|
for(final ListItem.Tag tag : tagList) {
|
|
|
|
final TextView tv = (TextView) inflater.inflate(R.layout.list_item_tag,tags,false);
|
2014-11-18 13:24:06 +00:00
|
|
|
tv.setText(tag.getName());
|
|
|
|
tv.setBackgroundColor(tag.getColor());
|
|
|
|
tags.addView(tv);
|
|
|
|
}
|
|
|
|
}
|
2014-03-05 14:41:14 +00:00
|
|
|
}
|
2014-09-08 21:58:37 +00:00
|
|
|
|
2015-12-23 18:18:53 +00:00
|
|
|
private void onOmemoKeyClicked(Account account, String fingerprint) {
|
|
|
|
final XmppAxolotlSession.Trust trust = account.getAxolotlService().getFingerprintTrust(fingerprint);
|
2016-03-20 16:24:15 +00:00
|
|
|
if (Config.X509_VERIFICATION && trust != null && trust == XmppAxolotlSession.Trust.TRUSTED_X509) {
|
2015-12-23 18:18:53 +00:00
|
|
|
X509Certificate x509Certificate = account.getAxolotlService().getFingerprintCertificate(fingerprint);
|
|
|
|
if (x509Certificate != null) {
|
|
|
|
showCertificateInformationDialog(CryptoHelper.extractCertificateInformation(x509Certificate));
|
2015-12-23 21:30:14 +00:00
|
|
|
} else {
|
|
|
|
Toast.makeText(this,R.string.certificate_not_found, Toast.LENGTH_SHORT).show();
|
2015-12-23 18:18:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showCertificateInformationDialog(Bundle bundle) {
|
|
|
|
View view = getLayoutInflater().inflate(R.layout.certificate_information, null);
|
|
|
|
final String not_available = getString(R.string.certicate_info_not_available);
|
|
|
|
TextView subject_cn = (TextView) view.findViewById(R.id.subject_cn);
|
|
|
|
TextView subject_o = (TextView) view.findViewById(R.id.subject_o);
|
|
|
|
TextView issuer_cn = (TextView) view.findViewById(R.id.issuer_cn);
|
|
|
|
TextView issuer_o = (TextView) view.findViewById(R.id.issuer_o);
|
|
|
|
TextView sha1 = (TextView) view.findViewById(R.id.sha1);
|
|
|
|
|
|
|
|
subject_cn.setText(bundle.getString("subject_cn", not_available));
|
|
|
|
subject_o.setText(bundle.getString("subject_o", not_available));
|
|
|
|
issuer_cn.setText(bundle.getString("issuer_cn", not_available));
|
|
|
|
issuer_o.setText(bundle.getString("issuer_o", not_available));
|
|
|
|
sha1.setText(bundle.getString("sha1", not_available));
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setTitle(R.string.certificate_information);
|
|
|
|
builder.setView(view);
|
|
|
|
builder.setPositiveButton(R.string.ok, null);
|
|
|
|
builder.create().show();
|
|
|
|
}
|
|
|
|
|
2014-09-07 21:08:40 +00:00
|
|
|
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);
|
2014-09-08 21:58:37 +00:00
|
|
|
builder.setPositiveButton(R.string.delete,
|
|
|
|
new android.content.DialogInterface.OnClickListener() {
|
2014-09-07 21:08:40 +00:00
|
|
|
|
2014-09-08 21:58:37 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
if (contact.deleteOtrFingerprint(fingerprint)) {
|
|
|
|
populateView();
|
2015-01-02 00:21:14 +00:00
|
|
|
xmppConnectionService.syncRosterToDisk(contact.getAccount());
|
2014-09-08 21:58:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2014-09-07 21:08:40 +00:00
|
|
|
builder.create().show();
|
|
|
|
}
|
2014-03-05 14:41:14 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackendConnected() {
|
2014-07-20 01:14:47 +00:00
|
|
|
if ((accountJid != null) && (contactJid != null)) {
|
|
|
|
Account account = xmppConnectionService
|
2014-12-21 20:43:58 +00:00
|
|
|
.findAccountByJid(accountJid);
|
2014-07-20 01:14:47 +00:00
|
|
|
if (account == null) {
|
2014-05-19 13:15:09 +00:00
|
|
|
return;
|
2014-03-05 14:41:14 +00:00
|
|
|
}
|
2014-05-19 13:15:09 +00:00
|
|
|
this.contact = account.getRoster().getContact(contactJid);
|
|
|
|
populateView();
|
2014-03-05 14:41:14 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-21 12:18:16 +00:00
|
|
|
|
|
|
|
@Override
|
2015-10-17 12:09:26 +00:00
|
|
|
public void onKeyStatusUpdated(AxolotlService.FetchStatus report) {
|
2015-07-21 12:18:16 +00:00
|
|
|
refreshUi();
|
|
|
|
}
|
2014-03-05 14:41:14 +00:00
|
|
|
}
|