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