Search in sources :

Example 1 with Email

use of org.thoughtcrime.securesms.contactshare.Contact.Email in project Signal-Android by WhisperSystems.

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);
}
Also used : Email(org.thoughtcrime.securesms.contactshare.Contact.Email) ArrayList(java.util.ArrayList) Name(org.thoughtcrime.securesms.contactshare.Contact.Name) PostalAddress(org.thoughtcrime.securesms.contactshare.Contact.PostalAddress) Phone(org.thoughtcrime.securesms.contactshare.Contact.Phone) SharedContact(org.whispersystems.signalservice.api.messages.shared.SharedContact)

Example 2 with Email

use of org.thoughtcrime.securesms.contactshare.Contact.Email 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 3 with Email

use of org.thoughtcrime.securesms.contactshare.Contact.Email in project Signal-Android by WhisperSystems.

the class ContactModelMapper method remoteToLocal.

public static Contact remoteToLocal(@NonNull SharedContact sharedContact) {
    Name name = new Name(sharedContact.getName().getDisplay().orNull(), sharedContact.getName().getGiven().orNull(), sharedContact.getName().getFamily().orNull(), sharedContact.getName().getPrefix().orNull(), sharedContact.getName().getSuffix().orNull(), sharedContact.getName().getMiddle().orNull());
    List<Phone> phoneNumbers = new LinkedList<>();
    if (sharedContact.getPhone().isPresent()) {
        for (SharedContact.Phone phone : sharedContact.getPhone().get()) {
            phoneNumbers.add(new Phone(phone.getValue(), remoteToLocalType(phone.getType()), phone.getLabel().orNull()));
        }
    }
    List<Email> emails = new LinkedList<>();
    if (sharedContact.getEmail().isPresent()) {
        for (SharedContact.Email email : sharedContact.getEmail().get()) {
            emails.add(new Email(email.getValue(), remoteToLocalType(email.getType()), email.getLabel().orNull()));
        }
    }
    List<PostalAddress> postalAddresses = new LinkedList<>();
    if (sharedContact.getAddress().isPresent()) {
        for (SharedContact.PostalAddress postalAddress : sharedContact.getAddress().get()) {
            postalAddresses.add(new PostalAddress(remoteToLocalType(postalAddress.getType()), postalAddress.getLabel().orNull(), postalAddress.getStreet().orNull(), postalAddress.getPobox().orNull(), postalAddress.getNeighborhood().orNull(), postalAddress.getCity().orNull(), postalAddress.getRegion().orNull(), postalAddress.getPostcode().orNull(), postalAddress.getCountry().orNull()));
        }
    }
    Avatar avatar = null;
    if (sharedContact.getAvatar().isPresent()) {
        Attachment attachment = PointerAttachment.forPointer(Optional.of(sharedContact.getAvatar().get().getAttachment().asPointer())).get();
        boolean isProfile = sharedContact.getAvatar().get().isProfile();
        avatar = new Avatar(null, attachment, isProfile);
    }
    return new Contact(name, sharedContact.getOrganization().orNull(), phoneNumbers, emails, postalAddresses, avatar);
}
Also used : Email(org.thoughtcrime.securesms.contactshare.Contact.Email) PointerAttachment(org.thoughtcrime.securesms.attachments.PointerAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) LinkedList(java.util.LinkedList) Avatar(org.thoughtcrime.securesms.contactshare.Contact.Avatar) Name(org.thoughtcrime.securesms.contactshare.Contact.Name) SharedContact(org.whispersystems.signalservice.api.messages.shared.SharedContact) PostalAddress(org.thoughtcrime.securesms.contactshare.Contact.PostalAddress) Phone(org.thoughtcrime.securesms.contactshare.Contact.Phone) SharedContact(org.whispersystems.signalservice.api.messages.shared.SharedContact)

Example 4 with Email

use of org.thoughtcrime.securesms.contactshare.Contact.Email in project Signal-Android by signalapp.

the class ContactModelMapper method remoteToLocal.

public static Contact remoteToLocal(@NonNull SharedContact sharedContact) {
    Name name = new Name(sharedContact.getName().getDisplay().orNull(), sharedContact.getName().getGiven().orNull(), sharedContact.getName().getFamily().orNull(), sharedContact.getName().getPrefix().orNull(), sharedContact.getName().getSuffix().orNull(), sharedContact.getName().getMiddle().orNull());
    List<Phone> phoneNumbers = new LinkedList<>();
    if (sharedContact.getPhone().isPresent()) {
        for (SharedContact.Phone phone : sharedContact.getPhone().get()) {
            phoneNumbers.add(new Phone(phone.getValue(), remoteToLocalType(phone.getType()), phone.getLabel().orNull()));
        }
    }
    List<Email> emails = new LinkedList<>();
    if (sharedContact.getEmail().isPresent()) {
        for (SharedContact.Email email : sharedContact.getEmail().get()) {
            emails.add(new Email(email.getValue(), remoteToLocalType(email.getType()), email.getLabel().orNull()));
        }
    }
    List<PostalAddress> postalAddresses = new LinkedList<>();
    if (sharedContact.getAddress().isPresent()) {
        for (SharedContact.PostalAddress postalAddress : sharedContact.getAddress().get()) {
            postalAddresses.add(new PostalAddress(remoteToLocalType(postalAddress.getType()), postalAddress.getLabel().orNull(), postalAddress.getStreet().orNull(), postalAddress.getPobox().orNull(), postalAddress.getNeighborhood().orNull(), postalAddress.getCity().orNull(), postalAddress.getRegion().orNull(), postalAddress.getPostcode().orNull(), postalAddress.getCountry().orNull()));
        }
    }
    Avatar avatar = null;
    if (sharedContact.getAvatar().isPresent()) {
        Attachment attachment = PointerAttachment.forPointer(Optional.of(sharedContact.getAvatar().get().getAttachment().asPointer())).get();
        boolean isProfile = sharedContact.getAvatar().get().isProfile();
        avatar = new Avatar(null, attachment, isProfile);
    }
    return new Contact(name, sharedContact.getOrganization().orNull(), phoneNumbers, emails, postalAddresses, avatar);
}
Also used : Email(org.thoughtcrime.securesms.contactshare.Contact.Email) PointerAttachment(org.thoughtcrime.securesms.attachments.PointerAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) LinkedList(java.util.LinkedList) Avatar(org.thoughtcrime.securesms.contactshare.Contact.Avatar) Name(org.thoughtcrime.securesms.contactshare.Contact.Name) SharedContact(org.whispersystems.signalservice.api.messages.shared.SharedContact) PostalAddress(org.thoughtcrime.securesms.contactshare.Contact.PostalAddress) Phone(org.thoughtcrime.securesms.contactshare.Contact.Phone) SharedContact(org.whispersystems.signalservice.api.messages.shared.SharedContact)

Example 5 with Email

use of org.thoughtcrime.securesms.contactshare.Contact.Email 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);
}
Also used : Email(org.thoughtcrime.securesms.contactshare.Contact.Email) ArrayList(java.util.ArrayList) Name(org.thoughtcrime.securesms.contactshare.Contact.Name) PostalAddress(org.thoughtcrime.securesms.contactshare.Contact.PostalAddress) Phone(org.thoughtcrime.securesms.contactshare.Contact.Phone) SharedContact(org.whispersystems.signalservice.api.messages.shared.SharedContact)

Aggregations

Email (org.thoughtcrime.securesms.contactshare.Contact.Email)6 LinkedList (java.util.LinkedList)4 Name (org.thoughtcrime.securesms.contactshare.Contact.Name)4 Phone (org.thoughtcrime.securesms.contactshare.Contact.Phone)4 PostalAddress (org.thoughtcrime.securesms.contactshare.Contact.PostalAddress)4 SharedContact (org.whispersystems.signalservice.api.messages.shared.SharedContact)4 Cursor (android.database.Cursor)2 NonNull (androidx.annotation.NonNull)2 WorkerThread (androidx.annotation.WorkerThread)2 ArrayList (java.util.ArrayList)2 Attachment (org.thoughtcrime.securesms.attachments.Attachment)2 PointerAttachment (org.thoughtcrime.securesms.attachments.PointerAttachment)2 Avatar (org.thoughtcrime.securesms.contactshare.Contact.Avatar)2