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