This repository has been archived by the owner on Jan 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Notification enhancement #31
Merged
alexstyl
merged 6 commits into
alexstyl:develop
from
auricgoldfinger:notification-enhancement
Sep 8, 2016
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c895d25
Add inbox style + contact age
auricgoldfinger 95d13f2
Add number of birthdays
auricgoldfinger 31d07c6
Removed debug code
auricgoldfinger 3d9388b
Fix @alexstyl remarks
auricgoldfinger f496039
Get event label using a separate method
auricgoldfinger 77498ad
Use getLabelFor in case of a single event as well
auricgoldfinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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); | ||
|
||
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) | ||
|
@@ -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) { | ||
|
@@ -137,6 +171,27 @@ public void forDailyReminder(ContactEvents events) { | |
|
||
} | ||
|
||
/** | ||
* TODO duplicated from {@link com.alexstyl.specialdates.upcoming.ui.ContactEventView#getLabelFor(ContactEvent)} | ||
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. 👍 |
||
* | ||
* @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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
👍