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