use of com.alexstyl.specialdates.contact.Contact 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.contact.Contact in project Memento-Calendar by alexstyl.
the class NaturalLanguageUtils method joinContacts.
public static String joinContacts(Strings strings, Collection<Contact> iterable, int displayNo) {
int size = iterable.size();
if (size == 1) {
return iterable.iterator().next().getDisplayName().toString();
}
ArrayList<String> names = new ArrayList<>(size);
for (Contact contact : iterable) {
names.add(contact.getGivenName());
}
return join(strings, names, displayNo);
}
use of com.alexstyl.specialdates.contact.Contact 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);
}
}
use of com.alexstyl.specialdates.contact.Contact in project Memento-Calendar by alexstyl.
the class FacebookContactFactoryTest method name.
@Test
public void name() throws DateParseException, InvalidFacebookContactException {
HashMap<String, String> map = new HashMap<>();
map.put("UID", "b123124@facebook.com");
map.put("DTSTART", "20180612");
map.put("SUMMARY", "Thanasis Thomopoulos's birthday");
ContactEvent contactEvent = factory.createContactFrom(map);
Contact contact = contactEvent.getContact();
assertThat(contact.getDisplayName()).isEqualTo(DisplayName.Companion.from("Thanasis Thomopoulos"));
assertThat(contact.getContactID()).isEqualTo(123124);
}
use of com.alexstyl.specialdates.contact.Contact 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);
}
Aggregations