Commit 8797f0d6 by Kunj Gupta

Added PTO request notification functionality.

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