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