Search in sources :

Example 71 with WorkerThread

use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.

the class SharedContactRepository method getContactFromVcard.

@WorkerThread
@Nullable
private Contact getContactFromVcard(@NonNull Uri uri) {
    Contact contact = null;
    try (InputStream stream = PartAuthority.getAttachmentStream(context, uri)) {
        VCard vcard = Ezvcard.parse(stream).first();
        contact = VCardUtil.getContactFromVcard(vcard);
    } catch (IOException e) {
        Log.w(TAG, "Failed to parse the vcard.", e);
    }
    if (BlobProvider.AUTHORITY.equals(uri.getAuthority())) {
        BlobProvider.getInstance().delete(context, uri);
    }
    return contact;
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) VCard(ezvcard.VCard) WorkerThread(androidx.annotation.WorkerThread) Nullable(androidx.annotation.Nullable)

Example 72 with WorkerThread

use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.

the class SharedContactRepository method getEmails.

@WorkerThread
@NonNull
private List<Email> getEmails(long contactId) {
    List<Email> emails = new LinkedList<>();
    try (Cursor cursor = contactsDatabase.getEmailDetails(contactId)) {
        while (cursor != null && cursor.moveToNext()) {
            String cursorEmail = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Email.ADDRESS));
            int cursorType = cursor.getInt(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Email.TYPE));
            String cursorLabel = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Email.LABEL));
            emails.add(new Email(cursorEmail, VCardUtil.emailTypeFromContactType(cursorType), cursorLabel));
        }
    }
    return emails;
}
Also used : Email(org.thoughtcrime.securesms.contactshare.Contact.Email) Cursor(android.database.Cursor) LinkedList(java.util.LinkedList) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 73 with WorkerThread

use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.

the class SharedContactRepository method getRecipientAvatarInfo.

@WorkerThread
@Nullable
private AvatarInfo getRecipientAvatarInfo(String address) {
    Recipient recipient = Recipient.external(context, address);
    ContactPhoto contactPhoto = recipient.getContactPhoto();
    if (contactPhoto != null) {
        Uri avatarUri = contactPhoto.getUri(context);
        if (avatarUri != null) {
            return new AvatarInfo(avatarUri, contactPhoto.isProfilePhoto());
        }
    }
    return null;
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient) ContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ContactPhoto) Uri(android.net.Uri) WorkerThread(androidx.annotation.WorkerThread) Nullable(androidx.annotation.Nullable)

Example 74 with WorkerThread

use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.

the class SharedContactRepository method getPhoneNumbers.

@WorkerThread
@NonNull
private List<Phone> getPhoneNumbers(long contactId) {
    Map<String, Phone> numberMap = new HashMap<>();
    try (Cursor cursor = contactsDatabase.getPhoneDetails(contactId)) {
        while (cursor != null && cursor.moveToNext()) {
            String cursorNumber = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER));
            int cursorType = cursor.getInt(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.TYPE));
            String cursorLabel = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.LABEL));
            String number = ContactUtil.getNormalizedPhoneNumber(context, cursorNumber);
            Phone existing = numberMap.get(number);
            Phone candidate = new Phone(number, VCardUtil.phoneTypeFromContactType(cursorType), cursorLabel);
            if (existing == null || (existing.getType() == Phone.Type.CUSTOM && existing.getLabel() == null)) {
                numberMap.put(number, candidate);
            }
        }
    }
    List<Phone> numbers = new ArrayList<>(numberMap.size());
    numbers.addAll(numberMap.values());
    return numbers;
}
Also used : HashMap(java.util.HashMap) Phone(org.thoughtcrime.securesms.contactshare.Contact.Phone) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 75 with WorkerThread

use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.

the class SharedContactRepository method getContactFromSystemContacts.

@WorkerThread
@Nullable
private Contact getContactFromSystemContacts(long contactId) {
    Name name = getName(contactId);
    if (name == null) {
        Log.w(TAG, "Couldn't find a name associated with the provided contact ID.");
        return null;
    }
    List<Phone> phoneNumbers = getPhoneNumbers(contactId);
    AvatarInfo avatarInfo = getAvatarInfo(contactId, phoneNumbers);
    Avatar avatar = avatarInfo != null ? new Avatar(avatarInfo.uri, avatarInfo.isProfile) : null;
    return new Contact(name, null, phoneNumbers, getEmails(contactId), getPostalAddresses(contactId), avatar);
}
Also used : Phone(org.thoughtcrime.securesms.contactshare.Contact.Phone) Avatar(org.thoughtcrime.securesms.contactshare.Contact.Avatar) Name(org.thoughtcrime.securesms.contactshare.Contact.Name) WorkerThread(androidx.annotation.WorkerThread) Nullable(androidx.annotation.Nullable)

Aggregations

WorkerThread (androidx.annotation.WorkerThread)365 NonNull (androidx.annotation.NonNull)151 IOException (java.io.IOException)83 Recipient (org.thoughtcrime.securesms.recipients.Recipient)82 Nullable (androidx.annotation.Nullable)51 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)46 Cursor (android.database.Cursor)41 ArrayList (java.util.ArrayList)41 Context (android.content.Context)39 Uri (android.net.Uri)32 LinkedList (java.util.LinkedList)30 List (java.util.List)30 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)28 Stream (com.annimon.stream.Stream)26 HashMap (java.util.HashMap)26 Log (org.signal.core.util.logging.Log)26 HashSet (java.util.HashSet)24 Map (java.util.Map)21 Collections (java.util.Collections)20 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)20