Skip to content

Commit

Permalink
Merge pull request #33 from samuelagm/master
Browse files Browse the repository at this point in the history
Enable inboxStyle mode on android
  • Loading branch information
EddyVerbruggen authored Jan 9, 2017
2 parents 62169d9 + f99e0e8 commit dfb18bc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ You can pass several options to this function, everything is optional:
|`id` |A number so you can easily distinguish your notifications. Default 0.|
|`title` |The title which is shown in the statusbar. Default empty.|
|`body` |The text below the title. Default empty.|
|`groupedMessages`| An array of atmost 5 messages that would be displayed using android's notification [inboxStyle](https://developer.android.com/reference/android/app/Notification.InboxStyle.html). Note: The array would be trimed from the top if the messages exceed five. Default not set |
|`groupSummary`| An [inboxStyle](https://developer.android.com/reference/android/app/Notification.InboxStyle.html) notification summary. Default empty|
|`ticker` |On Android you can show a different text in the statusbar, instead of the `body`. Default not set, so `body` is used.|
|`at` |A JavaScript Date object indicating when the notification should be shown. Default 'now'.|
|`badge` |On iOS (and some Android devices) you see a number on top of the app icon. On most Android devices you'll see this number in the notification center. Default not set (0).|
Expand All @@ -61,6 +63,8 @@ Note that after a reboot the `smallIcon` and `largeIcon` are not restored but fa
body: 'Recurs every minute until cancelled',
ticker: 'The ticker',
badge: 1,
groupedMessages:["The first", "Second", "Keep going", "one more..", "OK Stop"] //android only
groupSummary:"Summary of the grouped messages above" //android only
ongoing: true, // makes the notification ongoing (Android only)
smallIcon: 'res://heart.png',
interval: 'minute',
Expand Down
3 changes: 2 additions & 1 deletion local-notifications-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ LocalNotifications.defaults = {
body: '',
badge: 0,
interval: 0,
ongoing: false
ongoing: false,
groupSummary:null
};

LocalNotifications.merge = function merge(obj1, obj2) { // Our merge function
Expand Down
30 changes: 16 additions & 14 deletions local-notifications.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ LocalNotifications.schedule = function (arg) {
.setOngoing(options.ongoing)//sets the notification to ongoing if it's true.
.setTicker(options.ticker || options.body);

if(options.groupedMessages != null && Array.isArray(options.groupedMessages)){
var inboxStyle = new android.support.v4.app.NotificationCompat.InboxStyle();
var events = options.groupedMessages;
(events.length > 5) ? events.splice(0, events.length - 5) : 0;

// Sets a title for the Inbox in expanded layout
inboxStyle.setBigContentTitle(options.title);
for (var i=0; i < events.length; i++) {
inboxStyle.addLine(events[i]);
}
options.groupSummary !== null ? inboxStyle.setSummaryText(options.groupSummary):0;
builder.setGroup(options.group)
.setStyle(inboxStyle)
}

// add the intent that handles the event when the notification is clicked (which should launch the app)
var reqCode = new java.util.Random().nextInt();
var clickIntent = new android.content.Intent(context, com.telerik.localnotifications.NotificationClickedActivity.class)
Expand All @@ -91,19 +106,6 @@ LocalNotifications.schedule = function (arg) {
var pendingContentIntent = android.app.PendingIntent.getActivity(context, reqCode, clickIntent, android.app.PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingContentIntent);


// NOTE this expanded mode works and is pretty awesome.. add properties one day
/*
var inboxStyle = new android.support.v4.app.NotificationCompat.InboxStyle();
var events = ["a", "b", "c"];
// Sets a title for the Inbox in expanded layout
inboxStyle.setBigContentTitle("Event tracker details:");
for (var i=0; i < events.length; i++) {
inboxStyle.addLine(events[i]);
}
builder.setStyle(inboxStyle);
*/

// add the intent which schedules the notification
var notificationIntent = new android.content.Intent(context, com.telerik.localnotifications.NotificationPublisher.class)
.setAction("" + options.id)
Expand Down Expand Up @@ -178,7 +180,7 @@ LocalNotifications._unpersist = function (id) {
};

LocalNotifications._cancelById = function (id) {

var notificationIntent = new android.content.Intent(context, com.telerik.localnotifications.NotificationPublisher.class)
.setAction("" + id);

Expand Down
17 changes: 17 additions & 0 deletions local-notifications.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@ declare namespace localNotifications {
* Default false.
*/
ongoing?: boolean;

/***
* An array of messages to be displayed as a single notification using the inbox style
* Note: the length of the array cannot be greater than five, in a situation where it
* is, the array would be trimmed from the top
*
* Android only.
*/
groupedMessages?:Array<string>


/***
* The summary of the grouped message (see #groupedMessage) when using the inbox style
*
* Android only.
*/
groupSummary?:string;
}

export interface ReceivedNotification {
Expand Down

0 comments on commit dfb18bc

Please sign in to comment.