Commit 8797f0d6 by Kunj Gupta

Added PTO request notification functionality.

parent 2cb9e987
...@@ -11,8 +11,11 @@ import android.widget.TextView; ...@@ -11,8 +11,11 @@ import android.widget.TextView;
import com.vsoft.servicenow.R; import com.vsoft.servicenow.R;
import com.vsoft.servicenow.menu.HomeScreenMenuItemData; import com.vsoft.servicenow.menu.HomeScreenMenuItemData;
import com.vsoft.servicenow.menu.NotificationMenuItemData;
import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
...@@ -27,7 +30,15 @@ public class HomeScreenAdapter extends BaseAdapter { ...@@ -27,7 +30,15 @@ public class HomeScreenAdapter extends BaseAdapter {
//Constructor to initialize values //Constructor to initialize values
public HomeScreenAdapter(Context context, List<HomeScreenMenuItemData> homeScreenMenuItemDataList) { public HomeScreenAdapter(Context context, List<HomeScreenMenuItemData> homeScreenMenuItemDataList) {
mContext = context; mContext = context;
mHomeScreenMenuItemDataList = homeScreenMenuItemDataList; // mHomeScreenMenuItemDataList = homeScreenMenuItemDataList;
mHomeScreenMenuItemDataList = new ArrayList<>(homeScreenMenuItemDataList.size() - 1);
for (int i = 0; i < homeScreenMenuItemDataList.size(); i++) {
HomeScreenMenuItemData homeScreenMenuItemData = homeScreenMenuItemDataList.get(i);
if(homeScreenMenuItemData instanceof NotificationMenuItemData) {
} else {
mHomeScreenMenuItemDataList.add(homeScreenMenuItemData);
}
}
mInflater = (LayoutInflater) context mInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
} }
......
...@@ -41,9 +41,9 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants { ...@@ -41,9 +41,9 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
createAttachmentTable(db); createAttachmentTable(db);
createIncidentInputTable(db); createIncidentInputTable(db);
if(Util.isNotificationsItemEnabled()) { // if(Util.isNotificationsItemEnabled()) {
createNotificationsTable(db); // createNotificationsTable(db);
} // }
if(Util.isChatItemEnabled()) { if(Util.isChatItemEnabled()) {
createChatBotTable(db); createChatBotTable(db);
......
package com.vsoft.servicenow.service; package com.vsoft.servicenow.service;
import android.app.Notification;
import android.app.NotificationChannel; import android.app.NotificationChannel;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
...@@ -19,6 +20,7 @@ import com.vsoft.servicenow.db.managers.NotificationsManager; ...@@ -19,6 +20,7 @@ import com.vsoft.servicenow.db.managers.NotificationsManager;
import com.vsoft.servicenow.db.models.Notifications; import com.vsoft.servicenow.db.models.Notifications;
import com.vsoft.servicenow.ui.NotificationScreen; import com.vsoft.servicenow.ui.NotificationScreen;
import com.vsoft.servicenow.ui.PendingApprovalsActivity; import com.vsoft.servicenow.ui.PendingApprovalsActivity;
import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.PrefManager; import com.vsoft.servicenow.utils.PrefManager;
...@@ -46,6 +48,7 @@ public class NotificationMessagingService extends FirebaseMessagingService { ...@@ -46,6 +48,7 @@ public class NotificationMessagingService extends FirebaseMessagingService {
private static final String FCM_KEY_SHORT_DESCRIPTION = "short_description"; private static final String FCM_KEY_SHORT_DESCRIPTION = "short_description";
private static final String FCM_KEY_CREATED_BY = "created_by"; private static final String FCM_KEY_CREATED_BY = "created_by";
private static final String FCM_KEY_MESSAGE_BODY_TITLE = "title"; private static final String FCM_KEY_MESSAGE_BODY_TITLE = "title";
private static final String FCM_KEY_PTO_REQUEST_STATUS = "u_request_status";
private static final String CHANNEL_ID = "sn_channel"; private static final String CHANNEL_ID = "sn_channel";
...@@ -62,8 +65,9 @@ public class NotificationMessagingService extends FirebaseMessagingService { ...@@ -62,8 +65,9 @@ public class NotificationMessagingService extends FirebaseMessagingService {
if (userSysId != null && !userSysId.isEmpty()) { if (userSysId != null && !userSysId.isEmpty()) {
Map<String, String> dataMap = remoteMessage.getData(); Map<String, String> dataMap = remoteMessage.getData();
String title = dataMap.get(FCM_KEY_TITLE); String title = dataMap.get(FCM_KEY_TITLE);
CatalogueLog.e("onMessageReceived: dataMap: "+dataMap+", title: "+title);
String messageBody = dataMap.get(FCM_KEY_BODY); String messageBody = dataMap.get(FCM_KEY_BODY);
String priority = null, shortDes = null, createdBy = null, messageBodyTitle = null, requestState = null, documentId = null; String priority = null, shortDes = null, createdBy = null, messageBodyTitle = null, requestState = null, documentId = null, ptoRequestStatus = null;
try { try {
JSONObject jsonObject = new JSONObject(messageBody); JSONObject jsonObject = new JSONObject(messageBody);
if(!jsonObject.isNull(FCM_KEY_INCIDENT_PRIORITY)) { if(!jsonObject.isNull(FCM_KEY_INCIDENT_PRIORITY)) {
...@@ -75,42 +79,49 @@ public class NotificationMessagingService extends FirebaseMessagingService { ...@@ -75,42 +79,49 @@ public class NotificationMessagingService extends FirebaseMessagingService {
if(!jsonObject.isNull(FCM_KEY_REQUEST_STATE)) { if(!jsonObject.isNull(FCM_KEY_REQUEST_STATE)) {
requestState = jsonObject.getString(FCM_KEY_REQUEST_STATE); requestState = jsonObject.getString(FCM_KEY_REQUEST_STATE);
} }
if(!jsonObject.isNull(FCM_KEY_CREATED_BY)) {
createdBy = jsonObject.getString(FCM_KEY_CREATED_BY); createdBy = jsonObject.getString(FCM_KEY_CREATED_BY);
}
if(!jsonObject.isNull(FCM_KEY_MESSAGE_BODY_TITLE)) {
messageBodyTitle = jsonObject.getString(FCM_KEY_MESSAGE_BODY_TITLE); messageBodyTitle = jsonObject.getString(FCM_KEY_MESSAGE_BODY_TITLE);
}
if(!jsonObject.isNull(FCM_KEY_PTO_REQUEST_STATUS)) {
ptoRequestStatus = jsonObject.getString(FCM_KEY_PTO_REQUEST_STATUS);
}
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
Notifications newNotification = null; Notifications newNotification = null;
if(messageBodyTitle.equals(MESSAGE_BODY_INCIDENT_TITLE)) { // if(messageBodyTitle.equals(MESSAGE_BODY_INCIDENT_TITLE)) {
newNotification = new Notifications();
newNotification.setTitle(title);
newNotification.setShortDescription(shortDes);
newNotification.setPriority(priority);
newNotification.setCreated_by(createdBy);
NotificationsManager.save(newNotification);
} else if(messageBodyTitle.equals(MESSAGE_BODY_REQUEST_TITLE)) {
newNotification = new Notifications();
newNotification.setTitle(title);
newNotification.setShortDescription(shortDes);
newNotification.setPriority(requestState);
newNotification.setCreated_by(createdBy);
NotificationsManager.save(newNotification);
} else if(messageBodyTitle.equals(MESSAGE_BODY_APPROVALS_TITLE)) {
newNotification = new Notifications(); newNotification = new Notifications();
newNotification.setTitle(title); newNotification.setTitle(title);
newNotification.setShortDescription(shortDes); newNotification.setShortDescription(shortDes);
newNotification.setPriority(requestState); newNotification.setPriority(ptoRequestStatus);
newNotification.setCreated_by(createdBy); newNotification.setCreated_by(createdBy);
} // NotificationsManager.save(newNotification);
// } else if(messageBodyTitle.equals(MESSAGE_BODY_REQUEST_TITLE)) {
// newNotification = new Notifications();
// newNotification.setTitle(title);
// newNotification.setShortDescription(shortDes);
// newNotification.setPriority(requestState);
// newNotification.setCreated_by(createdBy);
// NotificationsManager.save(newNotification);
// } else if(messageBodyTitle.equals(MESSAGE_BODY_APPROVALS_TITLE)) {
// newNotification = new Notifications();
// newNotification.setTitle(title);
// newNotification.setShortDescription(shortDes);
// newNotification.setPriority(requestState);
// newNotification.setCreated_by(createdBy);
// }
sendNotification(newNotification, messageBodyTitle, null); sendNotification(newNotification, messageBodyTitle, null);
if(messageBodyTitle.equals(MESSAGE_BODY_APPROVALS_TITLE)) { // if(messageBodyTitle.equals(MESSAGE_BODY_APPROVALS_TITLE)) {
sendLocalMessage(NotificationMessagingService.this, newNotification, true); // sendLocalMessage(NotificationMessagingService.this, newNotification, true);
} else { // } else {
sendLocalMessage(NotificationMessagingService.this, newNotification, false); // sendLocalMessage(NotificationMessagingService.this, newNotification, false);
} // }
} }
} }
...@@ -124,35 +135,35 @@ public class NotificationMessagingService extends FirebaseMessagingService { ...@@ -124,35 +135,35 @@ public class NotificationMessagingService extends FirebaseMessagingService {
private void sendNotification(Notifications notification, String messageBodyTitle, String documentId) { private void sendNotification(Notifications notification, String messageBodyTitle, String documentId) {
String title = null; String title = null;
Intent newIntent = null; // Intent newIntent = null;
if(messageBodyTitle.equals(MESSAGE_BODY_APPROVALS_TITLE)) { // if(messageBodyTitle.equals(MESSAGE_BODY_APPROVALS_TITLE)) {
title = getString(R.string.notification_status_bar_approvals_title_string); // title = getString(R.string.notification_status_bar_approvals_title_string);
newIntent = new Intent(this, PendingApprovalsActivity.class); // newIntent = new Intent(this, PendingApprovalsActivity.class);
} else if(messageBodyTitle.equals(MESSAGE_BODY_INCIDENT_TITLE)) { // } else if(messageBodyTitle.equals(MESSAGE_BODY_INCIDENT_TITLE)) {
title = getString(R.string.notification_status_bar_incident_title_string); // title = getString(R.string.notification_status_bar_incident_title_string);
newIntent = new Intent(this, NotificationScreen.class); // newIntent = new Intent(this, NotificationScreen.class);
} else if(messageBodyTitle.equals(MESSAGE_BODY_REQUEST_TITLE)) { // } else if(messageBodyTitle.equals(MESSAGE_BODY_REQUEST_TITLE)) {
title = getString(R.string.notification_status_bar_request_title_string); // title = getString(R.string.notification_status_bar_request_title_string);
newIntent = new Intent(this, NotificationScreen.class); // newIntent = new Intent(this, NotificationScreen.class);
} else if(messageBodyTitle.equals(MESSAGE_BODY_HR_CASE_TITLE)) { // } else if(messageBodyTitle.equals(MESSAGE_BODY_HR_CASE_TITLE)) {
title = getString(R.string.notification_status_bar_hr_case_title_string); // title = getString(R.string.notification_status_bar_hr_case_title_string);
newIntent = new Intent(this, NotificationScreen.class); // newIntent = new Intent(this, NotificationScreen.class);
} // }
newIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); // newIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
//
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, newIntent, // PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, newIntent,
PendingIntent.FLAG_ONE_SHOT); // PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, CHANNEL_ID) NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.notification_icon) .setSmallIcon(R.drawable.notification_icon)
.setContentTitle(title) .setContentTitle(notification.getTitle())
.setContentText(notification != null ? notification.getShortDescription() : documentId) .setContentText(notification.getShortDescription() +"\n" + "Status: "+notification.getPriority())
.setAutoCancel(true) .setAutoCancel(true)
.setContentIntent(pendingIntent) // .setContentIntent(null)
.setChannelId(CHANNEL_ID) .setChannelId(CHANNEL_ID)
.setSound(defaultSoundUri); .setSound(defaultSoundUri);
......
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
"client": [ "client": [
{ {
"client_info": { "client_info": {
"mobilesdk_app_id": "1:222593508124:android:d77c1b70d2a38b4d", "mobilesdk_app_id": "1:222593508124:android:afc437977a23c97d",
"android_client_info": { "android_client_info": {
"package_name": "com.vsoft.servicenow.arrow.debug" "package_name": "com.vsoft.servicenow.vportal.staging"
} }
}, },
"oauth_client": [ "oauth_client": [
...@@ -39,9 +39,9 @@ ...@@ -39,9 +39,9 @@
}, },
{ {
"client_info": { "client_info": {
"mobilesdk_app_id": "1:222593508124:android:ade631ceed1f3560", "mobilesdk_app_id": "1:222593508124:android:afc437977a23c97d",
"android_client_info": { "android_client_info": {
"package_name": "com.vsoft.servicenow.vportal.debug" "package_name": "com.vsoft.servicenow.vportal"
} }
}, },
"oauth_client": [ "oauth_client": [
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
"client_info": { "client_info": {
"mobilesdk_app_id": "1:222593508124:android:ade631ceed1f3560", "mobilesdk_app_id": "1:222593508124:android:ade631ceed1f3560",
"android_client_info": { "android_client_info": {
"package_name": "com.vsoft.servicenow.vportal" "package_name": "com.vsoft.servicenow.vportal.debug"
} }
}, },
"oauth_client": [ "oauth_client": [
......
...@@ -47,11 +47,11 @@ public class MenuProvider { ...@@ -47,11 +47,11 @@ public class MenuProvider {
new ChatMenuItemData.Builder() new ChatMenuItemData.Builder()
.setTitle(R.string.home_screen_chat_title) .setTitle(R.string.home_screen_chat_title)
.setMenuIconResId(R.string.home_screen_chat_icon) .setMenuIconResId(R.string.home_screen_chat_icon)
.build(),
new NotificationMenuItemData.Builder()
.setTitle(R.string.home_screen_notification_title)
.setMenuIconResId(R.string.home_screen_notification_icon)
.build() .build()
// new NotificationMenuItemData.Builder()
// .setTitle(R.string.home_screen_notification_title)
// .setMenuIconResId(R.string.home_screen_notification_icon)
// .build(),
// new ApprovalsMenuItemData.Builder() // new ApprovalsMenuItemData.Builder()
// .setTitle(R.string.home_screen_approvals_title) // .setTitle(R.string.home_screen_approvals_title)
// .setMenuIconResId(R.string.home_screen_approvals_icon) // .setMenuIconResId(R.string.home_screen_approvals_icon)
......
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 sign in to comment