Search in sources :

Example 16 with ContactEvent

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;
}
Also used : ContactEvent(com.alexstyl.specialdates.date.ContactEvent) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList)

Example 17 with ContactEvent

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());
}
Also used : ContactEvent(com.alexstyl.specialdates.date.ContactEvent) URL(java.net.URL) Test(org.junit.Test)

Example 18 with ContactEvent

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");
}
Also used : ContactEvent(com.alexstyl.specialdates.date.ContactEvent) Date(com.alexstyl.specialdates.date.Date) Test(org.junit.Test)

Example 19 with ContactEvent

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");
}
Also used : ContactEvent(com.alexstyl.specialdates.date.ContactEvent) CustomEventType(com.alexstyl.specialdates.events.peopleevents.CustomEventType) Date(com.alexstyl.specialdates.date.Date) Test(org.junit.Test)

Example 20 with ContactEvent

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;
}
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)

Aggregations

ContactEvent (com.alexstyl.specialdates.date.ContactEvent)22 Test (org.junit.Test)13 Date (com.alexstyl.specialdates.date.Date)12 Contact (com.alexstyl.specialdates.contact.Contact)9 ArrayList (java.util.ArrayList)8 ContactEventsOnADate (com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate)3 URL (java.net.URL)3 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 NotificationCompat (android.support.v4.app.NotificationCompat)1 Spannable (android.text.Spannable)1 SpannableString (android.text.SpannableString)1 StyleSpan (android.text.style.StyleSpan)1 DisplayName (com.alexstyl.specialdates.contact.DisplayName)1 DateParseException (com.alexstyl.specialdates.date.DateParseException)1 TimePeriod (com.alexstyl.specialdates.date.TimePeriod)1