Search in sources :

Example 6 with Contact

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

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);
}
Also used : ArrayList(java.util.ArrayList) Contact(com.alexstyl.specialdates.contact.Contact)

Example 8 with Contact

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

Example 9 with Contact

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

Example 10 with Contact

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

Aggregations

Contact (com.alexstyl.specialdates.contact.Contact)21 Test (org.junit.Test)10 ContactEvent (com.alexstyl.specialdates.date.ContactEvent)9 ArrayList (java.util.ArrayList)8 Date (com.alexstyl.specialdates.date.Date)6 ContactsProvider (com.alexstyl.specialdates.contact.ContactsProvider)5 ContactEventsOnADate (com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 UpcomingEventsView (com.alexstyl.specialdates.UpcomingEventsView)2 DisplayName (com.alexstyl.specialdates.contact.DisplayName)2 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 Nullable (android.support.annotation.Nullable)1 NotificationCompat (android.support.v4.app.NotificationCompat)1