Commit dfab12f6 by Niladri

Merge branch 'devOfflineCapability' of…

Merge branch 'devOfflineCapability' of https://gitlab.vsoftconsulting.com/ssinangaram/uofl-android into devOfflineCapability

# Conflicts:
#	app/src/main/java/com/vsoft/servicenow/service/SyncService.java
parents 6fa49ad1 751570e0
......@@ -32,7 +32,7 @@ android {
}
compileSdkVersion 27
buildToolsVersion "27.0.0"
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.vsoft.servicenow"
......@@ -93,7 +93,7 @@ dependencies {
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.8.1'
compile 'com.jakewharton:butterknife:8.8.1'
compile 'com.google.android.gms:play-services-analytics:12.0.1'
compile 'com.google.android.gms:play-services-analytics:15.0.0'
//compile 'com.google.dagger:dagger:2.0'
//annotationProcessor 'com.google.dagger:dagger-compiler:2.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
......@@ -102,13 +102,13 @@ dependencies {
}
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.github.nkzawa:socket.io-client:0.3.0'
compile 'com.android.support:appcompat-v7:27.1.0'
compile 'com.android.support:cardview-v7:27.1.0'
compile 'com.android.support:recyclerview-v7:27.1.0'
compile 'com.android.support:animated-vector-drawable:27.1.0'
compile 'com.android.support:support-media-compat:27.1.0'
compile 'com.android.support:support-v4:27.1.0'
compile 'com.google.firebase:firebase-messaging:12.0.1'
compile 'com.android.support:appcompat-v7:27.1.1'
compile 'com.android.support:cardview-v7:27.1.1'
compile 'com.android.support:recyclerview-v7:27.1.1'
compile 'com.android.support:animated-vector-drawable:27.1.1'
compile 'com.android.support:support-media-compat:27.1.1'
compile 'com.android.support:support-v4:27.1.1'
compile 'com.google.firebase:firebase-messaging:15.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
}
......
......@@ -18,6 +18,7 @@ import com.vsoft.servicenow.R;
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.Constants;
import com.vsoft.servicenow.utils.PrefManager;
......@@ -33,11 +34,18 @@ import java.util.Map;
*/
public class NotificationMessagingService extends FirebaseMessagingService {
private static final String MESSAGE_BODY_INCIDENT_TITLE = "Incidents";
private static final String MESSAGE_BODY_HR_CASE_TITLE = "HR Cases";
private static final String MESSAGE_BODY_REQUEST_TITLE = "Order Services";
private static final String MESSAGE_BODY_APPROVALS_TITLE = "My Approvals";
private static final String FCM_KEY_TITLE = "title";
private static final String FCM_KEY_BODY = "body";
private static final String FCM_KEY_PRIORITY = "priority";
private static final String FCM_KEY_REQUEST_STATE = "state";
private static final String FCM_KEY_INCIDENT_PRIORITY = "priority";
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 CHANNEL_ID = "sn_channel";
......@@ -55,47 +63,94 @@ public class NotificationMessagingService extends FirebaseMessagingService {
Map<String, String> dataMap = remoteMessage.getData();
String title = dataMap.get(FCM_KEY_TITLE);
String messageBody = dataMap.get(FCM_KEY_BODY);
String priority = null, shortDes = null, createdBy = null;
String priority = null, shortDes = null, createdBy = null, messageBodyTitle = null, requestState = null, documentId = null;
try {
JSONObject jsonObject = new JSONObject(messageBody);
priority = jsonObject.getString(FCM_KEY_PRIORITY);
shortDes = jsonObject.getString(FCM_KEY_SHORT_DESCRIPTION);
if(!jsonObject.isNull(FCM_KEY_INCIDENT_PRIORITY)) {
priority = jsonObject.getString(FCM_KEY_INCIDENT_PRIORITY);
}
if(!jsonObject.isNull(FCM_KEY_SHORT_DESCRIPTION)) {
shortDes = jsonObject.getString(FCM_KEY_SHORT_DESCRIPTION);
}
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);
} catch (JSONException e) {
e.printStackTrace();
}
Notifications newNotification = new Notifications();
newNotification.setTitle(title);
newNotification.setShortDescription(shortDes);
newNotification.setPriority(priority);
newNotification.setCreated_by(createdBy);
NotificationsManager.save(newNotification);
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);
}
sendNotification(newNotification, messageBodyTitle, null);
sendNotification(newNotification);
sendLocalMessage(NotificationMessagingService.this, newNotification);
if(messageBodyTitle.equals(MESSAGE_BODY_APPROVALS_TITLE)) {
sendLocalMessage(NotificationMessagingService.this, newNotification, true);
} else {
sendLocalMessage(NotificationMessagingService.this, newNotification, false);
}
}
}
private void sendLocalMessage(Context context, Notifications notifications) {
private void sendLocalMessage(Context context, Notifications notifications, boolean isApproval) {
Intent intent = new Intent(Constants.BROADCAST_NOTIFICATION);
intent.putExtra(Constants.DATA_KEY_NOTIFICATION_TITLE, notifications.getTitle());
intent.putExtra(Constants.DATA_KEY_NOTIFICATION_MESSAGE, notifications.getShortDescription());
intent.putExtra(Constants.DATA_KEY_NOTIFICATION_IS_APPROVALS, isApproval);
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}
private void sendNotification(Notifications notification) {
Intent newIntent = new Intent(this, NotificationScreen.class);
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);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle(getString(R.string.notification_status_bar_title_string))
.setContentText(notification.getShortDescription())
.setContentTitle(title)
.setContentText(notification != null ? notification.getShortDescription() : documentId)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setChannelId(CHANNEL_ID)
......@@ -111,7 +166,6 @@ public class NotificationMessagingService extends FirebaseMessagingService {
notificationManager.createNotificationChannel(mChannel);
}
notificationManager.notify(1, notificationBuilder.build());
}
}
......@@ -10,10 +10,10 @@ import com.vsoft.servicenow.api.listeners.post.PostHRCaseVariableFormApiListener
import com.vsoft.servicenow.api.listeners.post.PostIncidentApiListener;
import com.vsoft.servicenow.api.listeners.post.PostVariableFormApiListener;
import com.vsoft.servicenow.api.managers.CatalogueVariableApiManager;
import com.vsoft.servicenow.api.managers.HRCaseItemApiManager;
import com.vsoft.servicenow.api.managers.HRCaseVariableApiManager;
import com.vsoft.servicenow.api.managers.IncidentApiManager;
import com.vsoft.servicenow.api.pojos.HRCaseVariableSubmitApiResponse;
import com.vsoft.servicenow.db.DBConstants;
import com.vsoft.servicenow.db.managers.AttachmentManager;
import com.vsoft.servicenow.db.managers.CatalogueItemInputManager;
import com.vsoft.servicenow.db.managers.CatalogueItemManager;
......@@ -31,8 +31,8 @@ import com.vsoft.servicenow.db.models.Incident;
import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.db.DBConstants;
import com.vsoft.servicenow.utils.PrefManager;
import com.vsoft.servicenow.utils.Util;
import org.json.JSONException;
import org.json.JSONObject;
......@@ -48,10 +48,10 @@ import java.util.List;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import static com.vsoft.servicenow.db.managers.CatalogueItemInputManager.getDirtyItemInput;
import static com.vsoft.servicenow.db.DBConstants.CATALOGUE_ITEM_INPUT_SYS_ID;
import static com.vsoft.servicenow.db.DBConstants.INCIDENT_INPUT_NUMBER;
import static com.vsoft.servicenow.db.DBConstants.SYNC_FLAG_NONE;
import static com.vsoft.servicenow.db.managers.CatalogueItemInputManager.getDirtyItemInput;
/**
......@@ -62,6 +62,7 @@ import static com.vsoft.servicenow.db.DBConstants.SYNC_FLAG_NONE;
public class SyncService extends IntentService {
private SyncStatus syncStatus = SyncStatus.FAIL;
public SyncService() {
super(SyncService.class.getSimpleName());
}
......@@ -69,7 +70,7 @@ public class SyncService extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
CatalogueApplication mApplication = (CatalogueApplication) getApplication();
if(!mApplication.isNetConnected()) {
if (!mApplication.isNetConnected()) {
CatalogueLog.e("SyncService: onHandleIntent(): Not connected to net. Exit.");
return;
}
......@@ -81,47 +82,59 @@ public class SyncService extends IntentService {
SyncStatus result;
/*First we will work on dirty variable form*/
List<CatalogueItemInput> catalogueItemInputList = getDirtyItemInput();
if(Constants.DEBUG) CatalogueLog.d("startSync: catalogue form to sync: "+catalogueItemInputList.size());
if (Constants.DEBUG)
CatalogueLog.d("startSync: catalogue form to sync: " + catalogueItemInputList.size());
for (int i = 0; i < catalogueItemInputList.size(); i++) {
CatalogueItemInput catalogueItemInput = catalogueItemInputList.get(i);
result = syncVariableForm(catalogueItemInput);
if(Constants.DEBUG) CatalogueLog.d("startSync: result of syncing catalogueItemInput "+i+": "+result);
if (Constants.DEBUG)
CatalogueLog.d("startSync: result of syncing catalogueItemInput " + i + ": " + result);
}
/*Then we will work on dirty attachment*/
List<Attachment> attachmentList = AttachmentManager.getDirtyAttachment();
if(Constants.DEBUG) CatalogueLog.d("startSync: attachment to sync: "+attachmentList.size());
if (Constants.DEBUG)
CatalogueLog.d("startSync: attachment to sync: " + attachmentList.size());
for (int i = 0; i < attachmentList.size(); i++) {
Attachment attachment = attachmentList.get(i);
result = syncAttachment(attachment);
if(Constants.DEBUG) CatalogueLog.d("startSync: result of syncing attachment "+i+": "+result);
if (Constants.DEBUG)
CatalogueLog.d("startSync: result of syncing attachment " + i + ": " + result);
}
// /*Then we will work on dirty variable form*/
// List<HRCaseItemInput> hrCaseItemInputList = HRCaseItemInputManager.getDirtyItemInput();
// if(Constants.DEBUG) CatalogueLog.d("startSync: HRCase form to sync: "+hrCaseItemInputList.size());
// for (int i = 0; i < hrCaseItemInputList.size(); i++) {
// HRCaseItemInput hrCaseItemInput = hrCaseItemInputList.get(i);
// result = syncHRCaseVariableForm(hrCaseItemInput);
// if(Constants.DEBUG) CatalogueLog.d("startSync: result of syncing hrCaseItemInput "+i+": "+result);
// }
//
// /*Then we will work on dirty HRCase attachment*/
// List<HRCaseAttachment> hrCaseAttachmentList = HRCaseAttachmentManager.getDirtyHRCaseAttachment();
// if(Constants.DEBUG) CatalogueLog.d("startSync: HRCaseAttachment to sync: "+hrCaseAttachmentList.size());
// for (int i = 0; i < hrCaseAttachmentList.size(); i++) {
// HRCaseAttachment hrCaseAttachment = hrCaseAttachmentList.get(i);
// result = syncHRCaseAttachment(hrCaseAttachment);
// if(Constants.DEBUG) CatalogueLog.d("startSync: result of syncing hrCaseAttachment "+i+": "+result);
// }
if (Util.isHrCaseEnabled()) {
/*Then we will work on dirty variable form*/
List<HRCaseItemInput> hrCaseItemInputList = HRCaseItemInputManager.getDirtyItemInput();
if (Constants.DEBUG)
CatalogueLog.d("startSync: HRCase form to sync: " + hrCaseItemInputList.size());
for (int i = 0; i < hrCaseItemInputList.size(); i++) {
HRCaseItemInput hrCaseItemInput = hrCaseItemInputList.get(i);
result = syncHRCaseVariableForm(hrCaseItemInput);
if (Constants.DEBUG)
CatalogueLog.d("startSync: result of syncing hrCaseItemInput " + i + ": " + result);
}
/*Then we will work on dirty HRCase attachment*/
List<HRCaseAttachment> hrCaseAttachmentList = HRCaseAttachmentManager.getDirtyHRCaseAttachment();
if (Constants.DEBUG)
CatalogueLog.d("startSync: HRCaseAttachment to sync: " + hrCaseAttachmentList.size());
for (int i = 0; i < hrCaseAttachmentList.size(); i++) {
HRCaseAttachment hrCaseAttachment = hrCaseAttachmentList.get(i);
result = syncHRCaseAttachment(hrCaseAttachment);
if (Constants.DEBUG)
CatalogueLog.d("startSync: result of syncing hrCaseAttachment " + i + ": " + result);
}
}
/*Then we will work on dirty incident form*/
List<Incident> incidentInputList = ReportIncidentValueManager.getDirtyIncident();
if(Constants.DEBUG) CatalogueLog.d("startSync: incident form to sync: "+incidentInputList.size());
if (Constants.DEBUG)
CatalogueLog.d("startSync: incident form to sync: " + incidentInputList.size());
for (int i = 0; i < incidentInputList.size(); i++) {
Incident incident = incidentInputList.get(i);
result = syncIncidentForm(incident);
if(Constants.DEBUG) CatalogueLog.d("startSync: result of syncing incidentInput "+i+": "+result);
if (Constants.DEBUG)
CatalogueLog.d("startSync: result of syncing incidentInput " + i + ": " + result);
}
}
......@@ -129,26 +142,26 @@ public class SyncService extends IntentService {
* Sync VariableForm
**/
private SyncStatus syncVariableForm(final CatalogueItemInput catalogueItemInput) {
CatalogueLog.d( "syncVariableForm");
if(catalogueItemInput.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE || catalogueItemInput.getSysId() == null || catalogueItemInput.getSysId().isEmpty()) {
CatalogueLog.d("syncVariableForm");
if (catalogueItemInput.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE || catalogueItemInput.getSysId() == null || catalogueItemInput.getSysId().isEmpty()) {
final CatalogueItem catalogueItem = CatalogueItemManager.get(catalogueItemInput.getCatalogueItemId());
CatalogueVariableApiManager.submitVariableForm(SyncService.this, catalogueItem.getSysId(),
catalogueItemInput.getData(),
new PostVariableFormApiListener() {
@Override
public void onDoneApiCall(String variableFromSysId) {
syncStatus = SyncStatus.SUCCESS;
CatalogueLog.e("syncVariableForm: saveVariableForm: result is SUCCESS");
catalogueItemInput.setSysId(variableFromSysId);
CatalogueItemInputManager.handleSaveServerResponse(catalogueItemInput, Collections.singletonList(CATALOGUE_ITEM_INPUT_SYS_ID), SYNC_FLAG_NONE);
}
@Override
public void onDoneApiCall(String variableFromSysId) {
syncStatus = SyncStatus.SUCCESS;
CatalogueLog.e("syncVariableForm: saveVariableForm: result is SUCCESS");
catalogueItemInput.setSysId(variableFromSysId);
CatalogueItemInputManager.handleSaveServerResponse(catalogueItemInput, Collections.singletonList(CATALOGUE_ITEM_INPUT_SYS_ID), SYNC_FLAG_NONE);
}
@Override
public void onFailApiCall() {
CatalogueLog.e("syncVariableForm: saveVariableForm: result is FAIL");
syncStatus = SyncStatus.FAIL;
}
});
@Override
public void onFailApiCall() {
CatalogueLog.e("syncVariableForm: saveVariableForm: result is FAIL");
syncStatus = SyncStatus.FAIL;
}
});
}
return syncStatus;
}
......@@ -157,8 +170,8 @@ public class SyncService extends IntentService {
* Sync Attachment
**/
private SyncStatus syncAttachment(final Attachment attachment) {
CatalogueLog.d( "syncAttachment");
if(attachment.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE) {
CatalogueLog.d("syncAttachment");
if (attachment.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE) {
if (attachment.getMimeType() != null) {
InputStream in = null;
try {
......@@ -201,9 +214,9 @@ public class SyncService extends IntentService {
* Sync Incident form
**/
private SyncStatus syncIncidentForm(final Incident incident) {
CatalogueLog.d( "syncVariableForm");
CatalogueLog.d("syncVariableForm");
String userSysId = PrefManager.getSharedPref(SyncService.this, PrefManager.PREFERENCE_USER_SYS_ID);
if(incident.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE || incident.getNumber() == null || incident.getNumber().isEmpty()) {
if (incident.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE || incident.getNumber() == null || incident.getNumber().isEmpty()) {
JSONObject incidentJsonObject = new JSONObject();
try {
incidentJsonObject.put(Incident.Json.IMPACT, incident.getImpact().getServerString());
......@@ -237,8 +250,8 @@ public class SyncService extends IntentService {
* Sync HRCase VariableForm
**/
private SyncStatus syncHRCaseVariableForm(final HRCaseItemInput hrCaseItemInput) {
CatalogueLog.d( "syncHRCaseVariableForm");
if(hrCaseItemInput.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE || hrCaseItemInput.getSysId() == null || hrCaseItemInput.getSysId().isEmpty()) {
CatalogueLog.d("syncHRCaseVariableForm");
if (hrCaseItemInput.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE || hrCaseItemInput.getSysId() == null || hrCaseItemInput.getSysId().isEmpty()) {
final HRCaseItem hrCaseItem = HRCaseItemManager.get(hrCaseItemInput.getHRCaseItemId());
HRCaseVariableApiManager.submitHRCaseVariableForm(SyncService.this, hrCaseItem.getSysId(),
hrCaseItemInput.getData(),
......@@ -254,7 +267,7 @@ public class SyncService extends IntentService {
String record = hrCaseVariableSubmitApiResponse.getRecord();
String[] recordSpit = record.split("/");
String submittedFormSysId = null;
if(recordSpit.length > 0) {
if (recordSpit.length > 0) {
submittedFormSysId = recordSpit[recordSpit.length - 1];
}
hrCaseItemInput.setSysId(submittedFormSysId);
......@@ -275,8 +288,8 @@ public class SyncService extends IntentService {
* Sync HRCase Attachment
**/
private SyncStatus syncHRCaseAttachment(final HRCaseAttachment hrCaseAttachment) {
CatalogueLog.d( "syncHRCaseAttachment");
if(hrCaseAttachment.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE) {
CatalogueLog.d("syncHRCaseAttachment");
if (hrCaseAttachment.getSyncDirty() == DBConstants.SYNC_FLAG_CREATE) {
if (hrCaseAttachment.getMimeType() != null) {
InputStream in = null;
try {
......
......@@ -184,6 +184,34 @@ public class ChatActivity extends AppCompatActivity implements OnDSListener, OnD
}
});
//Below code for - Last message getting overlapped when virtual keyboard is opened.
mInputMessageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if(motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
if(mMessagesView.getAdapter().getItemCount() > 0) {
mMessagesView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v,
int left, int top, int right, int bottom,
int oldLeft, int oldTop, int oldRight, int oldBottom) {
if (bottom < oldBottom) {
mMessagesView.postDelayed(new Runnable() {
@Override
public void run() {
mMessagesView.smoothScrollToPosition(
mMessagesView.getAdapter().getItemCount() - 1);
}
}, 100);
}
}
});
}
}
return false;
}
});
droidSpeech = new DroidSpeech(this, getSupportFragmentManager());
droidSpeech.setOnDroidSpeechListener(this);
......
......@@ -46,24 +46,46 @@ public class HandleNotificationActivity extends AppCompatActivity {
// That's why we need to play explicitly
Util.playNotificationSound(HandleNotificationActivity.this);
AlertDialog.Builder builder = new AlertDialog.Builder(HandleNotificationActivity.this);
builder.setMessage(intent.getStringExtra(Constants.DATA_KEY_NOTIFICATION_MESSAGE))
.setTitle(intent.getStringExtra(Constants.DATA_KEY_NOTIFICATION_TITLE))
.setCancelable(false)
.setPositiveButton(R.string.go_to_notification_string,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
startActivity(new Intent(HandleNotificationActivity.this,
NotificationScreen.class));
}
})
.setNegativeButton(R.string.ok_string, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
boolean isApprovalNotification = intent.getBooleanExtra(Constants.DATA_KEY_NOTIFICATION_IS_APPROVALS, false);
if(!isApprovalNotification) {
AlertDialog.Builder builder = new AlertDialog.Builder(HandleNotificationActivity.this);
builder.setMessage(intent.getStringExtra(Constants.DATA_KEY_NOTIFICATION_MESSAGE))
.setTitle(intent.getStringExtra(Constants.DATA_KEY_NOTIFICATION_TITLE))
.setCancelable(false)
.setPositiveButton(R.string.go_to_notification_string,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
startActivity(new Intent(HandleNotificationActivity.this,
NotificationScreen.class));
}
})
.setNegativeButton(R.string.ok_string, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(HandleNotificationActivity.this);
builder.setMessage(intent.getStringExtra(Constants.DATA_KEY_NOTIFICATION_MESSAGE))
.setTitle(intent.getStringExtra(Constants.DATA_KEY_NOTIFICATION_TITLE))
.setCancelable(false)
.setPositiveButton(R.string.go_to_approvals_string,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
startActivity(new Intent(HandleNotificationActivity.this,
PendingApprovalsActivity.class));
}
})
.setNegativeButton(R.string.ok_string, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
};
}
......@@ -66,19 +66,41 @@ public class NotificationScreen extends AppCompatActivity {
// That's why we need to play explicitly
Util.playNotificationSound(NotificationScreen.this);
AlertDialog.Builder builder = new AlertDialog.Builder(NotificationScreen.this);
builder.setMessage(intent.getStringExtra(Constants.DATA_KEY_NOTIFICATION_MESSAGE))
.setTitle(intent.getStringExtra(Constants.DATA_KEY_NOTIFICATION_TITLE))
.setCancelable(false)
.setPositiveButton(R.string.ok_string,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
updateNotificationList();
}
});
AlertDialog alert = builder.create();
alert.show();
boolean isApprovalNotification = intent.getBooleanExtra(Constants.DATA_KEY_NOTIFICATION_IS_APPROVALS, false);
if(!isApprovalNotification) {
AlertDialog.Builder builder = new AlertDialog.Builder(NotificationScreen.this);
builder.setMessage(intent.getStringExtra(Constants.DATA_KEY_NOTIFICATION_MESSAGE))
.setTitle(intent.getStringExtra(Constants.DATA_KEY_NOTIFICATION_TITLE))
.setCancelable(false)
.setPositiveButton(R.string.ok_string,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
updateNotificationList();
}
});
AlertDialog alert = builder.create();
alert.show();
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(NotificationScreen.this);
builder.setMessage(intent.getStringExtra(Constants.DATA_KEY_NOTIFICATION_MESSAGE))
.setTitle(intent.getStringExtra(Constants.DATA_KEY_NOTIFICATION_TITLE))
.setCancelable(false)
.setPositiveButton(R.string.go_to_approvals_string,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
startActivity(new Intent(NotificationScreen.this,
PendingApprovalsActivity.class));
}
})
.setNegativeButton(R.string.ok_string, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
};
......
package com.vsoft.servicenow.ui;
import android.app.NotificationManager;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.TextUtils;
......@@ -30,6 +37,7 @@ import com.vsoft.servicenow.api.managers.PendingApprovalsApiManager;
import com.vsoft.servicenow.db.managers.PendingApprovalsManager;
import com.vsoft.servicenow.db.models.PendingApprovals;
import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.DialogUtils;
import com.vsoft.servicenow.utils.Util;
......@@ -48,7 +56,7 @@ import butterknife.OnItemClick;
/**
* Created by Kunj on 26/04/2018.
* */
public class PendingApprovalsActivity extends HandleNotificationActivity {
public class PendingApprovalsActivity extends AppCompatActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar;
@BindView(R.id.pending_approvals_screen_list_view) ListView mListView;
......@@ -60,6 +68,55 @@ public class PendingApprovalsActivity extends HandleNotificationActivity {
private boolean isProgressRequire;
private CatalogueApplication mApplication;
private final BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//Cancel received notifications
final NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
//Play notification sound because Above we already cancel notifications.
// That's why we need to play explicitly
Util.playNotificationSound(PendingApprovalsActivity.this);
boolean isApprovalNotification = intent.getBooleanExtra(Constants.DATA_KEY_NOTIFICATION_IS_APPROVALS, false);
if(isApprovalNotification) {
AlertDialog.Builder builder = new AlertDialog.Builder(PendingApprovalsActivity.this);
builder.setMessage(intent.getStringExtra(Constants.DATA_KEY_NOTIFICATION_MESSAGE))
.setTitle(intent.getStringExtra(Constants.DATA_KEY_NOTIFICATION_TITLE))
.setCancelable(false)
.setPositiveButton(R.string.ok_string,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(PendingApprovalsActivity.this);
builder.setMessage(intent.getStringExtra(Constants.DATA_KEY_NOTIFICATION_MESSAGE))
.setTitle(intent.getStringExtra(Constants.DATA_KEY_NOTIFICATION_TITLE))
.setCancelable(false)
.setPositiveButton(R.string.go_to_notification_string,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
startActivity(new Intent(PendingApprovalsActivity.this,
NotificationScreen.class));
}
})
.setNegativeButton(R.string.ok_string, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
......@@ -332,4 +389,19 @@ public class PendingApprovalsActivity extends HandleNotificationActivity {
}
}
}
@Override
public void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(PendingApprovalsActivity.this)
.registerReceiver(mMessageReceiver,
new IntentFilter(Constants.BROADCAST_NOTIFICATION));
}
@Override
public void onPause() {
LocalBroadcastManager.getInstance(PendingApprovalsActivity.this)
.unregisterReceiver(mMessageReceiver);
super.onPause();
}
}
......@@ -32,6 +32,7 @@ public class Constants {
public static final String DATA_KEY_CATALOGUE_ITEM_SHORT_DESCRIPTION = "catalogue_item_short_des";
public static final String DATA_KEY_NOTIFICATION_TITLE = "notification_title";
public static final String DATA_KEY_NOTIFICATION_MESSAGE = "notification_message";
public static final String DATA_KEY_NOTIFICATION_IS_APPROVALS = "notification_is_approvals";
public static final String DATA_KEY_LOGIN_REQUEST_CODE = "login_request_code";
public static final String DATA_KEY_CATEGORY_SYS_ID = "category_sys_id";
public static final String DATA_KEY_HR_CASE_TITLE = "hr_case_title";
......
......@@ -113,7 +113,11 @@
<string name="notification_screen_action_bar_title_string">Notifications</string>
<string name="notification_screen_empty_text_string">No Notifications</string>
<string name="go_to_notification_string">Go to Notification</string>
<string name="notification_status_bar_title_string">New Incident assigned to you</string>
<string name="go_to_approvals_string">Go to Approvals</string>
<string name="notification_status_bar_incident_title_string">New Incident assigned to you</string>
<string name="notification_status_bar_hr_case_title_string">New HR Case assigned to you</string>
<string name="notification_status_bar_request_title_string">New Request assigned to you</string>
<string name="notification_status_bar_approvals_title_string">New Approval assigned to you</string>
<!--Chat Related String-->
<string name="chat_activity_label">Vera</string>
......
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