Commit 35a89f7e authored by d4vidi's avatar d4vidi

Posting and clearing

parent 07664a60
...@@ -12,6 +12,9 @@ import com.facebook.react.bridge.Promise; ...@@ -12,6 +12,9 @@ import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.wix.reactnativenotifications.core.notification.IPushNotification;
import com.wix.reactnativenotifications.core.notification.PushNotification;
import com.wix.reactnativenotifications.core.notification.PushNotificationProps; import com.wix.reactnativenotifications.core.notification.PushNotificationProps;
import com.wix.reactnativenotifications.core.notificationdrawer.IPushNotificationsDrawer; import com.wix.reactnativenotifications.core.notificationdrawer.IPushNotificationsDrawer;
import com.wix.reactnativenotifications.core.notificationdrawer.PushNotificationsDrawer; import com.wix.reactnativenotifications.core.notificationdrawer.PushNotificationsDrawer;
...@@ -66,6 +69,27 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements ...@@ -66,6 +69,27 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements
} }
} }
@ReactMethod
public void postLocalNotification(ReadableMap notificationPropsMap, final Promise promise) {
Log.d(LOGTAG, "Native method invocation: postLocalNotification");
Object result = null;
try {
final Bundle notificationProps = Arguments.toBundle(notificationPropsMap);
final IPushNotification pushNotification = PushNotification.get(getReactApplicationContext().getApplicationContext(), notificationProps, ReactAppLifecycleFacade.get());
int id = pushNotification.onPostRequest();
result = id;
} finally {
promise.resolve(result);
}
}
@ReactMethod
public void removeLocalNotification(int notificationId) {
IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext());
notificationsDrawer.onNotificationClear(notificationId);
}
@Override @Override
public void onAppVisible() { public void onAppVisible() {
final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext()); final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(getReactApplicationContext().getApplicationContext());
......
...@@ -8,4 +8,5 @@ public interface IPushNotificationsDrawer { ...@@ -8,4 +8,5 @@ public interface IPushNotificationsDrawer {
void onNewActivity(Activity activity); void onNewActivity(Activity activity);
void onNotificationOpened(); void onNotificationOpened();
void onNotificationClear(int id);
} }
...@@ -47,6 +47,12 @@ public class PushNotificationsDrawer implements IPushNotificationsDrawer { ...@@ -47,6 +47,12 @@ public class PushNotificationsDrawer implements IPushNotificationsDrawer {
clearAll(); clearAll();
} }
@Override
public void onNotificationClear(int id) {
final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(id);
}
protected void clearAll() { protected void clearAll() {
final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); final NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll(); notificationManager.cancelAll();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment