use of org.thoughtcrime.securesms.contactshare.Contact.Phone in project Signal-Android by signalapp.
the class ContactModelMapper method localToRemoteBuilder.
public static SharedContact.Builder localToRemoteBuilder(@NonNull Contact contact) {
List<SharedContact.Phone> phoneNumbers = new ArrayList<>(contact.getPhoneNumbers().size());
List<SharedContact.Email> emails = new ArrayList<>(contact.getEmails().size());
List<SharedContact.PostalAddress> postalAddresses = new ArrayList<>(contact.getPostalAddresses().size());
for (Phone phone : contact.getPhoneNumbers()) {
phoneNumbers.add(new SharedContact.Phone.Builder().setValue(phone.getNumber()).setType(localToRemoteType(phone.getType())).setLabel(phone.getLabel()).build());
}
for (Email email : contact.getEmails()) {
emails.add(new SharedContact.Email.Builder().setValue(email.getEmail()).setType(localToRemoteType(email.getType())).setLabel(email.getLabel()).build());
}
for (PostalAddress postalAddress : contact.getPostalAddresses()) {
postalAddresses.add(new SharedContact.PostalAddress.Builder().setType(localToRemoteType(postalAddress.getType())).setLabel(postalAddress.getLabel()).setStreet(postalAddress.getStreet()).setPobox(postalAddress.getPoBox()).setNeighborhood(postalAddress.getNeighborhood()).setCity(postalAddress.getCity()).setRegion(postalAddress.getRegion()).setPostcode(postalAddress.getPostalCode()).setCountry(postalAddress.getCountry()).build());
}
SharedContact.Name name = new SharedContact.Name.Builder().setDisplay(contact.getName().getDisplayName()).setGiven(contact.getName().getGivenName()).setFamily(contact.getName().getFamilyName()).setPrefix(contact.getName().getPrefix()).setSuffix(contact.getName().getSuffix()).setMiddle(contact.getName().getMiddleName()).build();
return new SharedContact.Builder().setName(name).withOrganization(contact.getOrganization()).withPhones(phoneNumbers).withEmails(emails).withAddresses(postalAddresses);
}
use of org.thoughtcrime.securesms.contactshare.Contact.Phone in project Signal-Android by signalapp.
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);
}
use of org.thoughtcrime.securesms.contactshare.Contact.Phone in project Signal-Android by signalapp.
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;
}
Aggregations