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