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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations