Search in sources :

Example 11 with ContactEvent

use of com.alexstyl.specialdates.date.ContactEvent in project Memento-Calendar by alexstyl.

the class EventLabelCreatorTest method otherIsCalculatedCorrectly.

@Test
public void otherIsCalculatedCorrectly() {
    Date date = Date.Companion.on(12, DECEMBER);
    ContactEvent event = contactEventOn(date, OTHER);
    String label = creator.createFor(event);
    assertThat(label).isEqualTo("Other on December 12");
}
Also used : ContactEvent(com.alexstyl.specialdates.date.ContactEvent) Date(com.alexstyl.specialdates.date.Date) Test(org.junit.Test)

Example 12 with ContactEvent

use of com.alexstyl.specialdates.date.ContactEvent in project Memento-Calendar by alexstyl.

the class ContactActionTest method testReturnedContactsSizeIsCorrect.

@Test
public void testReturnedContactsSizeIsCorrect() {
    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.size()).isEqualTo(2);
}
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)

Example 13 with ContactEvent

use of com.alexstyl.specialdates.date.ContactEvent in project Memento-Calendar by alexstyl.

the class FacebookFriendsIntentService method onHandleIntent.

@Override
protected void onHandleIntent(@Nullable Intent intent) {
    FacebookCalendarLoader calendarLoader = new FacebookCalendarLoader();
    FacebookContactFactory factory = new FacebookContactFactory(parser);
    ContactEventSerialiser serialiser = new ContactEventSerialiser(factory, tracker);
    FacebookBirthdaysProvider calendarFetcher = new FacebookBirthdaysProvider(calendarLoader, serialiser);
    UserCredentials userCredentials = facebookUserSettings.retrieveCredentials();
    if (isAnnonymous(userCredentials)) {
        tracker.track(new RuntimeException("Tried to fetch events, but was anonymous"));
        return;
    }
    CalendarURLCreator calendarURLCreator = new CalendarURLCreator(tracker);
    URL calendarUrl = calendarURLCreator.createFrom(userCredentials);
    FacebookFriendsPersister persister = new FacebookFriendsPersister(new AndroidPeopleEventsPersister(new EventSQLiteOpenHelper(this), marshaller, tracker));
    try {
        List<ContactEvent> friends = calendarFetcher.fetchCalendarFrom(calendarUrl);
        persister.keepOnly(friends);
        uiRefresher.refreshViews();
    } catch (CalendarFetcherException e) {
        tracker.track(e);
    }
    if (BuildConfig.DEBUG) {
        notifyServiceRan();
    }
}
Also used : EventSQLiteOpenHelper(com.alexstyl.specialdates.events.database.EventSQLiteOpenHelper) URL(java.net.URL) ContactEvent(com.alexstyl.specialdates.date.ContactEvent) AndroidPeopleEventsPersister(com.alexstyl.specialdates.events.peopleevents.AndroidPeopleEventsPersister) UserCredentials(com.alexstyl.specialdates.facebook.UserCredentials)

Example 14 with ContactEvent

use of com.alexstyl.specialdates.date.ContactEvent in project Memento-Calendar by alexstyl.

the class ContactEventsMarshaller method marshall.

public ContentValues[] marshall(List<ContactEvent> item) {
    ContentValues[] returningValues = new ContentValues[item.size()];
    for (int i = 0; i < item.size(); i++) {
        ContactEvent event = item.get(i);
        returningValues[i] = createValuesFor(event);
    }
    return returningValues;
}
Also used : ContentValues(android.content.ContentValues) ContactEvent(com.alexstyl.specialdates.date.ContactEvent)

Example 15 with ContactEvent

use of com.alexstyl.specialdates.date.ContactEvent in project Memento-Calendar by alexstyl.

the class ContactEventsLoader method createModelsFor.

private List<AddEventContactEventViewModel> createModelsFor(Contact contact) {
    List<AddEventContactEventViewModel> existingViewModels;
    List<ContactEvent> contactEvents = new ArrayList<>();
    List<ContactEvent> contactEventsOnDate = peopleEventsProvider.fetchEventsBetween(TimePeriod.Companion.aYearFromNow());
    List<EventType> existingTypes = new ArrayList<>();
    for (ContactEvent contactEvent : contactEventsOnDate) {
        if (contactEvent.getContact().getContactID() == contact.getContactID() && isEditable(contactEvent)) {
            contactEvents.add(contactEvent);
            existingTypes.add(contactEvent.getType());
        }
    }
    existingViewModels = factory.createViewModel(contactEvents);
    List<AddEventContactEventViewModel> emptyViewModels = newEventFactory.createViewModelsForAllEventsBut(existingTypes);
    existingViewModels.addAll(emptyViewModels);
    return existingViewModels;
}
Also used : ContactEvent(com.alexstyl.specialdates.date.ContactEvent) EventType(com.alexstyl.specialdates.events.peopleevents.EventType) StandardEventType(com.alexstyl.specialdates.events.peopleevents.StandardEventType) ArrayList(java.util.ArrayList)

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