Commit bf298ac3 by HABI SHAIK

added webview screen for catalogue item selection, handled getnotification in push notifs

parent f2f40f22
......@@ -104,7 +104,7 @@ dependencies {
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.1'
implementation 'com.jakewharton:butterknife:8.8.1'
implementation ('com.google.android.gms:play-services-analytics:15.0.2') {
implementation ('com.google.android.gms:play-services-analytics:16.0.8') {
exclude group: 'com.google.firebase', module: 'firebase-iid'
}
......@@ -121,10 +121,10 @@ dependencies {
implementation 'com.android.support:animated-vector-drawable:27.1.1'
implementation 'com.android.support:support-media-compat:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation ('com.google.firebase:firebase-messaging:15.0.2') {
implementation ('com.google.firebase:firebase-messaging:17.6.0') {
exclude group: 'com.google.firebase', module: 'firebase-iid'
}
implementation 'com.google.firebase:firebase-core:15.0.2'
implementation 'com.google.firebase:firebase-core:16.0.9'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
......
......@@ -10,12 +10,13 @@
<application
android:name="com.vsoft.servicenow.CatalogueApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:allowBackup="false"
android:fullBackupContent="false"
tools:replace="allowBackup"
android:theme="@style/AppTheme">
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:usesCleartextTraffic="true"
android:theme="@style/AppTheme"
tools:replace="allowBackup">
<activity
android:name="com.vsoft.servicenow.ui.SplashScreen"
android:label="@string/app_name"
......@@ -29,7 +30,7 @@
<activity
android:name="com.vsoft.servicenow.ui.LoginScreen"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize|stateHidden"/>
android:windowSoftInputMode="adjustResize|stateHidden" />
<activity
android:name="com.vsoft.servicenow.ui.HomeScreen"
android:screenOrientation="portrait" />
......@@ -40,19 +41,22 @@
android:name="com.vsoft.servicenow.ui.CatalogueItemScreen"
android:screenOrientation="portrait" />
<activity
android:name="com.vsoft.servicenow.CatalogueWebViewScreen"
android:screenOrientation="portrait" />
<activity
android:name="com.vsoft.servicenow.ui.CatalogueVariableScreen"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize" />
<activity
android:name="com.vsoft.servicenow.ui.ReportIncidentScreen"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize"/>
android:windowSoftInputMode="stateHidden|adjustResize" />
<activity
android:name="com.vsoft.servicenow.ui.MyRequestActivity"
android:screenOrientation="portrait" />
<activity
android:name="com.vsoft.servicenow.ui.MyIncidentScreen"
android:screenOrientation="portrait"/>
android:screenOrientation="portrait" />
<service android:name=".service.SyncService" />
......
package com.vsoft.servicenow;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.PrefManager;
import java.util.HashMap;
import java.util.Map;
/**
* Created by habi on 5/24/2019.
*/
public class CatalogueWebViewScreen extends AppCompatActivity {
private WebView wv;
private ProgressDialog progressBar;
String url = "http://vsoftconsultingdev.service-now.com/sp?id=sc_cat_item&sys_id=";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_catalogue_web_view);
wv = (WebView) findViewById(R.id.webview);
Bundle extras = getIntent().getExtras();
String catalogueItemSysId = null;
if (extras != null) {
catalogueItemSysId = extras.getString(Constants.DATA_KEY_SYS_ID);
}
url = url + catalogueItemSysId;
progressBar = new ProgressDialog(CatalogueWebViewScreen.this);
progressBar.setMessage("Loading...");
progressBar.show();
WebSettings webSettings = wv.getSettings();
webSettings.setLoadWithOverviewMode(true);
webSettings.setUseWideViewPort(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setPluginState(WebSettings.PluginState.ON);
webSettings.setDomStorageEnabled(true);
webSettings.setJavaScriptEnabled(true);
wv.setWebViewClient(new myWebClient());
wv.loadUrl(url);
}
public class myWebClient extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url, getCustomHeaders());
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (progressBar.isShowing()) {
progressBar.dismiss();
}
}
}
private Map<String, String> getCustomHeaders() {
String authHeader = "Bearer " + PrefManager.getSharedPref(this, PrefManager.PREFERENCE_ACCESS_TOKEN);
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", authHeader);
return headers;
}
}
package com.vsoft.servicenow.service;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
......@@ -14,15 +13,11 @@ import android.support.v4.content.LocalBroadcastManager;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.vsoft.servicenow.CatalogueApplication;
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.ui.MyIncidentScreen;
import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.PrefManager;
import org.json.JSONException;
import org.json.JSONObject;
......@@ -43,6 +38,7 @@ public class NotificationMessagingService extends FirebaseMessagingService {
private static final String FCM_KEY_TITLE = "title";
private static final String FCM_KEY_BODY = "body";
private static final String FCM_KEY_DATA = "data";
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";
......@@ -61,31 +57,34 @@ public class NotificationMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
String userSysId = PrefManager.getSharedPref(CatalogueApplication.getContext(), PrefManager.PREFERENCE_USER_SYS_ID);
if (userSysId != null && !userSysId.isEmpty()) {
// String userSysId = PrefManager.getSharedPref(CatalogueApplication.getContext(), PrefManager.PREFERENCE_USER_SYS_ID);
// if (userSysId != null && !userSysId.isEmpty()) {
Map<String, String> dataMap = remoteMessage.getData();
RemoteMessage.Notification notificationMap = remoteMessage.getNotification();
if (dataMap != null) {
String title = dataMap.get(FCM_KEY_TITLE);
CatalogueLog.e("onMessageReceived: dataMap: "+dataMap+", title: "+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, ptoRequestStatus = null;
try {
JSONObject jsonObject = new JSONObject(messageBody);
if(!jsonObject.isNull(FCM_KEY_INCIDENT_PRIORITY)) {
if (!jsonObject.isNull(FCM_KEY_INCIDENT_PRIORITY)) {
priority = jsonObject.getString(FCM_KEY_INCIDENT_PRIORITY);
}
if(!jsonObject.isNull(FCM_KEY_SHORT_DESCRIPTION)) {
if (!jsonObject.isNull(FCM_KEY_SHORT_DESCRIPTION)) {
shortDes = jsonObject.getString(FCM_KEY_SHORT_DESCRIPTION);
}
if(!jsonObject.isNull(FCM_KEY_REQUEST_STATE)) {
if (!jsonObject.isNull(FCM_KEY_REQUEST_STATE)) {
requestState = jsonObject.getString(FCM_KEY_REQUEST_STATE);
}
if(!jsonObject.isNull(FCM_KEY_CREATED_BY)) {
if (!jsonObject.isNull(FCM_KEY_CREATED_BY)) {
createdBy = jsonObject.getString(FCM_KEY_CREATED_BY);
}
if(!jsonObject.isNull(FCM_KEY_MESSAGE_BODY_TITLE)) {
if (!jsonObject.isNull(FCM_KEY_MESSAGE_BODY_TITLE)) {
messageBodyTitle = jsonObject.getString(FCM_KEY_MESSAGE_BODY_TITLE);
}
if(!jsonObject.isNull(FCM_KEY_PTO_REQUEST_STATUS)) {
if (!jsonObject.isNull(FCM_KEY_PTO_REQUEST_STATUS)) {
ptoRequestStatus = jsonObject.getString(FCM_KEY_PTO_REQUEST_STATUS);
}
} catch (JSONException e) {
......@@ -93,12 +92,33 @@ public class NotificationMessagingService extends FirebaseMessagingService {
}
Notifications newNotification = null;
// if(messageBodyTitle.equals(MESSAGE_BODY_INCIDENT_TITLE)) {
newNotification = new Notifications();
newNotification.setTitle(title);
newNotification.setShortDescription(shortDes);
newNotification.setShortDescription(messageBody);
newNotification.setPriority(ptoRequestStatus);
newNotification.setCreated_by(createdBy);
sendNotification(newNotification, messageBodyTitle, null);
} else if (notificationMap != null) {
String title = notificationMap.getTitle();
CatalogueLog.e("onMessageReceived: notificationMap: " + notificationMap + ", title: " + title);
String messageBody = notificationMap.getBody();
String priority = null, shortDes = null, createdBy = null, messageBodyTitle = null, requestState = null, documentId = null, ptoRequestStatus = null;
Notifications newNotification = null;
newNotification = new Notifications();
newNotification.setTitle(title);
newNotification.setShortDescription(messageBody);
sendNotification(newNotification, messageBodyTitle, null);
}
// Notifications newNotification = null;
//// if(messageBodyTitle.equals(MESSAGE_BODY_INCIDENT_TITLE)) {
// newNotification = new Notifications();
// newNotification.setTitle(title);
// newNotification.setShortDescription(messageBody);
// newNotification.setPriority(ptoRequestStatus);
// newNotification.setCreated_by(createdBy);
// NotificationsManager.save(newNotification);
// } else if(messageBodyTitle.equals(MESSAGE_BODY_REQUEST_TITLE)) {
// newNotification = new Notifications();
......@@ -115,14 +135,14 @@ public class NotificationMessagingService extends FirebaseMessagingService {
// newNotification.setCreated_by(createdBy);
// }
sendNotification(newNotification, messageBodyTitle, null);
// sendNotification(newNotification, messageBodyTitle, null);
// 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, boolean isApproval) {
......@@ -157,14 +177,17 @@ public class NotificationMessagingService extends FirebaseMessagingService {
// PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
String message = "Status: " + notification.getPriority() + "\n" + notification.getShortDescription();
Intent intent = new Intent(this, MyIncidentScreen.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
intent, PendingIntent.FLAG_UPDATE_CURRENT);
// String message = "Status: " + notification.getPriority() + "\n" + notification.getShortDescription();
String message = notification.getShortDescription();
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle(notification.getTitle())
.setContentText(message)
.setAutoCancel(true)
// .setContentIntent(null)
.setContentIntent(pendingIntent)
.setChannelId(CHANNEL_ID)
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.setSound(defaultSoundUri);
......
......@@ -7,7 +7,6 @@ import android.os.AsyncTask;
import android.os.Bundle;
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.view.MenuItem;
import android.view.View;
......@@ -19,6 +18,7 @@ import android.widget.TextView;
import com.google.android.gms.analytics.Tracker;
import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.CatalogueWebViewScreen;
import com.vsoft.servicenow.R;
import com.vsoft.servicenow.adapters.CatalogueCategoryItemAdapter;
import com.vsoft.servicenow.api.listeners.get.GetCatalogueItemApiListener;
......@@ -191,11 +191,11 @@ public class CatalogueItemScreen extends HandleNotificationActivity {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
CatalogueItem catalogueItem = catalogueItemList.get(position);
Intent intent = new Intent(CatalogueItemScreen.this, CatalogueVariableScreen.class);
Intent intent = new Intent(CatalogueItemScreen.this, CatalogueWebViewScreen.class);
intent.putExtra(Constants.DATA_KEY_SYS_ID, catalogueItem.getSysId());
intent.putExtra(Constants.DATA_KEY_CATALOGUE_ITEM_DESCRIPTION, catalogueItem.getDescription());
/*intent.putExtra(Constants.DATA_KEY_CATALOGUE_ITEM_DESCRIPTION, catalogueItem.getDescription());
intent.putExtra(Constants.DATA_KEY_CATALOGUE_ITEM_SHORT_DESCRIPTION, catalogueItem.getShortDescription());
intent.putExtra(Constants.DATA_KEY_CATALOGUE_TITLE, catalogueItem.getName());
intent.putExtra(Constants.DATA_KEY_CATALOGUE_TITLE, catalogueItem.getName());*/
startActivity(intent);
}
});
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
\ No newline at end of file
......@@ -28,6 +28,9 @@
<string name="date_string">%1$s %2$s, %3$d</string>
<string name="date_and_time_string">%1$s:%2$s</string>
<string name="vera_notification_channel_id" translatable="false">vera_fcm_default_channel</string>
<string name="vera_notification_channel_name" translatable="true">VERA</string>
<!--Failed to fetch-->
<string name="failed_to_fetch_catalogue_category_string">Failed to fetch Catalogue Category.</string>
<string name="failed_to_fetch_my_request_string">Failed to fetch requests</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