ContactDetailsActivity.java

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