1package eu.siacs.conversations.ui;
2
3import android.Manifest;
4import android.content.ActivityNotFoundException;
5import android.content.DialogInterface;
6import android.content.Intent;
7import android.content.SharedPreferences;
8import android.content.pm.PackageManager;
9import android.net.Uri;
10import android.os.Build;
11import android.os.Bundle;
12import android.preference.PreferenceManager;
13import android.provider.ContactsContract.CommonDataKinds;
14import android.provider.ContactsContract.Contacts;
15import android.provider.ContactsContract.Intents;
16import android.text.Spannable;
17import android.text.SpannableString;
18import android.text.style.RelativeSizeSpan;
19import android.view.LayoutInflater;
20import android.view.Menu;
21import android.view.MenuItem;
22import android.view.View;
23import android.view.View.OnClickListener;
24import android.widget.CompoundButton;
25import android.widget.CompoundButton.OnCheckedChangeListener;
26import android.widget.EditText;
27import android.widget.TextView;
28import android.widget.Toast;
29
30import androidx.annotation.NonNull;
31import androidx.appcompat.app.AlertDialog;
32import androidx.databinding.DataBindingUtil;
33
34import org.openintents.openpgp.util.OpenPgpUtils;
35
36import java.util.Collection;
37import java.util.Collections;
38import java.util.List;
39
40import eu.siacs.conversations.Config;
41import eu.siacs.conversations.R;
42import eu.siacs.conversations.crypto.axolotl.AxolotlService;
43import eu.siacs.conversations.crypto.axolotl.FingerprintStatus;
44import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
45import eu.siacs.conversations.databinding.ActivityContactDetailsBinding;
46import eu.siacs.conversations.entities.Account;
47import eu.siacs.conversations.entities.Contact;
48import eu.siacs.conversations.entities.ListItem;
49import eu.siacs.conversations.services.AbstractQuickConversationsService;
50import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
51import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
52import eu.siacs.conversations.ui.adapter.MediaAdapter;
53import eu.siacs.conversations.ui.interfaces.OnMediaLoaded;
54import eu.siacs.conversations.ui.util.Attachment;
55import eu.siacs.conversations.ui.util.AvatarWorkerTask;
56import eu.siacs.conversations.ui.util.GridManager;
57import eu.siacs.conversations.ui.util.JidDialog;
58import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
59import eu.siacs.conversations.utils.AccountUtils;
60import eu.siacs.conversations.utils.Compatibility;
61import eu.siacs.conversations.utils.Emoticons;
62import eu.siacs.conversations.utils.IrregularUnicodeDetector;
63import eu.siacs.conversations.utils.PhoneNumberUtilWrapper;
64import eu.siacs.conversations.utils.UIHelper;
65import eu.siacs.conversations.utils.XmppUri;
66import eu.siacs.conversations.xml.Namespace;
67import eu.siacs.conversations.xmpp.Jid;
68import eu.siacs.conversations.xmpp.OnKeyStatusUpdated;
69import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
70import eu.siacs.conversations.xmpp.XmppConnection;
71
72public class ContactDetailsActivity extends OmemoActivity implements OnAccountUpdate, OnRosterUpdate, OnUpdateBlocklist, OnKeyStatusUpdated, OnMediaLoaded {
73 public static final String ACTION_VIEW_CONTACT = "view_contact";
74 private final int REQUEST_SYNC_CONTACTS = 0x28cf;
75 ActivityContactDetailsBinding binding;
76 private MediaAdapter mMediaAdapter;
77 protected MenuItem edit = null;
78 protected MenuItem save = null;
79
80 private Contact contact;
81 private final DialogInterface.OnClickListener removeFromRoster = new DialogInterface.OnClickListener() {
82
83 @Override
84 public void onClick(DialogInterface dialog, int which) {
85 xmppConnectionService.deleteContactOnServer(contact);
86 }
87 };
88 private final OnCheckedChangeListener mOnSendCheckedChange = new OnCheckedChangeListener() {
89
90 @Override
91 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
92 if (isChecked) {
93 if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
94 xmppConnectionService.stopPresenceUpdatesTo(contact);
95 } else {
96 contact.setOption(Contact.Options.PREEMPTIVE_GRANT);
97 }
98 } else {
99 contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
100 xmppConnectionService.sendPresencePacket(contact.getAccount(), xmppConnectionService.getPresenceGenerator().stopPresenceUpdatesTo(contact));
101 }
102 }
103 };
104 private final OnCheckedChangeListener mOnReceiveCheckedChange = new OnCheckedChangeListener() {
105
106 @Override
107 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
108 if (isChecked) {
109 xmppConnectionService.sendPresencePacket(contact.getAccount(), xmppConnectionService.getPresenceGenerator().requestPresenceUpdatesFrom(contact));
110 } else {
111 xmppConnectionService.sendPresencePacket(contact.getAccount(), xmppConnectionService.getPresenceGenerator().stopPresenceUpdatesFrom(contact));
112 }
113 }
114 };
115 private Jid accountJid;
116 private Jid contactJid;
117 private boolean showDynamicTags = false;
118 private boolean showLastSeen = false;
119 private boolean showInactiveOmemo = false;
120 private String messageFingerprint;
121
122 private void checkContactPermissionAndShowAddDialog() {
123 if (hasContactsPermission()) {
124 showAddToPhoneBookDialog();
125 } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
126 requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_SYNC_CONTACTS);
127 }
128 }
129
130 private boolean hasContactsPermission() {
131 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
132 return checkSelfPermission(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED;
133 } else {
134 return true;
135 }
136 }
137
138 private void showAddToPhoneBookDialog() {
139 final Jid jid = contact.getJid();
140 final boolean quicksyContact = AbstractQuickConversationsService.isQuicksy()
141 && Config.QUICKSY_DOMAIN.equals(jid.getDomain())
142 && jid.getLocal() != null;
143 final String value;
144 if (quicksyContact) {
145 value = PhoneNumberUtilWrapper.toFormattedPhoneNumber(this, jid);
146 } else {
147 value = jid.toEscapedString();
148 }
149 final AlertDialog.Builder builder = new AlertDialog.Builder(this);
150 builder.setTitle(getString(R.string.action_add_phone_book));
151 builder.setMessage(getString(R.string.add_phone_book_text, value));
152 builder.setNegativeButton(getString(R.string.cancel), null);
153 builder.setPositiveButton(getString(R.string.add), (dialog, which) -> {
154 final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
155 intent.setType(Contacts.CONTENT_ITEM_TYPE);
156 if (quicksyContact) {
157 intent.putExtra(Intents.Insert.PHONE, value);
158 } else {
159 intent.putExtra(Intents.Insert.IM_HANDLE, value);
160 intent.putExtra(Intents.Insert.IM_PROTOCOL, CommonDataKinds.Im.PROTOCOL_JABBER);
161 //TODO for modern use we want PROTOCOL_CUSTOM and an extra field with a value of 'XMPP'
162 // however we don’t have such a field and thus have to use the legacy PROTOCOL_JABBER
163 }
164 intent.putExtra("finishActivityOnSaveCompleted", true);
165 try {
166 startActivityForResult(intent, 0);
167 } catch (ActivityNotFoundException e) {
168 Toast.makeText(ContactDetailsActivity.this, R.string.no_application_found_to_view_contact, Toast.LENGTH_SHORT).show();
169 }
170 });
171 builder.create().show();
172 }
173
174 @Override
175 public void onRosterUpdate() {
176 refreshUi();
177 }
178
179 @Override
180 public void onAccountUpdate() {
181 refreshUi();
182 }
183
184 @Override
185 public void OnUpdateBlocklist(final Status status) {
186 refreshUi();
187 }
188
189 @Override
190 protected void refreshUiReal() {
191 invalidateOptionsMenu();
192 populateView();
193 }
194
195 @Override
196 protected String getShareableUri(boolean http) {
197 if (http) {
198 return "https://conversations.im/i/" + XmppUri.lameUrlEncode(contact.getJid().asBareJid().toEscapedString());
199 } else {
200 return "xmpp:" + contact.getJid().asBareJid().toEscapedString();
201 }
202 }
203
204 @Override
205 protected void onCreate(final Bundle savedInstanceState) {
206 super.onCreate(savedInstanceState);
207 showInactiveOmemo = savedInstanceState != null && savedInstanceState.getBoolean("show_inactive_omemo", false);
208 if (getIntent().getAction().equals(ACTION_VIEW_CONTACT)) {
209 try {
210 this.accountJid = Jid.ofEscaped(getIntent().getExtras().getString(EXTRA_ACCOUNT));
211 } catch (final IllegalArgumentException ignored) {
212 }
213 try {
214 this.contactJid = Jid.ofEscaped(getIntent().getExtras().getString("contact"));
215 } catch (final IllegalArgumentException ignored) {
216 }
217 }
218 this.messageFingerprint = getIntent().getStringExtra("fingerprint");
219 this.binding = DataBindingUtil.setContentView(this, R.layout.activity_contact_details);
220
221 setSupportActionBar(binding.toolbar);
222 configureActionBar(getSupportActionBar());
223 binding.showInactiveDevices.setOnClickListener(v -> {
224 showInactiveOmemo = !showInactiveOmemo;
225 populateView();
226 });
227 binding.addContactButton.setOnClickListener(v -> showAddToRosterDialog(contact));
228
229 mMediaAdapter = new MediaAdapter(this, R.dimen.media_size);
230 this.binding.media.setAdapter(mMediaAdapter);
231 GridManager.setupLayoutManager(this, this.binding.media, R.dimen.media_size);
232 }
233
234 @Override
235 public void onSaveInstanceState(final Bundle savedInstanceState) {
236 savedInstanceState.putBoolean("show_inactive_omemo", showInactiveOmemo);
237 super.onSaveInstanceState(savedInstanceState);
238 }
239
240 @Override
241 public void onStart() {
242 super.onStart();
243 final int theme = findTheme();
244 if (this.mTheme != theme) {
245 recreate();
246 } else {
247 final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
248 this.showDynamicTags = preferences.getBoolean(SettingsActivity.SHOW_DYNAMIC_TAGS, getResources().getBoolean(R.bool.show_dynamic_tags));
249 this.showLastSeen = preferences.getBoolean("last_activity", false);
250 }
251 binding.mediaWrapper.setVisibility(Compatibility.hasStoragePermission(this) ? View.VISIBLE : View.GONE);
252 mMediaAdapter.setAttachments(Collections.emptyList());
253 }
254
255 @Override
256 public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
257 super.onRequestPermissionsResult(requestCode, permissions, grantResults);
258 if (grantResults.length > 0)
259 if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
260 if (requestCode == REQUEST_SYNC_CONTACTS && xmppConnectionServiceBound) {
261 showAddToPhoneBookDialog();
262 xmppConnectionService.loadPhoneContacts();
263 xmppConnectionService.startContactObserver();
264 }
265 }
266 }
267
268 protected void saveEdits() {
269 if (edit != null) {
270 EditText text = edit.getActionView().findViewById(R.id.search_field);
271 contact.setServerName(text.getText().toString());
272 ContactDetailsActivity.this.xmppConnectionService.pushContactToServer(contact);
273 populateView();
274 edit.collapseActionView();
275 }
276 if (save != null) save.setVisible(false);
277 }
278
279 @Override
280 public boolean onOptionsItemSelected(final MenuItem menuItem) {
281 if (MenuDoubleTabUtil.shouldIgnoreTap()) {
282 return false;
283 }
284 final AlertDialog.Builder builder = new AlertDialog.Builder(this);
285 builder.setNegativeButton(getString(R.string.cancel), null);
286 switch (menuItem.getItemId()) {
287 case android.R.id.home:
288 finish();
289 break;
290 case R.id.action_share_http:
291 shareLink(true);
292 break;
293 case R.id.action_share_uri:
294 shareLink(false);
295 break;
296 case R.id.action_delete_contact:
297 builder.setTitle(getString(R.string.action_delete_contact))
298 .setMessage(JidDialog.style(this, R.string.remove_contact_text, contact.getJid().toEscapedString()))
299 .setPositiveButton(getString(R.string.delete),
300 removeFromRoster).create().show();
301 break;
302 case R.id.action_save:
303 saveEdits();
304 break;
305 case R.id.action_edit_contact:
306 Uri systemAccount = contact.getSystemAccount();
307 if (systemAccount == null) {
308 menuItem.expandActionView();
309 EditText text = menuItem.getActionView().findViewById(R.id.search_field);
310 text.setOnEditorActionListener((v, actionId, event) -> {
311 saveEdits();
312 return true;
313 });
314 text.setText(contact.getServerName());
315 text.requestFocus();
316 if (save != null) save.setVisible(true);
317 } else {
318 menuItem.collapseActionView();
319 if (save != null) save.setVisible(false);
320 Intent intent = new Intent(Intent.ACTION_EDIT);
321 intent.setDataAndType(systemAccount, Contacts.CONTENT_ITEM_TYPE);
322 intent.putExtra("finishActivityOnSaveCompleted", true);
323 try {
324 startActivity(intent);
325 } catch (ActivityNotFoundException e) {
326 Toast.makeText(ContactDetailsActivity.this, R.string.no_application_found_to_view_contact, Toast.LENGTH_SHORT).show();
327 }
328
329 }
330 break;
331 case R.id.action_block:
332 BlockContactDialog.show(this, contact);
333 break;
334 case R.id.action_unblock:
335 BlockContactDialog.show(this, contact);
336 break;
337 }
338 return super.onOptionsItemSelected(menuItem);
339 }
340
341 @Override
342 public boolean onCreateOptionsMenu(final Menu menu) {
343 getMenuInflater().inflate(R.menu.contact_details, menu);
344 AccountUtils.showHideMenuItems(menu);
345 edit = menu.findItem(R.id.action_edit_contact);
346 save = menu.findItem(R.id.action_save);
347 MenuItem block = menu.findItem(R.id.action_block);
348 MenuItem unblock = menu.findItem(R.id.action_unblock);
349 MenuItem edit = menu.findItem(R.id.action_edit_contact);
350 MenuItem delete = menu.findItem(R.id.action_delete_contact);
351 if (contact == null) {
352 return true;
353 }
354 final XmppConnection connection = contact.getAccount().getXmppConnection();
355 if (connection != null && connection.getFeatures().blocking()) {
356 if (this.contact.isBlocked()) {
357 block.setVisible(false);
358 } else {
359 unblock.setVisible(false);
360 }
361 } else {
362 unblock.setVisible(false);
363 block.setVisible(false);
364 }
365 if (!contact.showInRoster()) {
366 edit.setVisible(false);
367 delete.setVisible(false);
368 }
369 return super.onCreateOptionsMenu(menu);
370 }
371
372 private void populateView() {
373 if (contact == null) {
374 return;
375 }
376 invalidateOptionsMenu();
377 setTitle(contact.getDisplayName());
378 if (contact.showInRoster()) {
379 binding.detailsSendPresence.setVisibility(View.VISIBLE);
380 binding.detailsReceivePresence.setVisibility(View.VISIBLE);
381 binding.addContactButton.setVisibility(View.GONE);
382 binding.detailsSendPresence.setOnCheckedChangeListener(null);
383 binding.detailsReceivePresence.setOnCheckedChangeListener(null);
384
385 List<String> statusMessages = contact.getPresences().getStatusMessages();
386 if (statusMessages.size() == 0) {
387 binding.statusMessage.setVisibility(View.GONE);
388 } else if (statusMessages.size() == 1) {
389 final String message = statusMessages.get(0);
390 binding.statusMessage.setVisibility(View.VISIBLE);
391 final Spannable span = new SpannableString(message);
392 if (Emoticons.isOnlyEmoji(message)) {
393 span.setSpan(new RelativeSizeSpan(2.0f), 0, message.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
394 }
395 binding.statusMessage.setText(span);
396 } else {
397 StringBuilder builder = new StringBuilder();
398 binding.statusMessage.setVisibility(View.VISIBLE);
399 int s = statusMessages.size();
400 for (int i = 0; i < s; ++i) {
401 builder.append(statusMessages.get(i));
402 if (i < s - 1) {
403 builder.append("\n");
404 }
405 }
406 binding.statusMessage.setText(builder);
407 }
408
409 if (contact.getOption(Contact.Options.FROM)) {
410 binding.detailsSendPresence.setText(R.string.send_presence_updates);
411 binding.detailsSendPresence.setChecked(true);
412 } else if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
413 binding.detailsSendPresence.setChecked(false);
414 binding.detailsSendPresence.setText(R.string.send_presence_updates);
415 } else {
416 binding.detailsSendPresence.setText(R.string.preemptively_grant);
417 binding.detailsSendPresence.setChecked(contact.getOption(Contact.Options.PREEMPTIVE_GRANT));
418 }
419 if (contact.getOption(Contact.Options.TO)) {
420 binding.detailsReceivePresence.setText(R.string.receive_presence_updates);
421 binding.detailsReceivePresence.setChecked(true);
422 } else {
423 binding.detailsReceivePresence.setText(R.string.ask_for_presence_updates);
424 binding.detailsReceivePresence.setChecked(contact.getOption(Contact.Options.ASKING));
425 }
426 if (contact.getAccount().isOnlineAndConnected()) {
427 binding.detailsReceivePresence.setEnabled(true);
428 binding.detailsSendPresence.setEnabled(true);
429 } else {
430 binding.detailsReceivePresence.setEnabled(false);
431 binding.detailsSendPresence.setEnabled(false);
432 }
433 binding.detailsSendPresence.setOnCheckedChangeListener(this.mOnSendCheckedChange);
434 binding.detailsReceivePresence.setOnCheckedChangeListener(this.mOnReceiveCheckedChange);
435 } else {
436 binding.addContactButton.setVisibility(View.VISIBLE);
437 binding.detailsSendPresence.setVisibility(View.GONE);
438 binding.detailsReceivePresence.setVisibility(View.GONE);
439 binding.statusMessage.setVisibility(View.GONE);
440 }
441
442 if (contact.isBlocked() && !this.showDynamicTags) {
443 binding.detailsLastseen.setVisibility(View.VISIBLE);
444 binding.detailsLastseen.setText(R.string.contact_blocked);
445 } else {
446 if (showLastSeen
447 && contact.getLastseen() > 0
448 && contact.getPresences().allOrNonSupport(Namespace.IDLE)) {
449 binding.detailsLastseen.setVisibility(View.VISIBLE);
450 binding.detailsLastseen.setText(UIHelper.lastseen(getApplicationContext(), contact.isActive(), contact.getLastseen()));
451 } else {
452 binding.detailsLastseen.setVisibility(View.GONE);
453 }
454 }
455
456 binding.detailsContactjid.setText(IrregularUnicodeDetector.style(this, contact.getJid()));
457 String account;
458 if (Config.DOMAIN_LOCK != null) {
459 account = contact.getAccount().getJid().getEscapedLocal();
460 } else {
461 account = contact.getAccount().getJid().asBareJid().toEscapedString();
462 }
463 binding.detailsAccount.setText(getString(R.string.using_account, account));
464 AvatarWorkerTask.loadAvatar(contact, binding.detailsContactBadge, R.dimen.avatar_on_details_screen_size);
465 binding.detailsContactBadge.setOnClickListener(this::onBadgeClick);
466
467 binding.detailsContactKeys.removeAllViews();
468 boolean hasKeys = false;
469 final LayoutInflater inflater = getLayoutInflater();
470 final AxolotlService axolotlService = contact.getAccount().getAxolotlService();
471 if (Config.supportOmemo() && axolotlService != null) {
472 final Collection<XmppAxolotlSession> sessions = axolotlService.findSessionsForContact(contact);
473 boolean anyActive = false;
474 for (XmppAxolotlSession session : sessions) {
475 anyActive = session.getTrust().isActive();
476 if (anyActive) {
477 break;
478 }
479 }
480 boolean skippedInactive = false;
481 boolean showsInactive = false;
482 for (final XmppAxolotlSession session : sessions) {
483 final FingerprintStatus trust = session.getTrust();
484 hasKeys |= !trust.isCompromised();
485 if (!trust.isActive() && anyActive) {
486 if (showInactiveOmemo) {
487 showsInactive = true;
488 } else {
489 skippedInactive = true;
490 continue;
491 }
492 }
493 if (!trust.isCompromised()) {
494 boolean highlight = session.getFingerprint().equals(messageFingerprint);
495 addFingerprintRow(binding.detailsContactKeys, session, highlight);
496 }
497 }
498 if (showsInactive || skippedInactive) {
499 binding.showInactiveDevices.setText(showsInactive ? R.string.hide_inactive_devices : R.string.show_inactive_devices);
500 binding.showInactiveDevices.setVisibility(View.VISIBLE);
501 } else {
502 binding.showInactiveDevices.setVisibility(View.GONE);
503 }
504 } else {
505 binding.showInactiveDevices.setVisibility(View.GONE);
506 }
507 binding.scanButton.setVisibility(hasKeys && isCameraFeatureAvailable() ? View.VISIBLE : View.GONE);
508 if (hasKeys) {
509 binding.scanButton.setOnClickListener((v) -> ScanActivity.scan(this));
510 }
511 if (Config.supportOpenPgp() && contact.getPgpKeyId() != 0) {
512 hasKeys = true;
513 View view = inflater.inflate(R.layout.contact_key, binding.detailsContactKeys, false);
514 TextView key = view.findViewById(R.id.key);
515 TextView keyType = view.findViewById(R.id.key_type);
516 keyType.setText(R.string.openpgp_key_id);
517 if ("pgp".equals(messageFingerprint)) {
518 keyType.setTextAppearance(this, R.style.TextAppearance_Conversations_Caption_Highlight);
519 }
520 key.setText(OpenPgpUtils.convertKeyIdToHex(contact.getPgpKeyId()));
521 final OnClickListener openKey = v -> launchOpenKeyChain(contact.getPgpKeyId());
522 view.setOnClickListener(openKey);
523 key.setOnClickListener(openKey);
524 keyType.setOnClickListener(openKey);
525 binding.detailsContactKeys.addView(view);
526 }
527 binding.keysWrapper.setVisibility(hasKeys ? View.VISIBLE : View.GONE);
528
529 List<ListItem.Tag> tagList = contact.getTags(this);
530 if (tagList.size() == 0 || !this.showDynamicTags) {
531 binding.tags.setVisibility(View.GONE);
532 } else {
533 binding.tags.setVisibility(View.VISIBLE);
534 binding.tags.removeAllViewsInLayout();
535 for (final ListItem.Tag tag : tagList) {
536 final TextView tv = (TextView) inflater.inflate(R.layout.list_item_tag, binding.tags, false);
537 tv.setText(tag.getName());
538 tv.setBackgroundColor(tag.getColor());
539 binding.tags.addView(tv);
540 }
541 }
542 }
543
544 private void onBadgeClick(View view) {
545 final Uri systemAccount = contact.getSystemAccount();
546 if (systemAccount == null) {
547 checkContactPermissionAndShowAddDialog();
548 } else {
549 final Intent intent = new Intent(Intent.ACTION_VIEW);
550 intent.setData(systemAccount);
551 try {
552 startActivity(intent);
553 } catch (final ActivityNotFoundException e) {
554 Toast.makeText(this, R.string.no_application_found_to_view_contact, Toast.LENGTH_SHORT).show();
555 }
556 }
557 }
558
559 public void onBackendConnected() {
560 if (accountJid != null && contactJid != null) {
561 Account account = xmppConnectionService.findAccountByJid(accountJid);
562 if (account == null) {
563 return;
564 }
565 this.contact = account.getRoster().getContact(contactJid);
566 if (mPendingFingerprintVerificationUri != null) {
567 processFingerprintVerification(mPendingFingerprintVerificationUri);
568 mPendingFingerprintVerificationUri = null;
569 }
570
571 if (Compatibility.hasStoragePermission(this)) {
572 final int limit = GridManager.getCurrentColumnCount(this.binding.media);
573 xmppConnectionService.getAttachments(account, contact.getJid().asBareJid(), limit, this);
574 this.binding.showMedia.setOnClickListener((v) -> MediaBrowserActivity.launch(this, contact));
575 }
576 populateView();
577 }
578 }
579
580 @Override
581 public void onKeyStatusUpdated(AxolotlService.FetchStatus report) {
582 refreshUi();
583 }
584
585 @Override
586 protected void processFingerprintVerification(XmppUri uri) {
587 if (contact != null && contact.getJid().asBareJid().equals(uri.getJid()) && uri.hasFingerprints()) {
588 if (xmppConnectionService.verifyFingerprints(contact, uri.getFingerprints())) {
589 Toast.makeText(this, R.string.verified_fingerprints, Toast.LENGTH_SHORT).show();
590 }
591 } else {
592 Toast.makeText(this, R.string.invalid_barcode, Toast.LENGTH_SHORT).show();
593 }
594 }
595
596 @Override
597 public void onMediaLoaded(List<Attachment> attachments) {
598 runOnUiThread(() -> {
599 int limit = GridManager.getCurrentColumnCount(binding.media);
600 mMediaAdapter.setAttachments(attachments.subList(0, Math.min(limit, attachments.size())));
601 binding.mediaWrapper.setVisibility(attachments.size() > 0 ? View.VISIBLE : View.GONE);
602 });
603
604 }
605}