Skip to content
This repository has been archived by the owner on Jan 11, 2021. It is now read-only.

Notification enhancement #31

Merged
merged 6 commits into from
Sep 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import com.alexstyl.specialdates.R;
import com.alexstyl.specialdates.analytics.Action;
import com.alexstyl.specialdates.analytics.Analytics;
import com.alexstyl.specialdates.analytics.ActionWithParameters;
import com.alexstyl.specialdates.analytics.Analytics;
import com.alexstyl.specialdates.analytics.Firebase;
import com.alexstyl.specialdates.service.DailyReminderIntentService;
import com.alexstyl.specialdates.ui.widget.TimePreference;
Expand Down
65 changes: 60 additions & 5 deletions mobile/src/main/java/com/alexstyl/specialdates/util/Notifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.StyleSpan;

import com.alexstyl.specialdates.R;
import com.alexstyl.specialdates.contact.Birthday;
import com.alexstyl.specialdates.contact.Contact;
import com.alexstyl.specialdates.date.ContactEvent;
import com.alexstyl.specialdates.date.Date;
import com.alexstyl.specialdates.datedetails.DateDetailsActivity;
import com.alexstyl.specialdates.events.ContactEvents;
import com.alexstyl.specialdates.events.EventType;
import com.alexstyl.specialdates.events.bankholidays.BankHoliday;
import com.alexstyl.specialdates.events.namedays.NamedayPreferences;
import com.alexstyl.specialdates.images.ImageLoader;
Expand Down Expand Up @@ -89,19 +96,48 @@ public void forDailyReminder(ContactEvents events) {
);

String title = NaturalLanguageUtils.joinContacts(context, events.getContacts(), 3);
String fullText = TextUtils.join(", ", events.getContacts());

NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_stat_contact_event)
.setContentTitle(title)
.setLargeIcon(largeIcon)
.setStyle(new NotificationCompat.BigTextStyle().bigText(fullText))
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
.setAutoCancel(true)
.setContentText(fullText)
.setContentIntent(intent)
.setNumber(events.size())
.setColor(context.getResources().getColor(R.color.main_red));

if (events.size() == 1) {
ContactEvent event = events.getEvent(0);
String msg = getLabelFor(event);

NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle().bigText(msg);
bigTextStyle.setBigContentTitle(title);
builder.setContentText(msg);

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

builder.setStyle(bigTextStyle);

} else if (events.getContacts().size() > 1) {
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
inboxStyle.setBigContentTitle(title);

for (int i = 0; i < events.size(); ++i) {

ContactEvent event = events.getEvent(i);
Contact contact = event.getContact();
String name = contact.getDisplayName().toString();

String lineFormatted = name + " " + getLabelFor(event);

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(", ", events.getContacts()));
}

if (supportsPublicNotifications()) {
String publicTitle = context.getString(R.string.contact_celebration_count, contactCount);
NotificationCompat.Builder publicNotification = new NotificationCompat.Builder(context)
Expand All @@ -114,8 +150,6 @@ public void forDailyReminder(ContactEvents events) {
builder.setPublicVersion(publicNotification.build());
}

builder.setNumber(contactCount);

for (Contact contact : events.getContacts()) {
Uri uri = contact.getLookupUri();
if (uri != null) {
Expand All @@ -137,6 +171,27 @@ public void forDailyReminder(ContactEvents events) {

}

/**
* TODO duplicated from {@link com.alexstyl.specialdates.upcoming.ui.ContactEventView#getLabelFor(ContactEvent)}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

*
* @deprecated
*/
private String getLabelFor(ContactEvent event) {
Resources resources = context.getResources();

EventType eventType = event.getType();
if (eventType == EventType.BIRTHDAY) {
Birthday birthday = event.getContact().getBirthday();
if (birthday.includesYear()) {
int age = birthday.getAgeOnYear(event.getYear());
if (age > 0) {
return resources.getString(R.string.turns_age, age);
}
}
}
return resources.getString(eventType.nameRes());
}

public static Bitmap getCircleBitmap(Bitmap bitmap) {
final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Bitmap.Config.ARGB_8888
Expand Down
1 change: 0 additions & 1 deletion secret.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ext {

// Replace the existing values with your own unique keys
crashlyticsKey = "1234567890123456789012345678901234567890"
androidVendingKey = "Include your vending key here"
Expand Down