Search in sources :

Example 16 with Contact

use of com.alexstyl.specialdates.contact.Contact in project Memento-Calendar by alexstyl.

the class ContactsSearchTest method canFindFirstname.

@Test
public void canFindFirstname() {
    ContactsProvider contactsProvider = mock(ContactsProvider.class);
    when(contactsProvider.getAllContacts()).thenReturn(contacts("Alex Styl", "Alex Evil Twin", "Anna Papadopoulou"));
    ContactsSearch search = new ContactsSearch(contactsProvider, NameMatcher.INSTANCE);
    List<Contact> oneContact = search.searchForContacts("Anna", 1);
    assertThat(oneContact.size()).isEqualTo(1);
    assertThat(oneContact.get(0).getDisplayName().toString()).isEqualTo("Anna Papadopoulou");
}
Also used : ContactsProvider(com.alexstyl.specialdates.contact.ContactsProvider) Contact(com.alexstyl.specialdates.contact.Contact) Test(org.junit.Test)

Example 17 with Contact

use of com.alexstyl.specialdates.contact.Contact in project Memento-Calendar by alexstyl.

the class ContactsSearch method searchForContacts.

List<Contact> searchForContacts(String searchQuery, int numberOfResults) {
    List<Contact> matchedContacts = new ArrayList<>();
    if (numberOfResults == 0) {
        return matchedContacts;
    }
    searchQuery = searchQuery.trim();
    List<Contact> allContacts = contactsProvider.getAllContacts();
    if (allContacts.size() == 0) {
        return matchedContacts;
    }
    int count = 0;
    int index = 0;
    int contactSize = allContacts.size();
    do {
        Contact contact = allContacts.get(index);
        DisplayName displayName = contact.getDisplayName();
        if (nameMatcher.match(displayName, searchQuery)) {
            matchedContacts.add(contact);
            count++;
        }
        index++;
    } while (count < numberOfResults && index < contactSize);
    return matchedContacts;
}
Also used : ArrayList(java.util.ArrayList) DisplayName(com.alexstyl.specialdates.contact.DisplayName) Contact(com.alexstyl.specialdates.contact.Contact)

Example 18 with Contact

use of com.alexstyl.specialdates.contact.Contact in project Memento-Calendar by alexstyl.

the class ContactSuggestionViewHolder method bind.

public void bind(final ContactDetailsListener listener) {
    contactSuggestionView.setOnContactSelectedListener(new ContactSuggestionView.OnContactSelectedListener() {

        @Override
        public void onContactSelected(Contact contact) {
            listener.onContactSelected(contact);
        }

        @Override
        public void onContactCleared() {
            listener.onContactCleared();
        }
    });
    contactSuggestionView.addTextChangedListener(new SimpleTextWatcher() {

        @Override
        public void afterTextChanged(Editable text) {
            listener.onNameModified(text.toString());
        }
    });
}
Also used : SimpleTextWatcher(com.novoda.notils.text.SimpleTextWatcher) ContactSuggestionView(com.alexstyl.specialdates.addevent.ui.ContactSuggestionView) Editable(android.text.Editable) Contact(com.alexstyl.specialdates.contact.Contact)

Example 19 with Contact

use of com.alexstyl.specialdates.contact.Contact in project Memento-Calendar by alexstyl.

the class PeopleEventsSearch method searchForContacts.

List<ContactWithEvents> searchForContacts(String searchQuery, int counter) {
    if (counter <= 0) {
        return new ArrayList<>();
    }
    searchQuery = searchQuery.trim();
    HashMapList<Contact, ContactEvent> events = new HashMapList<>();
    TimePeriod between = TimePeriod.Companion.aYearFromNow();
    List<ContactEvent> contactEventsOnDate = peopleEventsProvider.fetchEventsBetween(between);
    int size = 0;
    for (ContactEvent contactEvent : contactEventsOnDate) {
        Contact contact = contactEvent.getContact();
        if (nameMatcher.match(contact.getDisplayName(), searchQuery)) {
            events.addValue(contact, contactEvent);
            size++;
        }
        if (size >= counter) {
            break;
        }
    }
    List<ContactWithEvents> contactWithEvents = new ArrayList<>();
    for (Contact contact : events.keys()) {
        List<ContactEvent> list = events.get(contact);
        contactWithEvents.add(new ContactWithEvents(contact, list));
    }
    return contactWithEvents;
}
Also used : ContactEvent(com.alexstyl.specialdates.date.ContactEvent) TimePeriod(com.alexstyl.specialdates.date.TimePeriod) ArrayList(java.util.ArrayList) HashMapList(com.alexstyl.specialdates.util.HashMapList) Contact(com.alexstyl.specialdates.contact.Contact)

Example 20 with Contact

use of com.alexstyl.specialdates.contact.Contact in project Memento-Calendar by alexstyl.

the class ContactActionTest method testContactsAreCorrectlyReturned.

@Test
public void testContactsAreCorrectlyReturned() {
    Date date = Date.Companion.on(1, JANUARY, 2016);
    ArrayList<ContactEvent> contactEvent = new ArrayList<>();
    contactEvent.add(EVENT_ONE);
    contactEvent.add(EVENT_TWO);
    ContactEventsOnADate events = ContactEventsOnADate.Companion.createFrom(date, contactEvent);
    List<Contact> contacts = events.getContacts();
    assertThat(contacts).contains(CONTACT_ONE);
    assertThat(contacts).contains(CONTACT_TWO);
}
Also used : ContactEvent(com.alexstyl.specialdates.date.ContactEvent) ArrayList(java.util.ArrayList) ContactEventsOnADate(com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate) ContactEventsOnADate(com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate) Date(com.alexstyl.specialdates.date.Date) Contact(com.alexstyl.specialdates.contact.Contact) Test(org.junit.Test)

Aggregations

Contact (com.alexstyl.specialdates.contact.Contact)21 Test (org.junit.Test)10 ContactEvent (com.alexstyl.specialdates.date.ContactEvent)9 ArrayList (java.util.ArrayList)8 Date (com.alexstyl.specialdates.date.Date)6 ContactsProvider (com.alexstyl.specialdates.contact.ContactsProvider)5 ContactEventsOnADate (com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 UpcomingEventsView (com.alexstyl.specialdates.UpcomingEventsView)2 DisplayName (com.alexstyl.specialdates.contact.DisplayName)2 Notification (android.app.Notification)1 PendingIntent (android.app.PendingIntent)1 ContentValues (android.content.ContentValues)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 Paint (android.graphics.Paint)1 Nullable (android.support.annotation.Nullable)1 NotificationCompat (android.support.v4.app.NotificationCompat)1