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