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 com.google.android.material.color.MaterialColors;
 34import com.google.android.material.dialog.MaterialAlertDialogBuilder;
 35
 36import org.openintents.openpgp.util.OpenPgpUtils;
 37
 38import java.util.Collection;
 39import java.util.Collections;
 40import java.util.List;
 41
 42import eu.siacs.conversations.Config;
 43import eu.siacs.conversations.R;
 44import eu.siacs.conversations.crypto.axolotl.AxolotlService;
 45import eu.siacs.conversations.crypto.axolotl.FingerprintStatus;
 46import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
 47import eu.siacs.conversations.databinding.ActivityContactDetailsBinding;
 48import eu.siacs.conversations.entities.Account;
 49import eu.siacs.conversations.entities.Contact;
 50import eu.siacs.conversations.entities.ListItem;
 51import eu.siacs.conversations.services.AbstractQuickConversationsService;
 52import eu.siacs.conversations.services.QuickConversationsService;
 53import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
 54import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
 55import eu.siacs.conversations.ui.adapter.MediaAdapter;
 56import eu.siacs.conversations.ui.interfaces.OnMediaLoaded;
 57import eu.siacs.conversations.ui.util.Attachment;
 58import eu.siacs.conversations.ui.util.AvatarWorkerTask;
 59import eu.siacs.conversations.ui.util.GridManager;
 60import eu.siacs.conversations.ui.util.JidDialog;
 61import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
 62import eu.siacs.conversations.utils.AccountUtils;
 63import eu.siacs.conversations.utils.Compatibility;
 64import eu.siacs.conversations.utils.Emoticons;
 65import eu.siacs.conversations.utils.IrregularUnicodeDetector;
 66import eu.siacs.conversations.utils.PhoneNumberUtilWrapper;
 67import eu.siacs.conversations.utils.UIHelper;
 68import eu.siacs.conversations.utils.XmppUri;
 69import eu.siacs.conversations.xml.Namespace;
 70import eu.siacs.conversations.xmpp.Jid;
 71import eu.siacs.conversations.xmpp.OnKeyStatusUpdated;
 72import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
 73import eu.siacs.conversations.xmpp.XmppConnection;
 74
 75public class ContactDetailsActivity extends OmemoActivity implements OnAccountUpdate, OnRosterUpdate, OnUpdateBlocklist, OnKeyStatusUpdated, OnMediaLoaded {
 76    public static final String ACTION_VIEW_CONTACT = "view_contact";
 77    private final int REQUEST_SYNC_CONTACTS = 0x28cf;
 78    ActivityContactDetailsBinding binding;
 79    private MediaAdapter mMediaAdapter;
 80
 81    private Contact contact;
 82    private final DialogInterface.OnClickListener removeFromRoster = new DialogInterface.OnClickListener() {
 83
 84        @Override
 85        public void onClick(DialogInterface dialog, int which) {
 86            xmppConnectionService.deleteContactOnServer(contact);
 87        }
 88    };
 89    private final OnCheckedChangeListener mOnSendCheckedChange = new OnCheckedChangeListener() {
 90
 91        @Override
 92        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
 93            if (isChecked) {
 94                if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
 95                    xmppConnectionService.stopPresenceUpdatesTo(contact);
 96                } else {
 97                    contact.setOption(Contact.Options.PREEMPTIVE_GRANT);
 98                }
 99            } else {
100                contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
101                xmppConnectionService.sendPresencePacket(contact.getAccount(), xmppConnectionService.getPresenceGenerator().stopPresenceUpdatesTo(contact));
102            }
103        }
104    };
105    private final OnCheckedChangeListener mOnReceiveCheckedChange = new OnCheckedChangeListener() {
106
107        @Override
108        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
109            if (isChecked) {
110                xmppConnectionService.sendPresencePacket(contact.getAccount(), xmppConnectionService.getPresenceGenerator().requestPresenceUpdatesFrom(contact));
111            } else {
112                xmppConnectionService.sendPresencePacket(contact.getAccount(), xmppConnectionService.getPresenceGenerator().stopPresenceUpdatesFrom(contact));
113            }
114        }
115    };
116    private Jid accountJid;
117    private Jid contactJid;
118    private boolean showDynamicTags = false;
119    private boolean showLastSeen = false;
120    private boolean showInactiveOmemo = false;
121    private String messageFingerprint;
122
123    private void checkContactPermissionAndShowAddDialog() {
124        if (hasContactsPermission()) {
125            showAddToPhoneBookDialog();
126        } else if (QuickConversationsService.isContactListIntegration(this) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
127            requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_SYNC_CONTACTS);
128        }
129    }
130
131    private boolean hasContactsPermission() {
132        if (QuickConversationsService.isContactListIntegration(this) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
133            return checkSelfPermission(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED;
134        } else {
135            return true;
136        }
137    }
138
139    private void showAddToPhoneBookDialog() {
140        final Jid jid = contact.getJid();
141        final boolean quicksyContact = AbstractQuickConversationsService.isQuicksy()
142                && Config.QUICKSY_DOMAIN.equals(jid.getDomain())
143                && jid.getLocal() != null;
144        final String value;
145        if (quicksyContact) {
146            value = PhoneNumberUtilWrapper.toFormattedPhoneNumber(this, jid);
147        } else {
148            value = jid.toEscapedString();
149        }
150        final MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this);
151        builder.setTitle(getString(R.string.action_add_phone_book));
152        builder.setMessage(getString(R.string.add_phone_book_text, value));
153        builder.setNegativeButton(getString(R.string.cancel), null);
154        builder.setPositiveButton(getString(R.string.add), (dialog, which) -> {
155            final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
156            intent.setType(Contacts.CONTENT_ITEM_TYPE);
157            if (quicksyContact) {
158                intent.putExtra(Intents.Insert.PHONE, value);
159            } else {
160                intent.putExtra(Intents.Insert.IM_HANDLE, value);
161                intent.putExtra(Intents.Insert.IM_PROTOCOL, CommonDataKinds.Im.PROTOCOL_JABBER);
162                //TODO for modern use we want PROTOCOL_CUSTOM and an extra field with a value of 'XMPP'
163                // however we don’t have such a field and thus have to use the legacy PROTOCOL_JABBER
164            }
165            intent.putExtra("finishActivityOnSaveCompleted", true);
166            try {
167                startActivityForResult(intent, 0);
168            } catch (ActivityNotFoundException e) {
169                Toast.makeText(ContactDetailsActivity.this, R.string.no_application_found_to_view_contact, Toast.LENGTH_SHORT).show();
170            }
171        });
172        builder.create().show();
173    }
174
175    @Override
176    public void onRosterUpdate() {
177        refreshUi();
178    }
179
180    @Override
181    public void onAccountUpdate() {
182        refreshUi();
183    }
184
185    @Override
186    public void OnUpdateBlocklist(final Status status) {
187        refreshUi();
188    }
189
190    @Override
191    protected void refreshUiReal() {
192        invalidateOptionsMenu();
193        populateView();
194    }
195
196    @Override
197    protected String getShareableUri(boolean http) {
198        if (http) {
199            return "https://conversations.im/i/" + XmppUri.lameUrlEncode(contact.getJid().asBareJid().toEscapedString());
200        } else {
201            return "xmpp:" + contact.getJid().asBareJid().toEscapedString();
202        }
203    }
204
205    @Override
206    protected void onCreate(final Bundle savedInstanceState) {
207        super.onCreate(savedInstanceState);
208        showInactiveOmemo = savedInstanceState != null && savedInstanceState.getBoolean("show_inactive_omemo", false);
209        if (getIntent().getAction().equals(ACTION_VIEW_CONTACT)) {
210            try {
211                this.accountJid = Jid.ofEscaped(getIntent().getExtras().getString(EXTRA_ACCOUNT));
212            } catch (final IllegalArgumentException ignored) {
213            }
214            try {
215                this.contactJid = Jid.ofEscaped(getIntent().getExtras().getString("contact"));
216            } catch (final IllegalArgumentException ignored) {
217            }
218        }
219        this.messageFingerprint = getIntent().getStringExtra("fingerprint");
220        this.binding = DataBindingUtil.setContentView(this, R.layout.activity_contact_details);
221        Activities.setStatusAndNavigationBarColors(this, binding.getRoot());
222
223        setSupportActionBar(binding.toolbar);
224        configureActionBar(getSupportActionBar());
225        binding.showInactiveDevices.setOnClickListener(v -> {
226            showInactiveOmemo = !showInactiveOmemo;
227            populateView();
228        });
229        binding.addContactButton.setOnClickListener(v -> showAddToRosterDialog(contact));
230
231        mMediaAdapter = new MediaAdapter(this, R.dimen.media_size);
232        this.binding.media.setAdapter(mMediaAdapter);
233        GridManager.setupLayoutManager(this, this.binding.media, R.dimen.media_size);
234    }
235
236    @Override
237    public void onSaveInstanceState(final Bundle savedInstanceState) {
238        savedInstanceState.putBoolean("show_inactive_omemo", showInactiveOmemo);
239        super.onSaveInstanceState(savedInstanceState);
240    }
241
242    @Override
243    public void onStart() {
244        super.onStart();
245        final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
246        this.showDynamicTags = preferences.getBoolean(SettingsActivity.SHOW_DYNAMIC_TAGS, false);
247        this.showLastSeen = preferences.getBoolean("last_activity", false);
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        switch (menuItem.getItemId()) {
271            case android.R.id.home:
272                finish();
273                break;
274            case R.id.action_share_http:
275                shareLink(true);
276                break;
277            case R.id.action_share_uri:
278                shareLink(false);
279                break;
280            case R.id.action_delete_contact:
281                final MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this);
282                builder.setNegativeButton(getString(R.string.cancel), null);
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        final String account = contact.getAccount().getJid().asBareJid().toEscapedString();
434        binding.detailsAccount.setText(getString(R.string.using_account, account));
435        AvatarWorkerTask.loadAvatar(contact, binding.detailsContactBadge, R.dimen.avatar_on_details_screen_size);
436        binding.detailsContactBadge.setOnClickListener(this::onBadgeClick);
437
438        binding.detailsContactKeys.removeAllViews();
439        boolean hasKeys = false;
440        final LayoutInflater inflater = getLayoutInflater();
441        final AxolotlService axolotlService = contact.getAccount().getAxolotlService();
442        if (Config.supportOmemo() && axolotlService != null) {
443            final Collection<XmppAxolotlSession> sessions = axolotlService.findSessionsForContact(contact);
444            boolean anyActive = false;
445            for (XmppAxolotlSession session : sessions) {
446                anyActive = session.getTrust().isActive();
447                if (anyActive) {
448                    break;
449                }
450            }
451            boolean skippedInactive = false;
452            boolean showsInactive = false;
453            boolean showUnverifiedWarning = false;
454            for (final XmppAxolotlSession session : sessions) {
455                final FingerprintStatus trust = session.getTrust();
456                hasKeys |= !trust.isCompromised();
457                if (!trust.isActive() && anyActive) {
458                    if (showInactiveOmemo) {
459                        showsInactive = true;
460                    } else {
461                        skippedInactive = true;
462                        continue;
463                    }
464                }
465                if (!trust.isCompromised()) {
466                    boolean highlight = session.getFingerprint().equals(messageFingerprint);
467                    addFingerprintRow(binding.detailsContactKeys, session, highlight);
468                }
469                if (trust.isUnverified()) {
470                    showUnverifiedWarning = true;
471                }
472            }
473            binding.unverifiedWarning.setVisibility(showUnverifiedWarning ? View.VISIBLE : View.GONE);
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        final boolean isCameraFeatureAvailable = isCameraFeatureAvailable();
484        binding.scanButton.setVisibility(hasKeys && isCameraFeatureAvailable ? View.VISIBLE : View.GONE);
485        if (hasKeys) {
486            binding.scanButton.setOnClickListener((v) -> ScanActivity.scan(this));
487        }
488        if (Config.supportOpenPgp() && contact.getPgpKeyId() != 0) {
489            hasKeys = true;
490            View view = inflater.inflate(R.layout.contact_key, binding.detailsContactKeys, false);
491            TextView key = view.findViewById(R.id.key);
492            TextView keyType = view.findViewById(R.id.key_type);
493            keyType.setText(R.string.openpgp_key_id);
494            if ("pgp".equals(messageFingerprint)) {
495                keyType.setTextColor(MaterialColors.getColor(keyType, com.google.android.material.R.attr.colorPrimaryVariant));
496            }
497            key.setText(OpenPgpUtils.convertKeyIdToHex(contact.getPgpKeyId()));
498            final OnClickListener openKey = v -> launchOpenKeyChain(contact.getPgpKeyId());
499            view.setOnClickListener(openKey);
500            key.setOnClickListener(openKey);
501            keyType.setOnClickListener(openKey);
502            binding.detailsContactKeys.addView(view);
503        }
504        binding.keysWrapper.setVisibility(hasKeys ? View.VISIBLE : View.GONE);
505
506        List<ListItem.Tag> tagList = contact.getTags(this);
507        if (tagList.isEmpty() || !this.showDynamicTags) {
508            binding.tags.setVisibility(View.GONE);
509        } else {
510            binding.tags.setVisibility(View.VISIBLE);
511            binding.tags.removeAllViewsInLayout();
512            for (final ListItem.Tag tag : tagList) {
513                final TextView tv = (TextView) inflater.inflate(R.layout.list_item_tag, binding.tags, false);
514                tv.setText(tag.getName());
515                tv.setBackgroundColor(tag.getColor());
516                binding.tags.addView(tv);
517            }
518        }
519    }
520
521    private void onBadgeClick(final View view) {
522        if (QuickConversationsService.isContactListIntegration(this)) {
523            final Uri systemAccount = contact.getSystemAccount();
524            if (systemAccount == null) {
525                checkContactPermissionAndShowAddDialog();
526            } else {
527                final Intent intent = new Intent(Intent.ACTION_VIEW);
528                intent.setData(systemAccount);
529                try {
530                    startActivity(intent);
531                } catch (final ActivityNotFoundException e) {
532                    Toast.makeText(
533                                    this,
534                                    R.string.no_application_found_to_view_contact,
535                                    Toast.LENGTH_SHORT)
536                            .show();
537                }
538            }
539        } else {
540            Toast.makeText(
541                            this,
542                            R.string.contact_list_integration_not_available,
543                            Toast.LENGTH_SHORT)
544                    .show();
545        }
546    }
547
548    public void onBackendConnected() {
549        if (accountJid != null && contactJid != null) {
550            Account account = xmppConnectionService.findAccountByJid(accountJid);
551            if (account == null) {
552                return;
553            }
554            this.contact = account.getRoster().getContact(contactJid);
555            if (mPendingFingerprintVerificationUri != null) {
556                processFingerprintVerification(mPendingFingerprintVerificationUri);
557                mPendingFingerprintVerificationUri = null;
558            }
559
560            if (Compatibility.hasStoragePermission(this)) {
561                final int limit = GridManager.getCurrentColumnCount(this.binding.media);
562                xmppConnectionService.getAttachments(account, contact.getJid().asBareJid(), limit, this);
563                this.binding.showMedia.setOnClickListener((v) -> MediaBrowserActivity.launch(this, contact));
564            }
565            populateView();
566        }
567    }
568
569    @Override
570    public void onKeyStatusUpdated(AxolotlService.FetchStatus report) {
571        refreshUi();
572    }
573
574    @Override
575    protected void processFingerprintVerification(XmppUri uri) {
576        if (contact != null && contact.getJid().asBareJid().equals(uri.getJid()) && uri.hasFingerprints()) {
577            if (xmppConnectionService.verifyFingerprints(contact, uri.getFingerprints())) {
578                Toast.makeText(this, R.string.verified_fingerprints, Toast.LENGTH_SHORT).show();
579            }
580        } else {
581            Toast.makeText(this, R.string.invalid_barcode, Toast.LENGTH_SHORT).show();
582        }
583    }
584
585    @Override
586    public void onMediaLoaded(List<Attachment> attachments) {
587        runOnUiThread(() -> {
588            int limit = GridManager.getCurrentColumnCount(binding.media);
589            mMediaAdapter.setAttachments(attachments.subList(0, Math.min(limit, attachments.size())));
590            binding.mediaWrapper.setVisibility(attachments.size() > 0 ? View.VISIBLE : View.GONE);
591        });
592
593    }
594}