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