Search in sources :

Example 1 with ContactEvent

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

the class DailyReminderIntentService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    Date today = getDayDateToDisplay();
    if (hasContactPermission()) {
        List<ContactEvent> celebrationDate = peopleEventsProvider.fetchEventsBetween(TimePeriod.Companion.between(today, today));
        if (containsAnyContactEvents(celebrationDate)) {
            notifier.forDailyReminder(today, celebrationDate);
        }
    }
    if (namedaysAreEnabledForAllCases()) {
        notifyForNamedaysFor(today);
    }
    if (bankholidaysAreEnabled()) {
        notifyForBankholidaysFor(today);
    }
    DailyReminderPreferences preferences = DailyReminderPreferences.newInstance(this);
    if (preferences.isEnabled()) {
        new DailyReminderScheduler(AlarmManagerCompat.from(this), this).setupReminder(preferences);
    }
}
Also used : ContactEvent(com.alexstyl.specialdates.date.ContactEvent) Date(com.alexstyl.specialdates.date.Date) NamesInADate(com.alexstyl.specialdates.events.namedays.NamesInADate)

Example 2 with ContactEvent

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

the class PeopleDynamicNamedaysProviderTest method gettingSpecialNamedaysOnSpecificDateOnlyReturnsTheEventsForThatDate.

@Test
public void gettingSpecialNamedaysOnSpecificDateOnlyReturnsTheEventsForThatDate() {
    List<Contact> testContacts = createSomeContacts();
    testContacts.add(EASTER_CELEBRATING_CONTACT);
    when(mockContactsProvider.getAllContacts()).thenReturn(testContacts);
    Date easterDate = OrthodoxEasterCalculator.INSTANCE.calculateEasterForYear(YEAR);
    List<ContactEvent> contactEvents = calculator.fetchEventsBetween(TimePeriod.Companion.between(easterDate, easterDate));
    assertThat(contactEvents).hasSize(1);
    assertThat(contactEvents.get(0).getContact()).isEqualTo(EASTER_CELEBRATING_CONTACT);
}
Also used : ContactEvent(com.alexstyl.specialdates.date.ContactEvent) Date(com.alexstyl.specialdates.date.Date) Contact(com.alexstyl.specialdates.contact.Contact) Test(org.junit.Test)

Example 3 with ContactEvent

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

the class ContactOperations method getAllDeviceEventsFor.

private List<ContactEvent> getAllDeviceEventsFor(Contact contact) {
    List<ContactEvent> contactEvents = new ArrayList<>();
    List<ContactEvent> contactEventsOnDate = peopleEventsProvider.fetchEventsBetween(TimePeriod.Companion.aYearFromNow());
    for (ContactEvent contactEvent : contactEventsOnDate) {
        Contact dbContact = contactEvent.getContact();
        if (dbContact.getContactID() == contact.getContactID() && contactEvent.getType() != StandardEventType.NAMEDAY) {
            contactEvents.add(contactEvent);
        }
    }
    return contactEvents;
}
Also used : ContactEvent(com.alexstyl.specialdates.date.ContactEvent) ArrayList(java.util.ArrayList) Contact(com.alexstyl.specialdates.contact.Contact)

Example 4 with ContactEvent

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

the class DailyReminderNotifier method forDailyReminder.

void forDailyReminder(Date date, List<ContactEvent> events) {
    Bitmap largeIcon = null;
    int contactCount = events.size();
    if (shouldDisplayContactImage(contactCount)) {
        Contact displayingContact = events.get(0).getContact();
        int size = dimensions.getPixelSize(android.R.dimen.notification_large_icon_width);
        Optional<Bitmap> loadedIcon = imageLoader.load(displayingContact.getImagePath()).withSize(size, size).synchronously();
        if (Version.hasLollipop() && loadedIcon.isPresent()) {
            // in Lollipop the notifications is the default to use Rounded Images
            largeIcon = getCircleBitmap(loadedIcon.get());
        }
    }
    Intent startIntent = HomeActivity.getStartIntent(context);
    PendingIntent intent = PendingIntent.getActivity(context, NOTIFICATION_ID_DAILY_REMINDER_CONTACTS, startIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    List<Contact> contacts = new ArrayList<>();
    for (ContactEvent event : events) {
        contacts.add(event.getContact());
    }
    String title = NaturalLanguageUtils.joinContacts(strings, contacts, MAX_CONTACTS);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_stat_memento).setContentTitle(title).setLargeIcon(largeIcon).setVisibility(NotificationCompat.VISIBILITY_PRIVATE).setAutoCancel(true).setContentIntent(intent).setNumber(events.size()).setColor(colors.getDailyReminderColor()).setSound(preferences.getRingtoneSelected());
    if (events.size() == 1) {
        ContactEvent event = events.get(0);
        String msg = event.getLabel(date, strings);
        NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle().bigText(msg);
        bigTextStyle.setBigContentTitle(title);
        builder.setContentText(msg);
        builder.setStyle(bigTextStyle);
    } else if (contacts.size() > 1) {
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        inboxStyle.setBigContentTitle(title);
        for (int i = 0; i < events.size(); ++i) {
            ContactEvent event = events.get(i);
            Contact contact = event.getContact();
            String name = contact.getDisplayName().toString();
            String lineFormatted = name + "\t\t" + event.getLabel(date, strings);
            Spannable sb = new SpannableString(lineFormatted);
            sb.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            inboxStyle.addLine(sb);
        }
        builder.setStyle(inboxStyle);
        builder.setContentText(TextUtils.join(", ", contacts));
    }
    if (supportsPublicNotifications()) {
        String publicTitle = context.getString(R.string.contact_celebration_count, contactCount);
        NotificationCompat.Builder publicNotification = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_stat_memento).setAutoCancel(true).setContentIntent(intent).setContentTitle(publicTitle).setColor(colors.getDailyReminderColor());
        builder.setPublicVersion(publicNotification.build());
    }
    if (preferences.getVibrationSet()) {
        builder.setDefaults(Notification.DEFAULT_VIBRATE);
    }
    Notification notification = builder.build();
    notificationManager.notify(NOTIFICATION_ID_DAILY_REMINDER_CONTACTS, notification);
}
Also used : ArrayList(java.util.ArrayList) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) SpannableString(android.text.SpannableString) Paint(android.graphics.Paint) Notification(android.app.Notification) Contact(com.alexstyl.specialdates.contact.Contact) SpannableString(android.text.SpannableString) Bitmap(android.graphics.Bitmap) ContactEvent(com.alexstyl.specialdates.date.ContactEvent) StyleSpan(android.text.style.StyleSpan) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) Spannable(android.text.Spannable)

Example 5 with ContactEvent

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

the class FacebookContactFactory method createContactFrom.

ContactEvent createContactFrom(Map<String, String> map) throws InvalidFacebookContactException {
    try {
        Date date = dateFrom(map);
        DisplayName name = nameFrom(map);
        long uid = idOf(map);
        URI imagePath = FacebookImagePath.INSTANCE.forUid(uid);
        return new ContactEvent(Optional.Companion.<Long>absent(), StandardEventType.BIRTHDAY, date, new Contact(uid, name, imagePath, SOURCE_FACEBOOK));
    } catch (DateParseException | IndexOutOfBoundsException ex) {
        throw new InvalidFacebookContactException(ex);
    }
}
Also used : ContactEvent(com.alexstyl.specialdates.date.ContactEvent) DateParseException(com.alexstyl.specialdates.date.DateParseException) DisplayName(com.alexstyl.specialdates.contact.DisplayName) URI(java.net.URI) Date(com.alexstyl.specialdates.date.Date) 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