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