2014-03-05 14:41:14 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
2020-07-09 18:03:02 +00:00
|
|
|
import android.Manifest;
|
2018-07-22 20:42:05 +00:00
|
|
|
import android.content.ActivityNotFoundException;
|
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;
|
2020-07-09 18:03:02 +00:00
|
|
|
import android.content.pm.PackageManager;
|
2021-01-18 17:26:46 +00:00
|
|
|
import androidx.databinding.DataBindingUtil;
|
2014-03-05 14:41:14 +00:00
|
|
|
import android.net.Uri;
|
2020-07-09 18:03:02 +00:00
|
|
|
import android.os.Build;
|
2014-03-05 14:41:14 +00:00
|
|
|
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;
|
2021-01-18 17:26:46 +00:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import androidx.appcompat.widget.Toolbar;
|
2019-09-22 09:39:34 +00:00
|
|
|
import android.text.Spannable;
|
|
|
|
import android.text.SpannableString;
|
|
|
|
import android.text.style.RelativeSizeSpan;
|
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;
|
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-03-05 14:41:14 +00:00
|
|
|
import android.widget.TextView;
|
2015-12-23 21:30:14 +00:00
|
|
|
import android.widget.Toast;
|
2014-11-11 16:39:28 +00:00
|
|
|
|
|
|
|
import org.openintents.openpgp.util.OpenPgpUtils;
|
|
|
|
|
2018-09-16 12:08:56 +00:00
|
|
|
import java.util.Collection;
|
2018-09-15 17:38:45 +00:00
|
|
|
import java.util.Collections;
|
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;
|
2018-02-17 17:58:56 +00:00
|
|
|
import eu.siacs.conversations.databinding.ActivityContactDetailsBinding;
|
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;
|
2018-09-15 17:38:45 +00:00
|
|
|
import eu.siacs.conversations.ui.adapter.MediaAdapter;
|
|
|
|
import eu.siacs.conversations.ui.interfaces.OnMediaLoaded;
|
|
|
|
import eu.siacs.conversations.ui.util.Attachment;
|
2019-01-25 09:07:02 +00:00
|
|
|
import eu.siacs.conversations.ui.util.AvatarWorkerTask;
|
2018-09-15 17:38:45 +00:00
|
|
|
import eu.siacs.conversations.ui.util.GridManager;
|
2018-10-06 15:03:12 +00:00
|
|
|
import eu.siacs.conversations.ui.util.JidDialog;
|
2018-03-18 22:32:30 +00:00
|
|
|
import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
|
2018-10-17 20:50:34 +00:00
|
|
|
import eu.siacs.conversations.utils.AccountUtils;
|
2018-09-17 19:24:25 +00:00
|
|
|
import eu.siacs.conversations.utils.Compatibility;
|
2019-09-22 09:39:34 +00:00
|
|
|
import eu.siacs.conversations.utils.Emoticons;
|
2018-03-08 21:02:19 +00:00
|
|
|
import eu.siacs.conversations.utils.IrregularUnicodeDetector;
|
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;
|
2020-07-09 18:03:02 +00:00
|
|
|
import eu.siacs.conversations.xmpp.Jid;
|
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-03-05 14:41:14 +00:00
|
|
|
|
2018-09-15 17:38:45 +00:00
|
|
|
public class ContactDetailsActivity extends OmemoActivity implements OnAccountUpdate, OnRosterUpdate, OnUpdateBlocklist, OnKeyStatusUpdated, OnMediaLoaded {
|
2018-07-22 20:42:05 +00:00
|
|
|
public static final String ACTION_VIEW_CONTACT = "view_contact";
|
2020-07-09 18:03:02 +00:00
|
|
|
private final int REQUEST_SYNC_CONTACTS = 0x28cf;
|
2018-07-22 20:42:05 +00:00
|
|
|
ActivityContactDetailsBinding binding;
|
2018-09-15 17:38:45 +00:00
|
|
|
private MediaAdapter mMediaAdapter;
|
|
|
|
|
2018-07-22 20:42:05 +00:00
|
|
|
private Contact contact;
|
|
|
|
private DialogInterface.OnClickListener removeFromRoster = new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
xmppConnectionService.deleteContactOnServer(contact);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
private OnCheckedChangeListener mOnSendCheckedChange = new OnCheckedChangeListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
|
if (isChecked) {
|
|
|
|
if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
|
2018-11-18 09:34:14 +00:00
|
|
|
xmppConnectionService.stopPresenceUpdatesTo(contact);
|
2018-07-22 20:42:05 +00:00
|
|
|
} else {
|
|
|
|
contact.setOption(Contact.Options.PREEMPTIVE_GRANT);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
|
|
|
|
xmppConnectionService.sendPresencePacket(contact.getAccount(), xmppConnectionService.getPresenceGenerator().stopPresenceUpdatesTo(contact));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
private OnCheckedChangeListener mOnReceiveCheckedChange = new OnCheckedChangeListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
|
if (isChecked) {
|
|
|
|
xmppConnectionService.sendPresencePacket(contact.getAccount(), xmppConnectionService.getPresenceGenerator().requestPresenceUpdatesFrom(contact));
|
|
|
|
} else {
|
|
|
|
xmppConnectionService.sendPresencePacket(contact.getAccount(), xmppConnectionService.getPresenceGenerator().stopPresenceUpdatesFrom(contact));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
private Jid accountJid;
|
|
|
|
private Jid contactJid;
|
|
|
|
private boolean showDynamicTags = false;
|
|
|
|
private boolean showLastSeen = false;
|
|
|
|
private boolean showInactiveOmemo = false;
|
|
|
|
private String messageFingerprint;
|
|
|
|
|
2020-07-09 18:03:02 +00:00
|
|
|
private void checkContactPermissionAndShowAddDialog() {
|
|
|
|
if (hasContactsPermission()) {
|
|
|
|
showAddToPhoneBookDialog();
|
|
|
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_SYNC_CONTACTS);
|
|
|
|
}
|
|
|
|
}
|
2018-07-22 20:42:05 +00:00
|
|
|
|
2020-07-09 18:03:02 +00:00
|
|
|
private boolean hasContactsPermission() {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
return checkSelfPermission(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showAddToPhoneBookDialog() {
|
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setTitle(getString(R.string.action_add_phone_book));
|
|
|
|
builder.setMessage(getString(R.string.add_phone_book_text, contact.getJid().toEscapedString()));
|
|
|
|
builder.setNegativeButton(getString(R.string.cancel), null);
|
|
|
|
builder.setPositiveButton(getString(R.string.add), (dialog, which) -> {
|
|
|
|
final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
|
2018-07-22 20:42:05 +00:00
|
|
|
intent.setType(Contacts.CONTENT_ITEM_TYPE);
|
|
|
|
intent.putExtra(Intents.Insert.IM_HANDLE, contact.getJid().toEscapedString());
|
|
|
|
intent.putExtra(Intents.Insert.IM_PROTOCOL, CommonDataKinds.Im.PROTOCOL_JABBER);
|
|
|
|
intent.putExtra("finishActivityOnSaveCompleted", true);
|
|
|
|
try {
|
2020-07-09 18:03:02 +00:00
|
|
|
startActivityForResult(intent, 0);
|
2018-07-22 20:42:05 +00:00
|
|
|
} catch (ActivityNotFoundException e) {
|
|
|
|
Toast.makeText(ContactDetailsActivity.this, R.string.no_application_found_to_view_contact, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
2020-07-09 18:03:02 +00:00
|
|
|
});
|
|
|
|
builder.create().show();
|
|
|
|
}
|
2018-07-22 20:42:05 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRosterUpdate() {
|
|
|
|
refreshUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAccountUpdate() {
|
|
|
|
refreshUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void OnUpdateBlocklist(final Status status) {
|
|
|
|
refreshUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void refreshUiReal() {
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
populateView();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String getShareableUri(boolean http) {
|
|
|
|
if (http) {
|
2018-09-18 15:15:52 +00:00
|
|
|
return "https://conversations.im/i/" + XmppUri.lameUrlEncode(contact.getJid().asBareJid().toEscapedString());
|
2018-07-22 20:42:05 +00:00
|
|
|
} else {
|
|
|
|
return "xmpp:" + contact.getJid().asBareJid().toEscapedString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(final Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
showInactiveOmemo = savedInstanceState != null && savedInstanceState.getBoolean("show_inactive_omemo", false);
|
|
|
|
if (getIntent().getAction().equals(ACTION_VIEW_CONTACT)) {
|
|
|
|
try {
|
2020-05-20 18:14:13 +00:00
|
|
|
this.accountJid = Jid.ofEscaped(getIntent().getExtras().getString(EXTRA_ACCOUNT));
|
2018-07-22 20:42:05 +00:00
|
|
|
} catch (final IllegalArgumentException ignored) {
|
|
|
|
}
|
|
|
|
try {
|
2020-05-20 18:14:13 +00:00
|
|
|
this.contactJid = Jid.ofEscaped(getIntent().getExtras().getString("contact"));
|
2018-07-22 20:42:05 +00:00
|
|
|
} catch (final IllegalArgumentException ignored) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.messageFingerprint = getIntent().getStringExtra("fingerprint");
|
|
|
|
this.binding = DataBindingUtil.setContentView(this, R.layout.activity_contact_details);
|
|
|
|
|
|
|
|
setSupportActionBar((Toolbar) binding.toolbar);
|
|
|
|
configureActionBar(getSupportActionBar());
|
|
|
|
binding.showInactiveDevices.setOnClickListener(v -> {
|
|
|
|
showInactiveOmemo = !showInactiveOmemo;
|
|
|
|
populateView();
|
|
|
|
});
|
|
|
|
binding.addContactButton.setOnClickListener(v -> showAddToRosterDialog(contact));
|
2018-09-15 17:38:45 +00:00
|
|
|
|
2020-04-20 11:41:50 +00:00
|
|
|
mMediaAdapter = new MediaAdapter(this, R.dimen.media_size);
|
2018-09-15 17:38:45 +00:00
|
|
|
this.binding.media.setAdapter(mMediaAdapter);
|
|
|
|
GridManager.setupLayoutManager(this, this.binding.media, R.dimen.media_size);
|
2018-07-22 20:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState(final Bundle savedInstanceState) {
|
|
|
|
savedInstanceState.putBoolean("show_inactive_omemo", showInactiveOmemo);
|
|
|
|
super.onSaveInstanceState(savedInstanceState);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStart() {
|
|
|
|
super.onStart();
|
|
|
|
final int theme = findTheme();
|
|
|
|
if (this.mTheme != theme) {
|
|
|
|
recreate();
|
|
|
|
} else {
|
|
|
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
this.showDynamicTags = preferences.getBoolean(SettingsActivity.SHOW_DYNAMIC_TAGS, false);
|
|
|
|
this.showLastSeen = preferences.getBoolean("last_activity", false);
|
|
|
|
}
|
2018-09-17 19:24:25 +00:00
|
|
|
binding.mediaWrapper.setVisibility(Compatibility.hasStoragePermission(this) ? View.VISIBLE : View.GONE);
|
2018-09-15 17:38:45 +00:00
|
|
|
mMediaAdapter.setAttachments(Collections.emptyList());
|
2018-07-22 20:42:05 +00:00
|
|
|
}
|
|
|
|
|
2020-07-09 18:03:02 +00:00
|
|
|
@Override
|
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
|
|
|
|
if (grantResults.length > 0)
|
|
|
|
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
|
|
if (requestCode == REQUEST_SYNC_CONTACTS && xmppConnectionServiceBound) {
|
|
|
|
showAddToPhoneBookDialog();
|
|
|
|
xmppConnectionService.loadPhoneContacts();
|
|
|
|
xmppConnectionService.startContactObserver();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-22 20:42:05 +00:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(final MenuItem menuItem) {
|
|
|
|
if (MenuDoubleTabUtil.shouldIgnoreTap()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setNegativeButton(getString(R.string.cancel), null);
|
|
|
|
switch (menuItem.getItemId()) {
|
|
|
|
case android.R.id.home:
|
|
|
|
finish();
|
|
|
|
break;
|
|
|
|
case R.id.action_share_http:
|
|
|
|
shareLink(true);
|
|
|
|
break;
|
|
|
|
case R.id.action_share_uri:
|
|
|
|
shareLink(false);
|
|
|
|
break;
|
|
|
|
case R.id.action_delete_contact:
|
|
|
|
builder.setTitle(getString(R.string.action_delete_contact))
|
2018-10-06 15:03:12 +00:00
|
|
|
.setMessage(JidDialog.style(this, R.string.remove_contact_text, contact.getJid().toEscapedString()))
|
2018-07-22 20:42:05 +00:00
|
|
|
.setPositiveButton(getString(R.string.delete),
|
|
|
|
removeFromRoster).create().show();
|
|
|
|
break;
|
|
|
|
case R.id.action_edit_contact:
|
|
|
|
Uri systemAccount = contact.getSystemAccount();
|
|
|
|
if (systemAccount == null) {
|
|
|
|
quickEdit(contact.getServerName(), R.string.contact_name, value -> {
|
|
|
|
contact.setServerName(value);
|
|
|
|
ContactDetailsActivity.this.xmppConnectionService.pushContactToServer(contact);
|
|
|
|
populateView();
|
|
|
|
return null;
|
|
|
|
}, true);
|
|
|
|
} else {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_EDIT);
|
|
|
|
intent.setDataAndType(systemAccount, Contacts.CONTENT_ITEM_TYPE);
|
|
|
|
intent.putExtra("finishActivityOnSaveCompleted", true);
|
|
|
|
try {
|
|
|
|
startActivity(intent);
|
|
|
|
} catch (ActivityNotFoundException e) {
|
|
|
|
Toast.makeText(ContactDetailsActivity.this, R.string.no_application_found_to_view_contact, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R.id.action_block:
|
|
|
|
BlockContactDialog.show(this, contact);
|
|
|
|
break;
|
|
|
|
case R.id.action_unblock:
|
|
|
|
BlockContactDialog.show(this, contact);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(menuItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(final Menu menu) {
|
|
|
|
getMenuInflater().inflate(R.menu.contact_details, menu);
|
2018-10-17 20:50:34 +00:00
|
|
|
AccountUtils.showHideMenuItems(menu);
|
2018-07-22 20:42:05 +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);
|
|
|
|
if (contact == null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
final XmppConnection connection = contact.getAccount().getXmppConnection();
|
|
|
|
if (connection != null && connection.getFeatures().blocking()) {
|
|
|
|
if (this.contact.isBlocked()) {
|
|
|
|
block.setVisible(false);
|
|
|
|
} else {
|
|
|
|
unblock.setVisible(false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unblock.setVisible(false);
|
|
|
|
block.setVisible(false);
|
|
|
|
}
|
|
|
|
if (!contact.showInRoster()) {
|
|
|
|
edit.setVisible(false);
|
|
|
|
delete.setVisible(false);
|
|
|
|
}
|
|
|
|
return super.onCreateOptionsMenu(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void populateView() {
|
|
|
|
if (contact == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
setTitle(contact.getDisplayName());
|
|
|
|
if (contact.showInRoster()) {
|
|
|
|
binding.detailsSendPresence.setVisibility(View.VISIBLE);
|
|
|
|
binding.detailsReceivePresence.setVisibility(View.VISIBLE);
|
|
|
|
binding.addContactButton.setVisibility(View.GONE);
|
|
|
|
binding.detailsSendPresence.setOnCheckedChangeListener(null);
|
|
|
|
binding.detailsReceivePresence.setOnCheckedChangeListener(null);
|
|
|
|
|
|
|
|
List<String> statusMessages = contact.getPresences().getStatusMessages();
|
|
|
|
if (statusMessages.size() == 0) {
|
|
|
|
binding.statusMessage.setVisibility(View.GONE);
|
2019-09-22 09:39:34 +00:00
|
|
|
} else if (statusMessages.size() == 1) {
|
|
|
|
final String message = statusMessages.get(0);
|
|
|
|
binding.statusMessage.setVisibility(View.VISIBLE);
|
|
|
|
final Spannable span = new SpannableString(message);
|
|
|
|
if (Emoticons.isOnlyEmoji(message)) {
|
|
|
|
span.setSpan(new RelativeSizeSpan(2.0f), 0, message.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
}
|
|
|
|
binding.statusMessage.setText(span);
|
2018-07-22 20:42:05 +00:00
|
|
|
} else {
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
binding.statusMessage.setVisibility(View.VISIBLE);
|
|
|
|
int s = statusMessages.size();
|
|
|
|
for (int i = 0; i < s; ++i) {
|
|
|
|
builder.append(statusMessages.get(i));
|
|
|
|
if (i < s - 1) {
|
|
|
|
builder.append("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
binding.statusMessage.setText(builder);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contact.getOption(Contact.Options.FROM)) {
|
|
|
|
binding.detailsSendPresence.setText(R.string.send_presence_updates);
|
|
|
|
binding.detailsSendPresence.setChecked(true);
|
|
|
|
} else if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
|
|
|
|
binding.detailsSendPresence.setChecked(false);
|
|
|
|
binding.detailsSendPresence.setText(R.string.send_presence_updates);
|
|
|
|
} else {
|
|
|
|
binding.detailsSendPresence.setText(R.string.preemptively_grant);
|
|
|
|
if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
|
|
|
|
binding.detailsSendPresence.setChecked(true);
|
|
|
|
} else {
|
|
|
|
binding.detailsSendPresence.setChecked(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (contact.getOption(Contact.Options.TO)) {
|
|
|
|
binding.detailsReceivePresence.setText(R.string.receive_presence_updates);
|
|
|
|
binding.detailsReceivePresence.setChecked(true);
|
|
|
|
} else {
|
|
|
|
binding.detailsReceivePresence.setText(R.string.ask_for_presence_updates);
|
|
|
|
if (contact.getOption(Contact.Options.ASKING)) {
|
|
|
|
binding.detailsReceivePresence.setChecked(true);
|
|
|
|
} else {
|
|
|
|
binding.detailsReceivePresence.setChecked(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (contact.getAccount().isOnlineAndConnected()) {
|
|
|
|
binding.detailsReceivePresence.setEnabled(true);
|
|
|
|
binding.detailsSendPresence.setEnabled(true);
|
|
|
|
} else {
|
|
|
|
binding.detailsReceivePresence.setEnabled(false);
|
|
|
|
binding.detailsSendPresence.setEnabled(false);
|
|
|
|
}
|
|
|
|
binding.detailsSendPresence.setOnCheckedChangeListener(this.mOnSendCheckedChange);
|
|
|
|
binding.detailsReceivePresence.setOnCheckedChangeListener(this.mOnReceiveCheckedChange);
|
|
|
|
} else {
|
|
|
|
binding.addContactButton.setVisibility(View.VISIBLE);
|
|
|
|
binding.detailsSendPresence.setVisibility(View.GONE);
|
|
|
|
binding.detailsReceivePresence.setVisibility(View.GONE);
|
|
|
|
binding.statusMessage.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contact.isBlocked() && !this.showDynamicTags) {
|
|
|
|
binding.detailsLastseen.setVisibility(View.VISIBLE);
|
|
|
|
binding.detailsLastseen.setText(R.string.contact_blocked);
|
|
|
|
} else {
|
|
|
|
if (showLastSeen
|
|
|
|
&& contact.getLastseen() > 0
|
|
|
|
&& contact.getPresences().allOrNonSupport(Namespace.IDLE)) {
|
|
|
|
binding.detailsLastseen.setVisibility(View.VISIBLE);
|
|
|
|
binding.detailsLastseen.setText(UIHelper.lastseen(getApplicationContext(), contact.isActive(), contact.getLastseen()));
|
|
|
|
} else {
|
|
|
|
binding.detailsLastseen.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
binding.detailsContactjid.setText(IrregularUnicodeDetector.style(this, contact.getJid()));
|
|
|
|
String account;
|
|
|
|
if (Config.DOMAIN_LOCK != null) {
|
2020-05-15 16:21:45 +00:00
|
|
|
account = contact.getAccount().getJid().getEscapedLocal();
|
2018-07-22 20:42:05 +00:00
|
|
|
} else {
|
2020-05-15 16:21:45 +00:00
|
|
|
account = contact.getAccount().getJid().asBareJid().toEscapedString();
|
2018-07-22 20:42:05 +00:00
|
|
|
}
|
|
|
|
binding.detailsAccount.setText(getString(R.string.using_account, account));
|
2020-04-20 11:41:50 +00:00
|
|
|
AvatarWorkerTask.loadAvatar(contact, binding.detailsContactBadge, R.dimen.avatar_on_details_screen_size);
|
2020-07-09 18:03:02 +00:00
|
|
|
binding.detailsContactBadge.setOnClickListener(this::onBadgeClick);
|
2018-07-22 20:42:05 +00:00
|
|
|
|
|
|
|
binding.detailsContactKeys.removeAllViews();
|
|
|
|
boolean hasKeys = false;
|
|
|
|
final LayoutInflater inflater = getLayoutInflater();
|
|
|
|
final AxolotlService axolotlService = contact.getAccount().getAxolotlService();
|
|
|
|
if (Config.supportOmemo() && axolotlService != null) {
|
2018-09-16 12:08:56 +00:00
|
|
|
final Collection<XmppAxolotlSession> sessions = axolotlService.findSessionsForContact(contact);
|
|
|
|
boolean anyActive = false;
|
2020-04-20 11:41:50 +00:00
|
|
|
for (XmppAxolotlSession session : sessions) {
|
2018-09-16 12:08:56 +00:00
|
|
|
anyActive = session.getTrust().isActive();
|
|
|
|
if (anyActive) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-07-22 20:42:05 +00:00
|
|
|
boolean skippedInactive = false;
|
|
|
|
boolean showsInactive = false;
|
2020-04-20 11:41:50 +00:00
|
|
|
for (final XmppAxolotlSession session : sessions) {
|
2018-07-22 20:42:05 +00:00
|
|
|
final FingerprintStatus trust = session.getTrust();
|
|
|
|
hasKeys |= !trust.isCompromised();
|
2018-09-16 12:08:56 +00:00
|
|
|
if (!trust.isActive() && anyActive) {
|
2018-07-22 20:42:05 +00:00
|
|
|
if (showInactiveOmemo) {
|
|
|
|
showsInactive = true;
|
|
|
|
} else {
|
|
|
|
skippedInactive = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!trust.isCompromised()) {
|
|
|
|
boolean highlight = session.getFingerprint().equals(messageFingerprint);
|
|
|
|
addFingerprintRow(binding.detailsContactKeys, session, highlight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (showsInactive || skippedInactive) {
|
|
|
|
binding.showInactiveDevices.setText(showsInactive ? R.string.hide_inactive_devices : R.string.show_inactive_devices);
|
|
|
|
binding.showInactiveDevices.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
binding.showInactiveDevices.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
binding.showInactiveDevices.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
binding.scanButton.setVisibility(hasKeys && isCameraFeatureAvailable() ? View.VISIBLE : View.GONE);
|
|
|
|
if (hasKeys) {
|
|
|
|
binding.scanButton.setOnClickListener((v) -> ScanActivity.scan(this));
|
|
|
|
}
|
|
|
|
if (Config.supportOpenPgp() && contact.getPgpKeyId() != 0) {
|
|
|
|
hasKeys = true;
|
|
|
|
View view = inflater.inflate(R.layout.contact_key, binding.detailsContactKeys, false);
|
|
|
|
TextView key = (TextView) view.findViewById(R.id.key);
|
|
|
|
TextView keyType = (TextView) view.findViewById(R.id.key_type);
|
|
|
|
keyType.setText(R.string.openpgp_key_id);
|
|
|
|
if ("pgp".equals(messageFingerprint)) {
|
|
|
|
keyType.setTextAppearance(this, R.style.TextAppearance_Conversations_Caption_Highlight);
|
|
|
|
}
|
|
|
|
key.setText(OpenPgpUtils.convertKeyIdToHex(contact.getPgpKeyId()));
|
|
|
|
final OnClickListener openKey = v -> launchOpenKeyChain(contact.getPgpKeyId());
|
|
|
|
view.setOnClickListener(openKey);
|
|
|
|
key.setOnClickListener(openKey);
|
|
|
|
keyType.setOnClickListener(openKey);
|
|
|
|
binding.detailsContactKeys.addView(view);
|
|
|
|
}
|
|
|
|
binding.keysWrapper.setVisibility(hasKeys ? View.VISIBLE : View.GONE);
|
|
|
|
|
|
|
|
List<ListItem.Tag> tagList = contact.getTags(this);
|
|
|
|
if (tagList.size() == 0 || !this.showDynamicTags) {
|
|
|
|
binding.tags.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
binding.tags.setVisibility(View.VISIBLE);
|
|
|
|
binding.tags.removeAllViewsInLayout();
|
|
|
|
for (final ListItem.Tag tag : tagList) {
|
|
|
|
final TextView tv = (TextView) inflater.inflate(R.layout.list_item_tag, binding.tags, false);
|
|
|
|
tv.setText(tag.getName());
|
|
|
|
tv.setBackgroundColor(tag.getColor());
|
|
|
|
binding.tags.addView(tv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-09 18:03:02 +00:00
|
|
|
private void onBadgeClick(View view) {
|
|
|
|
final Uri systemAccount = contact.getSystemAccount();
|
|
|
|
if (systemAccount == null) {
|
|
|
|
checkContactPermissionAndShowAddDialog();
|
|
|
|
} else {
|
|
|
|
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.setData(systemAccount);
|
|
|
|
try {
|
|
|
|
startActivity(intent);
|
|
|
|
} catch (final ActivityNotFoundException e) {
|
|
|
|
Toast.makeText(this, R.string.no_application_found_to_view_contact, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-22 20:42:05 +00:00
|
|
|
public void onBackendConnected() {
|
|
|
|
if (accountJid != null && contactJid != null) {
|
|
|
|
Account account = xmppConnectionService.findAccountByJid(accountJid);
|
|
|
|
if (account == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.contact = account.getRoster().getContact(contactJid);
|
|
|
|
if (mPendingFingerprintVerificationUri != null) {
|
|
|
|
processFingerprintVerification(mPendingFingerprintVerificationUri);
|
|
|
|
mPendingFingerprintVerificationUri = null;
|
|
|
|
}
|
2018-09-15 17:38:45 +00:00
|
|
|
|
2018-09-17 19:24:25 +00:00
|
|
|
if (Compatibility.hasStoragePermission(this)) {
|
|
|
|
final int limit = GridManager.getCurrentColumnCount(this.binding.media);
|
|
|
|
xmppConnectionService.getAttachments(account, contact.getJid().asBareJid(), limit, this);
|
|
|
|
this.binding.showMedia.setOnClickListener((v) -> MediaBrowserActivity.launch(this, contact));
|
|
|
|
}
|
2018-07-22 20:42:05 +00:00
|
|
|
populateView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onKeyStatusUpdated(AxolotlService.FetchStatus report) {
|
|
|
|
refreshUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void processFingerprintVerification(XmppUri uri) {
|
|
|
|
if (contact != null && contact.getJid().asBareJid().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();
|
|
|
|
}
|
|
|
|
}
|
2018-09-15 17:38:45 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onMediaLoaded(List<Attachment> attachments) {
|
|
|
|
runOnUiThread(() -> {
|
|
|
|
int limit = GridManager.getCurrentColumnCount(binding.media);
|
2020-04-20 11:41:50 +00:00
|
|
|
mMediaAdapter.setAttachments(attachments.subList(0, Math.min(limit, attachments.size())));
|
2018-09-15 17:38:45 +00:00
|
|
|
binding.mediaWrapper.setVisibility(attachments.size() > 0 ? View.VISIBLE : View.GONE);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2014-03-05 14:41:14 +00:00
|
|
|
}
|