Handling notification post (local notif style)

This commit is contained in:
d4vidi
2016-11-23 20:01:07 +02:00
parent c28a2c9e6f
commit 07664a60fd
2 changed files with 23 additions and 2 deletions

View File

@@ -18,5 +18,11 @@ public interface IPushNotification {
*/
void onOpened();
/**
* Handle a request to post this notification.
* @return ID to optionally use for notification deletion.
*/
int onPostRequest();
PushNotificationProps asProps();
}

View File

@@ -68,15 +68,20 @@ public class PushNotification implements IPushNotification {
PushNotificationsDrawer.get(mContext).onNotificationOpened();
}
@Override
public int onPostRequest() {
return postNotification();
}
@Override
public PushNotificationProps asProps() {
return mNotificationProps.copy();
}
protected void postNotification() {
protected int postNotification() {
final PendingIntent pendingIntent = getCTAPendingIntent();
final Notification notification = buildNotification(pendingIntent);
postNotification((int) System.currentTimeMillis(), notification);
return postNotification(notification);
}
protected void digestNotification() {
@@ -141,11 +146,21 @@ public class PushNotification implements IPushNotification {
.setAutoCancel(true);
}
protected int postNotification(Notification notification) {
int id = createNotificationId(notification);
postNotification(id, notification);
return id;
}
protected void postNotification(int id, Notification notification) {
final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(id, notification);
}
protected int createNotificationId(Notification notification) {
return (int) System.currentTimeMillis();
}
protected ReactContext getRunningReactContext() {
final ReactNativeHost rnHost = ((ReactApplication) mContext.getApplicationContext()).getReactNativeHost();
if (!rnHost.hasInstance()) {