use of com.alexstyl.specialdates.date.ContactEvent in project Memento-Calendar by alexstyl.
the class ContactEventSerialiser method createEventsFrom.
List<ContactEvent> createEventsFrom(InputStream inputStream) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
String line;
List<ContactEvent> contactEvents = new ArrayList<>();
Map<String, String> map = null;
while ((line = reader.readLine()) != null) {
if (EVENT_START.equals(line)) {
map = new HashMap<>();
} else if (EVENT_END.equals(line)) {
try {
ContactEvent contactEvent = factory.createContactFrom(map);
contactEvents.add(contactEvent);
} catch (InvalidFacebookContactException ex) {
tracker.track(ex);
}
} else if (line.startsWith(EVENT_DATE)) {
parse(line, map, EVENT_DATE);
} else if (line.startsWith(EVENT_SUMMARY)) {
parse(line, map, EVENT_SUMMARY);
} else if (line.startsWith(EVENT_UID)) {
parse(line, map, EVENT_UID);
}
}
return contactEvents;
}
use of com.alexstyl.specialdates.date.ContactEvent in project Memento-Calendar by alexstyl.
the class FacebookBirthdaysProviderTest method parsingRandomURLreturnsNoEvents.
@Test
public void parsingRandomURLreturnsNoEvents() throws CalendarFetcherException, MalformedURLException {
FacebookContactFactory factory = new FacebookContactFactory(parser);
FacebookBirthdaysProvider fetcher = new FacebookBirthdaysProvider(new FacebookCalendarLoader(), new ContactEventSerialiser(factory, tracker));
URL url = new URL("https://www.google.com");
List<ContactEvent> contactEvents = fetcher.fetchCalendarFrom(url);
assertThat(contactEvents.isEmpty());
}
use of com.alexstyl.specialdates.date.ContactEvent in project Memento-Calendar by alexstyl.
the class EventLabelCreatorTest method birthdayWithYearIsCalculatedCorrectly.
@Test
public void birthdayWithYearIsCalculatedCorrectly() {
int age = Date.Companion.getCURRENT_YEAR() - 1990;
Date date = Date.Companion.on(12, DECEMBER, 1990);
ContactEvent event = contactEventOn(date, BIRTHDAY);
String label = creator.createFor(event);
assertThat(label).isEqualTo("Turns " + age + " on December 12");
}
use of com.alexstyl.specialdates.date.ContactEvent in project Memento-Calendar by alexstyl.
the class EventLabelCreatorTest method customIsCalculatedCorrectly.
@Test
public void customIsCalculatedCorrectly() {
Date date = Date.Companion.on(12, DECEMBER);
ContactEvent event = contactEventOn(date, new CustomEventType("H4x"));
String label = creator.createFor(event);
assertThat(label).isEqualTo("H4x on December 12");
}
use of com.alexstyl.specialdates.date.ContactEvent 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;
}
Aggregations