Commit 0209bbaf authored by Varun Patil's avatar Varun Patil

Make event about to start notification

parent cd68a18a
...@@ -66,23 +66,24 @@ public class InstiAppFirebaseMessagingService extends FirebaseMessagingService { ...@@ -66,23 +66,24 @@ public class InstiAppFirebaseMessagingService extends FirebaseMessagingService {
super.onMessageReceived(remoteMessage); super.onMessageReceived(remoteMessage);
} }
/** Ensure key is in data */
private boolean ensureKeyExists(RemoteMessage remoteMessage, String key) {
return (remoteMessage.getData().get(key) != null);
}
/** Send a event is starting notification */ /** Send a event is starting notification */
private void sendEventStartingNotification(RemoteMessage remoteMessage) { private void sendEventStartingNotification(RemoteMessage remoteMessage) {
if (!ensureKeyExists(remoteMessage, "name")) { return; }
int notification_id = NotificationId.getID(); int notification_id = NotificationId.getID();
Notification notification = new NotificationCompat.Builder(this, channel) Notification notification = standardNotificationBuilder()
.setSmallIcon(R.drawable.ic_lotusgray) .setContentTitle(remoteMessage.getData().get("name"))
.setColor(getResources().getColor(R.color.colorPrimary)) .setContentText("Event is about to start")
.setContentTitle("TEST")
.setContentText("TEST")
.setContentIntent(getNotificationIntent(remoteMessage, notification_id)) .setContentIntent(getNotificationIntent(remoteMessage, notification_id))
.setVibrate(new long[]{0, 400})
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.build(); .build();
/* Show notification */ /* Show notification */
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); showNotification(notification_id, notification);
notificationManager.notify(notification_id, notification);
} }
/** Send a standard notification from foreground */ /** Send a standard notification from foreground */
...@@ -101,19 +102,29 @@ public class InstiAppFirebaseMessagingService extends FirebaseMessagingService { ...@@ -101,19 +102,29 @@ public class InstiAppFirebaseMessagingService extends FirebaseMessagingService {
if (title == null || body == null) { return; } if (title == null || body == null) { return; }
/* Build notification */ /* Build notification */
Notification notification = new NotificationCompat.Builder(this, channel) Notification notification = standardNotificationBuilder()
.setSmallIcon(R.drawable.ic_lotusgray)
.setColor(getResources().getColor(R.color.colorPrimary))
.setContentTitle(title) .setContentTitle(title)
.setContentText(body) .setContentText(body)
.setContentIntent(getNotificationIntent(remoteMessage, notification_id)) .setContentIntent(getNotificationIntent(remoteMessage, notification_id))
.setVibrate(new long[]{0, 400})
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.build(); .build();
/* Show notification */ /* Show notification */
showNotification(notification_id, notification);
}
/** Show the notification */
private void showNotification(int id, Notification notification) {
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(notification_id, notification); notificationManager.notify(id, notification);
}
/** Common builder */
private NotificationCompat.Builder standardNotificationBuilder() {
return new NotificationCompat.Builder(this, channel)
.setSmallIcon(R.drawable.ic_lotusgray)
.setColor(getResources().getColor(R.color.colorPrimary))
.setVibrate(new long[]{0, 400})
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
} }
} }
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