-
Notifications
You must be signed in to change notification settings - Fork 50
Notification enhancement #31
Changes from 4 commits
c895d25
95d13f2
31d07c6
3d9388b
f496039
77498ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,15 +14,21 @@ | |
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.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; | ||
|
@@ -89,19 +95,66 @@ 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 = ""; | ||
|
||
if (EventType.BIRTHDAY.equals(event.getType())) { | ||
int age = event.getContact().getBirthday().getAgeOnYear(event.getYear()); | ||
msg = context.getString(R.string.turns_age, age); | ||
|
||
} else if (EventType.NAMEDAY.equals(event.getType())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
msg = context.getString(R.string.nameday); | ||
} | ||
|
||
NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle().bigText(msg); | ||
bigTextStyle.setBigContentTitle(title); | ||
builder.setContentText(msg); | ||
|
||
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; | ||
|
||
if (EventType.BIRTHDAY.equals(event.getType())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ This is hard to extend. What happens when more events are added in the future? We would have to check all bits of code that do checks with specific events. Also, a Birthday might not include a year of birth, which means that the following bit will throw an exception if the contact does not have a specified year of birth. You could just copy-paste the Don't worry about the code duplication from the other class. I'll solve it nicely in a later PR :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copy Paste! Oh no! I'm going to create an issue as well so that it is not forgotten |
||
int age = contact.getBirthday().getAgeOnYear(events.getDate().getYear()); | ||
|
||
lineFormatted += " " + context.getString(R.string.turns_age, age); | ||
|
||
} else if (EventType.NAMEDAY.equals(event.getType())) { | ||
lineFormatted += " " + context.getString(R.string.nameday); | ||
|
||
} | ||
|
||
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) | ||
|
@@ -114,8 +167,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) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we have the
getLabelFor()
in place. Why not use it here as well? :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is not a good first impression I'm giving right now 😳
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are making a contribution to the project. You have made the best impression already so don't you worry about it :)