2014-03-05 14:41:14 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
|
|
|
import android.app.AlertDialog;
|
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-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;
|
2017-03-29 16:30:28 +00:00
|
|
|
import android.support.v4.content.ContextCompat;
|
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;
|
|
|
|
|
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;
|
2015-10-17 12:09:26 +00:00
|
|
|
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
|
2016-12-30 12:17:45 +00:00
|
|
|
import eu.siacs.conversations.crypto.axolotl.FingerprintStatus;
|
2016-11-18 20:49:52 +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;
|
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;
|
2016-11-28 14:11:44 +00:00
|
|
|
import eu.siacs.conversations.utils.XmppUri;
|
2017-03-20 16:58:58 +00:00
|
|
|
import eu.siacs.conversations.xml.Namespace;
|
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
|
|
|
|
2016-11-15 19:00:52 +00:00
|
|
|
public class ContactDetailsActivity extends OmemoActivity 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;
|
2016-12-30 12:17:45 +00:00
|
|
|
private Button mShowInactiveDevicesButton;
|
2014-11-11 16:39:28 +00:00
|
|
|
private QuickContactBadge badge;
|
2014-11-18 13:24:06 +00:00
|
|
|
private LinearLayout keys;
|
2017-01-12 19:50:53 +00:00
|
|
|
private LinearLayout keysWrapper;
|
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;
|
2016-12-30 12:17:45 +00:00
|
|
|
private boolean showInactiveOmemo = 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
|
2017-09-19 14:28:01 +00:00
|
|
|
protected String getShareableUri(boolean http) {
|
|
|
|
final String prefix = http ? "https://conversations.im/i/" : "xmpp:";
|
2014-11-11 16:39:28 +00:00
|
|
|
if (contact != null) {
|
2017-09-19 14:28:01 +00:00
|
|
|
return prefix+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);
|
2016-12-30 12:17:45 +00:00
|
|
|
showInactiveOmemo = savedInstanceState != null && savedInstanceState.getBoolean("show_inactive_omemo",false);
|
2014-03-05 14:41:14 +00:00
|
|
|
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);
|
2017-01-12 19:50:53 +00:00
|
|
|
keysWrapper = (LinearLayout) findViewById(R.id.keys_wrapper);
|
2016-08-26 14:34:42 +00:00
|
|
|
tags = (FlowLayout) findViewById(R.id.tags);
|
2016-12-30 12:17:45 +00:00
|
|
|
mShowInactiveDevicesButton = (Button) findViewById(R.id.show_inactive_devices);
|
2014-12-21 20:43:58 +00:00
|
|
|
if (getActionBar() != null) {
|
|
|
|
getActionBar().setHomeButtonEnabled(true);
|
|
|
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
}
|
2016-12-30 12:17:45 +00:00
|
|
|
mShowInactiveDevicesButton.setOnClickListener(new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
showInactiveOmemo = !showInactiveOmemo;
|
|
|
|
populateView();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState(final Bundle savedInstanceState) {
|
|
|
|
savedInstanceState.putBoolean("show_inactive_omemo",showInactiveOmemo);
|
|
|
|
super.onSaveInstanceState(savedInstanceState);
|
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();
|
2016-09-18 18:26:47 +00:00
|
|
|
final int theme = findTheme();
|
|
|
|
if (this.mTheme != theme) {
|
|
|
|
recreate();
|
|
|
|
} else {
|
|
|
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
2017-06-05 12:57:09 +00:00
|
|
|
this.showDynamicTags = preferences.getBoolean(SettingsActivity.SHOW_DYNAMIC_TAGS, false);
|
2016-09-18 18:26:47 +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;
|
2017-09-19 14:28:01 +00:00
|
|
|
case R.id.action_share_http:
|
|
|
|
shareLink(true);
|
|
|
|
break;
|
|
|
|
case R.id.action_share_uri:
|
|
|
|
shareLink(false);
|
2016-06-24 13:16:01 +00:00
|
|
|
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:
|
2017-03-06 15:53:54 +00:00
|
|
|
BlockContactDialog.show(this, contact);
|
2015-01-16 00:08:12 +00:00
|
|
|
break;
|
|
|
|
case R.id.action_unblock:
|
2017-03-06 15:53:54 +00:00
|
|
|
BlockContactDialog.show(this, contact);
|
2015-01-16 00:08:12 +00:00
|
|
|
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 {
|
2017-03-20 16:58:58 +00:00
|
|
|
if (showLastSeen
|
|
|
|
&& contact.getLastseen() > 0
|
|
|
|
&& contact.getPresences().allOrNonSupport(Namespace.IDLE)) {
|
2016-06-04 14:16:14 +00:00
|
|
|
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));
|
2017-05-04 11:02:46 +00:00
|
|
|
if (otrFingerprint != null && otrFingerprint.equalsIgnoreCase(messageFingerprint)) {
|
2016-06-16 10:12:24 +00:00
|
|
|
keyType.setText(R.string.otr_fingerprint_selected_message);
|
2017-03-29 16:30:28 +00:00
|
|
|
keyType.setTextColor(ContextCompat.getColor(this, R.color.accent));
|
2016-06-16 10:12:24 +00:00
|
|
|
} 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()) {
|
2016-12-30 12:17:45 +00:00
|
|
|
boolean skippedInactive = false;
|
|
|
|
boolean showsInactive = false;
|
2016-11-18 20:49:52 +00:00
|
|
|
for (final XmppAxolotlSession session : contact.getAccount().getAxolotlService().findSessionsForContact(contact)) {
|
2016-12-30 12:17:45 +00:00
|
|
|
final FingerprintStatus trust = session.getTrust();
|
2017-03-01 11:50:46 +00:00
|
|
|
hasKeys |= !trust.isCompromised();
|
2016-12-30 12:17:45 +00:00
|
|
|
if (!trust.isActive()) {
|
|
|
|
if (showInactiveOmemo) {
|
|
|
|
showsInactive = true;
|
|
|
|
} else {
|
|
|
|
skippedInactive = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!trust.isCompromised()) {
|
2016-11-18 20:49:52 +00:00
|
|
|
boolean highlight = session.getFingerprint().equals(messageFingerprint);
|
|
|
|
addFingerprintRow(keys, session, highlight);
|
|
|
|
}
|
2016-05-25 20:12:13 +00:00
|
|
|
}
|
2016-12-30 12:17:45 +00:00
|
|
|
if (showsInactive || skippedInactive) {
|
|
|
|
mShowInactiveDevicesButton.setText(showsInactive ? R.string.hide_inactive_devices : R.string.show_inactive_devices);
|
|
|
|
mShowInactiveDevicesButton.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
mShowInactiveDevicesButton.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mShowInactiveDevicesButton.setVisibility(View.GONE);
|
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)) {
|
2017-03-29 16:30:28 +00:00
|
|
|
keyType.setTextColor(ContextCompat.getColor(this, R.color.accent));
|
2016-06-16 10:12:24 +00:00
|
|
|
}
|
2014-05-09 18:47:03 +00:00
|
|
|
key.setText(OpenPgpUtils.convertKeyIdToHex(contact.getPgpKeyId()));
|
2017-04-25 13:23:01 +00:00
|
|
|
final OnClickListener openKey = new OnClickListener() {
|
2014-07-20 01:14:47 +00:00
|
|
|
|
2014-05-09 18:47:03 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-05-04 11:02:46 +00:00
|
|
|
launchOpenKeyChain(contact.getPgpKeyId());
|
2014-05-09 18:47:03 +00:00
|
|
|
}
|
2017-04-25 13:23:01 +00:00
|
|
|
};
|
|
|
|
view.setOnClickListener(openKey);
|
|
|
|
key.setOnClickListener(openKey);
|
|
|
|
keyType.setOnClickListener(openKey);
|
2014-03-06 19:00:46 +00:00
|
|
|
keys.addView(view);
|
|
|
|
}
|
2017-01-12 19:50:53 +00:00
|
|
|
keysWrapper.setVisibility(hasKeys ? View.VISIBLE : 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
|
|
|
|
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
|
|
|
|
|
|
|
public void onBackendConnected() {
|
2016-11-28 14:11:44 +00:00
|
|
|
if (accountJid != null && contactJid != null) {
|
|
|
|
Account account = xmppConnectionService.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);
|
2016-11-28 14:11:44 +00:00
|
|
|
if (mPendingFingerprintVerificationUri != null) {
|
|
|
|
processFingerprintVerification(mPendingFingerprintVerificationUri);
|
|
|
|
mPendingFingerprintVerificationUri = null;
|
|
|
|
}
|
2014-05-19 13:15:09 +00:00
|
|
|
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();
|
|
|
|
}
|
2016-11-28 14:11:44 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void processFingerprintVerification(XmppUri uri) {
|
|
|
|
if (contact != null && contact.getJid().toBareJid().equals(uri.getJid()) && uri.hasFingerprints()) {
|
|
|
|
if (xmppConnectionService.verifyFingerprints(contact,uri.getFingerprints())) {
|
|
|
|
Toast.makeText(this,R.string.verified_fingerprints,Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Toast.makeText(this,R.string.invalid_barcode,Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
2014-03-05 14:41:14 +00:00
|
|
|
}
|