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());
}
}
......@@ -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