Commit 1310b51d by Kunj Gupta

Added Notification part and Device Registration API in Arrow.

parent ab925e59
Showing with 417 additions and 220 deletions
{
"project_info": {
"project_number": "222593508124",
"firebase_url": "https://v-soft-poc-apps.firebaseio.com",
"project_id": "v-soft-poc-apps",
"storage_bucket": "v-soft-poc-apps.appspot.com"
"project_number": "593992849158",
"project_id": "uofl-servicenow-android"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:222593508124:android:d77c1b70d2a38b4d",
"mobilesdk_app_id": "1:593992849158:android:84f481659dc7e412",
"android_client_info": {
"package_name": "com.vsoft.servicenow.arrow.debug"
"package_name": "com.vsoft.uoflservicenow"
}
},
"oauth_client": [
{
"client_id": "222593508124-1jq94gaia4oahk321cd8ud74jv6tqgr3.apps.googleusercontent.com",
"client_type": 3
}
],
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyALtTZoenaAEMfqvBLlHRsAU4P_aoOYBLg"
"current_key": "AIzaSyBEzc7fo12bQLx8CkogSGIb2j-vivdbJNg"
}
],
"services": {
"analytics_service": {
"status": 1
"status": 2,
"analytics_property": {
"tracking_id": "UA-83545030-1"
}
},
"appinvite_service": {
"status": 1,
"other_platform_oauth_client": []
},
"ads_service": {
"status": 2
"status": 1
}
}
}
],
"configuration_version": "1"
}
\ No newline at end of file
}
{
"project_info": {
"project_number": "222593508124",
"firebase_url": "https://v-soft-poc-apps.firebaseio.com",
"project_id": "v-soft-poc-apps",
"storage_bucket": "v-soft-poc-apps.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:222593508124:android:d77c1b70d2a38b4d",
"android_client_info": {
"package_name": "com.vsoft.servicenow.arrow.debug"
}
},
"oauth_client": [
{
"client_id": "222593508124-1jq94gaia4oahk321cd8ud74jv6tqgr3.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyALtTZoenaAEMfqvBLlHRsAU4P_aoOYBLg"
}
],
"services": {
"analytics_service": {
"status": 1
},
"appinvite_service": {
"status": 1,
"other_platform_oauth_client": []
},
"ads_service": {
"status": 2
}
}
}
],
"configuration_version": "1"
}
\ No newline at end of file
......@@ -5,7 +5,7 @@ package com.vsoft.servicenow;
*/
public class AppConfig {
public static final String CHAT_SERVER_URL = "http://111.93.6.218:12910/";//https://socket-io-chat.now.sh/";
public static final String CHAT_SERVER_URL = "http://111.93.6.218:12910/";
public static final String APP_INTERNAL_NAME = "Arrow";
......
package com.vsoft.servicenow.ui;
import android.app.Notification;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.TypedArray;
......@@ -31,7 +32,7 @@ import butterknife.OnItemClick;
/**
* Created by Kunj on 11/8/16.
*/
public class HomeScreen extends AppCompatActivity {
public class HomeScreen extends HandleNotificationActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar;
@BindView(R.id.home_screen_grid_view) GridView mGridView;
......@@ -73,6 +74,9 @@ public class HomeScreen extends AppCompatActivity {
Intent intent = new Intent(HomeScreen.this, ChatActivity.class);
intent.putExtra(Constants.DATA_KEY_CHAT_USER_NAME, userFirstName);
startActivity(intent);
} else if (position == 5) {
Intent intent = new Intent(HomeScreen.this, NotificationScreen.class);
startActivity(intent);
}
}
......
......@@ -6,6 +6,7 @@
<item>My Incidents</item>
<item>My Requests</item>
<item>Chatbot</item>
<item>Notifications</item>
</string-array>
<array name="home_screen_icon_array">
<item>@drawable/ic_myincident_icon</item>
......@@ -13,6 +14,7 @@
<item>@drawable/ic_my_incidents_icon</item>
<item>@drawable/ic_my_requiest_icon</item>
<item>@drawable/ic_my_requiest_icon</item>
<item>@drawable/ic_my_requiest_icon</item>
</array>
<string-array name="incident_impact_array">
<item>-None-</item>
......
......@@ -7,6 +7,8 @@ public class AppConfig {
public static final String APP_INTERNAL_NAME = "GE";
public static final String CHAT_SERVER_URL = "http://111.93.6.218:12910/";
public static final String DOMAIN_PRODUCTION = "https://ven01199.service-now.com/";
public static final String DOMAIN_TEST = "https://geapplightrnd.service-now.com/";
......
......@@ -24,7 +24,7 @@ import butterknife.OnItemClick;
/**
* Created by Kunj on 11/8/16.
*/
public class HomeScreen extends AppCompatActivity {
public class HomeScreen extends android.support.v7.app.AppCompatActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar;
@BindView(R.id.home_screen_grid_view) GridView mGridView;
......
......@@ -46,7 +46,6 @@
</compatible-screens>
<application
android:name="com.vsoft.servicenow.CatalogueApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
......@@ -88,6 +87,9 @@
<activity
android:name="com.vsoft.servicenow.ui.MyIncidentScreen"
android:screenOrientation="portrait"/>
<activity
android:name="com.vsoft.servicenow.ui.NotificationScreen"
android:screenOrientation="portrait"/>
<service android:name=".service.SyncService" />
......
......@@ -65,14 +65,9 @@ public class NotificationAdapter extends RecyclerView.Adapter<NotificationAdapte
// - replace the contents of the view with that element
final Notifications notifications = mNotificationsList.get(position);
holder.titleTextView.setText(notifications.getTitle());
holder.messageTextView.setText(notifications.getMessage());
holder.dateTextView.setText(Util.getDateTimeStringForDisplay(notifications.getTime()));
// holder.deleteImageView.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// showSuccessfulLogoutDialog(notifications);
// }
// });
holder.shortDesTextView.setText(notifications.getShortDescription());
holder.priorityTextView.setText(notifications.getPriority());
holder.createdByTextView.setText(notifications.getCreated_by());
}
/**
......@@ -87,19 +82,15 @@ public class NotificationAdapter extends RecyclerView.Adapter<NotificationAdapte
/**
* messageTextView: This is message text view.
*/
@BindView(R.id.notification_adapter_message_text_view)
TextView messageTextView;
@BindView(R.id.notification_adapter_short_des_text_view)
TextView shortDesTextView;
/**
* dateTextView: This is date text view.
*/
@BindView(R.id.notification_adapter_date_text_view)
TextView dateTextView;
/**
* deleteImageView: This is delete icon image view.
*/
// @BindView(R.id.notification_adapter_delete_image_view)
// ImageView deleteImageView;
@BindView(R.id.notification_adapter_priority_text_view)
TextView priorityTextView;
@BindView(R.id.notification_adapter_created_by_text_view)
TextView createdByTextView;
/**
* Constructor of NotificationHolder class.
*/
......
......@@ -4,8 +4,12 @@ import com.vsoft.servicenow.utils.Constants;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.PUT;
import retrofit2.http.Path;
import retrofit2.http.Query;
import retrofit2.http.Url;
/**
......@@ -14,11 +18,14 @@ import retrofit2.http.Query;
*
*/
public interface UserApi {
String DEVICE_TOKEN = "u_user_device_token";
// Get Catalogue API
@GET(Constants.URL_GET_USERDETAILS)
Call<ResponseBody> getuserDetails(@Query(Constants.URL_PARAM_SYSPRM_USERNAME) String sysparmQuery);
@PUT(Constants.URL_PUT_DEVICE_REGISTERATION)
Call<ResponseBody> putDeviceRegistration(@Path("user_sys_id") String userSysId, @Body String body);
}
package com.vsoft.servicenow.api.listeners.put;
import com.vsoft.servicenow.api.pojos.LoginApiResponse;
/**
* @since 1.0
* @author Kunj on 11/8/16
*
*/
public interface PutDeviceRegistrationApiListener {
void onDoneApiCall();
void onFailApiCall();
}
......@@ -11,7 +11,9 @@ import com.google.gson.JsonParseException;
import com.vsoft.servicenow.api.interfaces.UserApi;
import com.vsoft.servicenow.api.listeners.get.GetUserDetailApiListener;
import com.vsoft.servicenow.api.RestClient;
import com.vsoft.servicenow.api.listeners.put.PutDeviceRegistrationApiListener;
import com.vsoft.servicenow.db.models.UserApiValues;
import com.vsoft.servicenow.ui.LoginScreen;
import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.PrefManager;
......@@ -120,4 +122,40 @@ public class UserApiManager {
}
}
public static void putDeviceRegistration(Context context, String userSysId, PutDeviceRegistrationApiListener listener) {
String accessToken = PrefManager.getSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN);
String deviceToken = PrefManager.getSharedPref(context, Constants.PREFS_NOTIFICATION_TOKEN);
if(accessToken.isEmpty() || deviceToken.isEmpty()) {
listener.onFailApiCall();
return;
}
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put(UserApi.DEVICE_TOKEN, deviceToken);
} catch(JSONException e) {
CatalogueLog.e("putDeviceRegistration: JSONException: " + e.toString());
}
final Retrofit retrofit = RestClient.getInitializedRestAdapter(accessToken);
Call<ResponseBody> call = retrofit.create(UserApi.class).putDeviceRegistration(userSysId, jsonObject.toString());
try {
//Retrofit synchronous call
Response<ResponseBody> response = call.execute();
if (response.isSuccessful()) {
if(response.code() == 200) {
listener.onDoneApiCall();
} else {
listener.onFailApiCall();
}
} else {
listener.onFailApiCall();
}
} catch (IOException e) {
listener.onFailApiCall();
} catch (NullPointerException e) {
listener.onFailApiCall();
}
}
}
......@@ -207,8 +207,9 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
db.execSQL("create table IF NOT EXISTS " + TABLE_NOTIFICATIONS + "("
+ NOTIFICATIONS_ID + " integer primary key autoincrement, "
+ NOTIFICATIONS_TITLE + " text, "
+ NOTIFICATIONS_MESSAGE + " text, "
+ NOTIFICATIONS_TIME + " DATETIME"
+ NOTIFICATIONS_SHORT_DES + " text, "
+ NOTIFICATIONS_PRIORITY + " text, "
+ NOTIFICATIONS_CREATED_BY + " text"
+ ");");
}
}
......@@ -5,7 +5,9 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.models.Catalogue;
import com.vsoft.servicenow.db.models.Notifications;
import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.DBConstants;
import java.util.ArrayList;
......@@ -15,7 +17,7 @@ import java.util.List;
/**
* NotificationsManager: This is database manager class of notification,
* it will handle all the operation of database for notification.
* @author Kunj on 16-01-2017.
* @author Kunj on 20-03-2018.
*/
public final class NotificationsManager implements DBConstants {
......@@ -57,10 +59,7 @@ public final class NotificationsManager implements DBConstants {
public static List<Notifications> getAllNotifications() {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_NOTIFICATIONS
+ " ORDER BY "
+ DBConstants.NOTIFICATIONS_TIME
+ " DESC", null);
Cursor c = db.rawQuery("select * from " + TABLE_NOTIFICATIONS, null);
ArrayList<Notifications> notificationsList;
if (c.getCount() > 0) {
notificationsList = new ArrayList<>(c.getCount());
......@@ -104,15 +103,18 @@ public final class NotificationsManager implements DBConstants {
private static void fillAllNotificationDetails(Cursor c, Notifications.NotificationsBuilder builder) {
builder.setId(c.getLong(INDEX_NOTIFICATIONS_ID));
builder.setTitle(c.getString(INDEX_NOTIFICATIONS_TITLE));
builder.setMessage(c.getString(INDEX_NOTIFICATIONS_MESSAGE));
builder.setTime(c.getLong(INDEX_NOTIFICATIONS_TIME));
builder.setShortDes(c.getString(INDEX_NOTIFICATIONS_SHORT_DES));
builder.setPriority(c.getString(INDEX_NOTIFICATIONS_PRIORITY));
builder.setCreatedBy(c.getString(INDEX_NOTIFICATIONS_CREATED_BY));
}
private static ContentValues getContentValues(Notifications notifications) {
CatalogueLog.e("notification: "+notifications);
ContentValues cv = new ContentValues(NOTIFICATIONS_COLUMN_COUNT - 1);
cv.put(NOTIFICATIONS_TITLE, notifications.getTitle());
cv.put(NOTIFICATIONS_MESSAGE, notifications.getMessage());
cv.put(NOTIFICATIONS_TIME, notifications.getTime());
cv.put(NOTIFICATIONS_SHORT_DES, notifications.getShortDescription());
cv.put(NOTIFICATIONS_PRIORITY, notifications.getPriority());
cv.put(NOTIFICATIONS_CREATED_BY, notifications.getCreated_by());
return cv;
}
}
......@@ -9,8 +9,9 @@ public final class Notifications {
private long id = -1;
private String title;
private String message;
private long time;
private String shortDescription;
private String created_by;
private String priority;
/**
* Default constructor.
......@@ -34,30 +35,28 @@ public final class Notifications {
this.title = title;
}
public String getMessage() {
return message;
public String getShortDescription() {
return shortDescription;
}
public void setMessage(String message) {
this.message = message;
public void setShortDescription(String shortDescription) {
this.shortDescription = shortDescription;
}
public long getTime() {
return time;
public String getCreated_by() {
return created_by;
}
public void setTime(long time) {
this.time = time;
public void setCreated_by(String created_by) {
this.created_by = created_by;
}
@Override
public String toString() {
return "Notifications{"
+ "id=" + id
+ ", title='" + title + '\''
+ ", message='" + message + '\''
+ ", time=" + time
+ '}';
public String getPriority() {
return priority;
}
public void setPriority(String priority) {
this.priority = priority;
}
/**
......@@ -66,8 +65,9 @@ public final class Notifications {
public static final class NotificationsBuilder {
private long id = -1;
private String title;
private String message;
private long time;
private String shortDescription;
private String created_by;
private String priority;
private NotificationsBuilder() {
}
......@@ -96,18 +96,20 @@ public final class Notifications {
}
/**
* setTime: This method will set the notification time.
* setMessage: This method will set the notification message.
*/
public NotificationsBuilder setTime(long notificationTime) {
this.time = notificationTime;
public NotificationsBuilder setShortDes(String shortDescription) {
this.shortDescription = shortDescription;
return this;
}
/**
* setMessage: This method will set the notification message.
*/
public NotificationsBuilder setMessage(String notificationMessage) {
this.message = notificationMessage;
public NotificationsBuilder setCreatedBy(String created_by) {
this.created_by = created_by;
return this;
}
public NotificationsBuilder setPriority(String priority) {
this.priority = priority;
return this;
}
......@@ -115,7 +117,7 @@ public final class Notifications {
* but: This method will return NotificationBuilder reference.
*/
public NotificationsBuilder but() {
return aNotification().setId(id).setTitle(title).setMessage(message).setTime(time);
return aNotification().setId(id).setTitle(title).setShortDes(shortDescription).setPriority(priority).setCreatedBy(created_by);
}
/**
......@@ -125,8 +127,9 @@ public final class Notifications {
Notifications notifications = new Notifications();
notifications.setId(id);
notifications.setTitle(title);
notifications.setMessage(message);
notifications.setTime(time);
notifications.setShortDescription(shortDescription);
notifications.setPriority(priority);
notifications.setCreated_by(created_by);
return notifications;
}
}
......
......@@ -4,11 +4,17 @@ import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
import com.google.gson.JsonObject;
import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.api.interfaces.UserApi;
import com.vsoft.servicenow.api.listeners.put.PutDeviceRegistrationApiListener;
import com.vsoft.servicenow.api.managers.UserApiManager;
import com.vsoft.servicenow.db.models.Catalogue;
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;
/**
* NotificationInstanceIdService: This is service class to get refresh token.
* @author kunj on 16/01/17.
......@@ -23,22 +29,33 @@ public class NotificationInstanceIdService extends FirebaseInstanceIdService {
CatalogueLog.d("Refreshed token: " + refreshedToken);
PrefManager.setSharedPref(CatalogueApplication.getContext(), Constants.PREFS_NOTIFICATION_TOKEN, refreshedToken);
// sendRegistrationToServer(refreshedToken);
sendRegistrationToServer(refreshedToken);
}
// private void sendRegistrationToServer(String refreshedToken) {
// long userId = SharedPreferencesStore.getSharedPrefLong(Constants.PREFS_LOGGED_IN_USER_ID);
// if (userId == -1) {
// OklahomaLog.e("NotificationInstanceIdService: sendRegistrationToServer: userId is -1.");
// return;
// }
//
// JsonObject deviceJsonObject = new JsonObject();
// deviceJsonObject.addProperty(Constants.POST_JSON_USER_ID, userId);
// deviceJsonObject.addProperty(Constants.POST_JSON_PUSH_NOTIFY_KEY, refreshedToken);
// deviceJsonObject.addProperty(Constants.POST_JSON_DEVICE_TYPE, Constants.DEVICE_TYPE);
// deviceJsonObject.addProperty(Constants.POST_JSON_TEMP_DEVICE_ID, "");
// DeviceRegistrationApiManager.postDeviceRegistration(deviceJsonObject);
// }
private void sendRegistrationToServer(String refreshedToken) {
String userSysId = PrefManager.getSharedPref(CatalogueApplication.getContext(), PrefManager.PREFERENCE_SYS_ID);
if (userSysId == null || userSysId.isEmpty()) {
CatalogueLog.e("NotificationInstanceIdService: sendRegistrationToServer: userSysId is null.");
return;
}
JSONObject deviceJsonObject = new JSONObject();
try {
deviceJsonObject.put(UserApi.DEVICE_TOKEN, refreshedToken);
} catch (JSONException e) {
CatalogueLog.e("NotificationInstanceIdService: JSONException: "+ e);
}
UserApiManager.putDeviceRegistration(CatalogueApplication.getContext(), userSysId, new PutDeviceRegistrationApiListener() {
@Override
public void onDoneApiCall() {
CatalogueLog.e("NotificationInstanceIdService: putDeviceRegistration: onDoneApiCall");
}
@Override
public void onFailApiCall() {
CatalogueLog.e("NotificationInstanceIdService: putDeviceRegistration: onFailApiCall");
}
});
}
}
......@@ -11,12 +11,16 @@ 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.utils.CatalogueLog;
import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.PrefManager;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Map;
......@@ -28,7 +32,10 @@ import java.util.Map;
public class NotificationMessagingService extends FirebaseMessagingService {
private static final String FCM_KEY_TITLE = "title";
private static final String FCM_KEY_MESSAGE = "body";
private static final String FCM_KEY_BODY = "body";
private static final String FCM_KEY_PRIORITY = "priority";
private static final String FCM_KEY_SHORT_DESCRIPTION = "short_description";
private static final String FCM_KEY_CREATED_BY = "created_by";
/**
* This is default constructor of NotificationMessagingService.
......@@ -39,30 +46,37 @@ public class NotificationMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// long userId = SharedPreferences
// .getSharedPrefLong(Constants.PREFS_LOGGED_IN_USER_ID);
// if (userId != -1) {
CatalogueLog.e("RemoteMessage: "+remoteMessage.toString());
String userSysId = PrefManager.getSharedPref(CatalogueApplication.getContext(), PrefManager.PREFERENCE_SYS_ID);
if (userSysId != null && !userSysId.isEmpty()) {
Map<String, String> dataMap = remoteMessage.getData();
CatalogueLog.e("data: "+dataMap.toString());
String title = dataMap.get(FCM_KEY_TITLE);
String message = dataMap.get(FCM_KEY_MESSAGE);
String messageBody = dataMap.get(FCM_KEY_BODY);
String priority = null, shortDes = null, createdBy = null;
try {
JSONObject jsonObject = new JSONObject(messageBody);
priority = jsonObject.getString(FCM_KEY_PRIORITY);
shortDes = jsonObject.getString(FCM_KEY_SHORT_DESCRIPTION);
createdBy = jsonObject.getString(FCM_KEY_CREATED_BY);
} catch (JSONException e) {
e.printStackTrace();
}
Notifications newNotification = new Notifications();
newNotification.setTitle(title == null ? "" : title);
newNotification.setMessage(message);
newNotification.setTime(System.currentTimeMillis());
newNotification.setTitle(title);
newNotification.setShortDescription(shortDes);
newNotification.setPriority(priority);
newNotification.setCreated_by(createdBy);
NotificationsManager.save(newNotification);
sendNotification(newNotification);
sendLocalMessage(NotificationMessagingService.this, newNotification);
// }
}
}
private void sendLocalMessage(Context context, Notifications notifications) {
Intent intent = new Intent(Constants.BROADCAST_NOTIFICATION);
intent.putExtra(Constants.DATA_KEY_NOTIFICATION_TITLE, notifications.getTitle());
intent.putExtra(Constants.DATA_KEY_NOTIFICATION_MESSAGE, notifications.getMessage());
intent.putExtra(Constants.DATA_KEY_NOTIFICATION_MESSAGE, notifications.getShortDescription());
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}
......
......@@ -44,7 +44,7 @@ import butterknife.OnClick;
/**
* Created by Kunj on 11/8/16.
*/
public class CatalogueItemScreen extends AppCompatActivity {
public class CatalogueItemScreen extends HandleNotificationActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar;
@BindView(R.id.catalogue_item_screen_list_view) ListView mListView;
......
......@@ -41,7 +41,7 @@ import butterknife.OnClick;
/**
* Created by Kunj on 11/8/16.
*/
public class CatalogueScreen extends AppCompatActivity {
public class CatalogueScreen extends HandleNotificationActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar;
@BindView(R.id.catalogue_screen_list_view) ListView mListView;
......
......@@ -108,7 +108,7 @@ import butterknife.OnClick;
/**
* Created by Kunj on 11/8/16.
*/
public class CatalogueVariableScreen extends AppCompatActivity {
public class CatalogueVariableScreen extends HandleNotificationActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar;
@BindView(R.id.variable_screen_container_layout) LinearLayout mContainerLayout;
......
package com.vsoft.servicenow.ui;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import com.vsoft.servicenow.R;
import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.Util;
/**
* Created by chaukadev on 3/20/18.
*/
public class HandleNotificationActivity extends AppCompatActivity {
@Override
public void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(HandleNotificationActivity.this)
.registerReceiver(mMessageReceiver,
new IntentFilter(Constants.BROADCAST_NOTIFICATION));
}
@Override
public void onPause() {
LocalBroadcastManager.getInstance(HandleNotificationActivity.this)
.unregisterReceiver(mMessageReceiver);
super.onPause();
}
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(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();
}
};
}
......@@ -3,6 +3,7 @@ package com.vsoft.servicenow.ui;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
......@@ -13,12 +14,15 @@ import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.analytics.Tracker;
import com.vsoft.servicenow.api.interfaces.UserApi;
import com.vsoft.servicenow.api.listeners.get.GetUserDetailApiListener;
import com.vsoft.servicenow.api.listeners.get.GetUserLoginApiListener;
import com.vsoft.servicenow.api.listeners.put.PutDeviceRegistrationApiListener;
import com.vsoft.servicenow.api.managers.LoginApiManager;
import com.vsoft.servicenow.api.managers.UserApiManager;
import com.vsoft.servicenow.api.pojos.LoginApiResponse;
import com.vsoft.servicenow.db.models.UserApiValues;
import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.DialogUtils;
import com.vsoft.servicenow.utils.KeyboardUtil;
......@@ -27,6 +31,9 @@ import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.R;
import com.vsoft.servicenow.utils.PrefManager;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.List;
import butterknife.BindView;
......@@ -151,8 +158,19 @@ public class LoginScreen extends Activity {
UserApiManager.getUserDetailResponse(LoginScreen.this, userName, new GetUserDetailApiListener() {
@Override
public void onDoneApiCall(List<UserApiValues> userValues) {
apiStatus = API_SUCCESS_USER_DETAIL;
mUserDetails = userValues;
UserApiManager.putDeviceRegistration(LoginScreen.this, userValues.get(0).getSysId(), new PutDeviceRegistrationApiListener() {
@Override
public void onDoneApiCall() {
apiStatus = API_SUCCESS_USER_DETAIL;
}
@Override
public void onFailApiCall() {
apiStatus = API_FAIL_USER_DETAIL;
}
});
}
@Override
......
......@@ -39,7 +39,7 @@ import butterknife.OnItemClick;
/**
* Created by kunj on 30/8/16.
*/
public class MyIncidentScreen extends AppCompatActivity {
public class MyIncidentScreen extends HandleNotificationActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar;
@BindView(R.id.my_incidents_screen_list_view) ListView mListView;
......
......@@ -39,7 +39,7 @@ import butterknife.OnItemClick;
/**
* Created by kvemulavada on 8/30/2016.
*/
public class MyRequestActivity extends AppCompatActivity {
public class MyRequestActivity extends HandleNotificationActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar;
@BindView(R.id.request_screen_list_view) ListView mListView;
......
......@@ -14,6 +14,7 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
......@@ -48,6 +49,8 @@ public class NotificationScreen extends AppCompatActivity {
*/
@BindView(R.id.notification_screen_empty_text_view)
TextView mEmptyTextView;
@BindView(R.id.tool_bar_view)
Toolbar mToolbar;
private NotificationAdapter mAdapter;
......@@ -67,16 +70,12 @@ public class NotificationScreen extends AppCompatActivity {
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,
.setPositiveButton(R.string.ok_string,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
updateNotificationList();
}
})
.setNegativeButton(R.string.ok_string, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
updateNotificationList();
}
});
AlertDialog alert = builder.create();
alert.show();
......@@ -91,13 +90,13 @@ public class NotificationScreen extends AppCompatActivity {
ButterKnife.bind(this);
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
setSupportActionBar(mToolbar);
ActionBar actionBar = getSupportActionBar();
if(actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(getResources()
.getString(R.string.notification_screen_action_bar_title_string));
actionBar.setElevation(0);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setTitle(R.string.notification_screen_action_bar_title_string);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
}
......@@ -153,14 +152,10 @@ public class NotificationScreen extends AppCompatActivity {
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == android.R.id.home) {
finish();
}
return super.onOptionsItemSelected(menuItem);
}
}
......@@ -37,7 +37,7 @@ import butterknife.OnClick;
/**
* Created by kunj on 30/8/16.
*/
public class ReportIncidentScreen extends AppCompatActivity {
public class ReportIncidentScreen extends HandleNotificationActivity {
@BindView(R.id.tool_bar_view)
Toolbar mToolbar;
......
......@@ -30,11 +30,14 @@ public class Constants {
public static final String DATA_KEY_CATALOGUE_ITEM_DESCRIPTION = "catalogue_item_des";
public static final String DATA_KEY_CATALOGUE_ITEM_SHORT_DESCRIPTION = "catalogue_item_short_des";
public static final String DATA_KEY_CHAT_USER_NAME = "username";
public static final String DATA_KEY_NOTIFICATION_TITLE = "notification_title";
public static final String DATA_KEY_NOTIFICATION_MESSAGE = "notification_message";
/**
* Broadcast custom intent
*/
public static final String ACTION_SYNC = "action_sync";
public static final String BROADCAST_NOTIFICATION = "broadcast_notification";
/**
* Broadcast custom intent
......@@ -146,6 +149,7 @@ public class Constants {
/*Login API */
public static final String URL_POST_LOGIN_ITEM = "/oauth_token.do";
public static final String URL_REFRESH_LOGIN = URL_POST_LOGIN_ITEM;
public static final String URL_PUT_DEVICE_REGISTERATION = "api/now/table/sys_user/{user_sys_id}";
/*Catalogue Category API */
public static final String URL_GET_CATALOGUE = DOMAIN + AppConfig.URL_GET_CATALOGUE;
......@@ -171,18 +175,4 @@ public class Constants {
/*Chat Activity*/
public static final String CHAT_USER_API_URL = DOMAIN + URL_GET_USERDETAILS.substring(1);
/**
* Broadcast String: broadcast notification.
*/
public static final String BROADCAST_NOTIFICATION = "broadcast_notification";
/**
* Intent String: Notification title.
*/
public static final String DATA_KEY_NOTIFICATION_TITLE = "notification_title";
/**
* Intent String: Notification message.
*/
public static final String DATA_KEY_NOTIFICATION_MESSAGE = "notification_message";
}
......@@ -16,6 +16,7 @@ public interface DBConstants {
String TABLE_UI_POLICY_ACTION = "ui_policy_action";
String TABLE_CATALOGUE_ITEM_INPUT = "input_catalogue_item";
String TABLE_ATTACHMENT = "attachment";
String TABLE_NOTIFICATIONS = "notifications";
String ID = "_id";
String SYS_ID = "sys_id";
......@@ -345,45 +346,24 @@ public interface DBConstants {
int ATTACHMENT_COLUMN_COUNT = 6;
/**
* Notification table name.
*/
String TABLE_NOTIFICATIONS = "notifications";
/**
* NOTIFICATIONS_ID: Id column name for Notification table.
* Notification table
*/
String NOTIFICATIONS_ID = ID;
/**
* NOTIFICATIONS_TITLE: Time column name for Notification table.
*/
String NOTIFICATIONS_TITLE = "title";
/**
* NOTIFICATIONS_MESSAGE: Message column name for Notification table.
*/
String NOTIFICATIONS_MESSAGE = "message";
/**
* NOTIFICATIONS_TIME: Time column name for Notification table.
*/
String NOTIFICATIONS_TIME = "time";
String NOTIFICATIONS_SHORT_DES = "short_des";
String NOTIFICATIONS_PRIORITY = "priority";
String NOTIFICATIONS_CREATED_BY = "created_by";
/**
* INDEX_NOTIFICATIONS_ID: Id indices for Notification table.
* Notification table. *Use these only if you fetch all columns*
*/
int INDEX_NOTIFICATIONS_ID = 0;
/**
* INDEX_NOTIFICATIONS_TITLE: Title indices for Notification table.
*/
int INDEX_NOTIFICATIONS_TITLE = 1;
/**
* INDEX_NOTIFICATIONS_MESSAGE: Message indices for Notification table.
*/
int INDEX_NOTIFICATIONS_MESSAGE = 2;
/**
* INDEX_NOTIFICATIONS_TIME: Time indices for Notification table.
*/
int INDEX_NOTIFICATIONS_TIME = 3;
int INDEX_NOTIFICATIONS_SHORT_DES = 2;
int INDEX_NOTIFICATIONS_PRIORITY = 3;
int INDEX_NOTIFICATIONS_CREATED_BY = 4;
/**
* NOTIFICATIONS_COLUMN_COUNT: Total column count for notification table.
*/
int NOTIFICATIONS_COLUMN_COUNT = 4;
int NOTIFICATIONS_COLUMN_COUNT = 5;
}
\ No newline at end of file
......@@ -8,37 +8,39 @@
android:paddingRight="@dimen/normal_margin"
android:paddingTop="@dimen/extra_large_margin">
<!--<ImageView
android:id="@+id/notification_adapter_delete_image_view"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/notification_delete"/>-->
<TextView
android:id="@+id/notification_adapter_title_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:layout_marginRight="@dimen/small_margin"
android:textColor="@android:color/white"
android:textSize="@dimen/extra_normal_text_size" />
<TextView
android:id="@+id/notification_adapter_message_text_view"
android:id="@+id/notification_adapter_short_des_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/notification_adapter_title_text_view"
android:layout_marginTop="@dimen/small_margin"
android:textColor="@android:color/white"
android:textSize="@dimen/normal_text_size" />
<TextView
android:id="@+id/notification_adapter_priority_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/notification_adapter_short_des_text_view"
android:layout_marginTop="@dimen/small_margin"
android:textColor="@android:color/white"
android:textSize="@dimen/normal_text_size" />
<TextView
android:id="@+id/notification_adapter_date_text_view"
android:id="@+id/notification_adapter_created_by_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/notification_adapter_message_text_view"
android:layout_alignParentRight="true"
android:layout_below="@id/notification_adapter_priority_text_view"
android:layout_marginTop="@dimen/small_margin"
android:layout_centerVertical="true"
android:textColor="@android:color/white"
android:textSize="@dimen/normal_text_size" />
</RelativeLayout>
\ No newline at end of file
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/notification_recycle_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:divider="@color/list_divider_color"
android:dividerHeight="@dimen/list_divider_height"
android:scrollbars="vertical"/>
<include layout="@layout/toolbar" />
<TextView
android:id="@+id/notification_screen_empty_text_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:text="@string/notification_screen_empty_text_string"
android:textSize="@dimen/normal_text_size"
android:gravity="center"
android:visibility="gone"/>
</merge>
\ No newline at end of file
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/notification_recycle_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:divider="@color/list_divider_color"
android:dividerHeight="@dimen/list_divider_height"
android:scrollbars="vertical" />
<TextView
android:id="@+id/notification_screen_empty_text_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:gravity="center"
android:text="@string/notification_screen_empty_text_string"
android:textSize="@dimen/normal_text_size"
android:visibility="gone" />
</FrameLayout>
</LinearLayout>
\ No newline at end of file
......@@ -24,6 +24,6 @@
<color name="login_screen_login_button_background_color">@color/colorPrimaryDark</color>
<color name="login_screen_edit_text_background_color">@color/colorPrimaryDark</color>
<!--Setting screen-->
<!--Notification screen-->
<color name="list_divider_color">@color/light_gray</color>
</resources>
......@@ -44,6 +44,6 @@
<dimen name="uofl_tool_bar_refresh_button_width">35dp</dimen>
<dimen name="uofl_tool_bar_refresh_button_height">35dp</dimen>
<!--Setting screen-->
<!--Notification screen-->
<dimen name="list_divider_height">0.5dp</dimen>
</resources>
\ No newline at end of file
......@@ -107,6 +107,5 @@
<!--Notifications-->
<string name="notification_screen_action_bar_title_string">Notifications</string>
<string name="notification_screen_empty_text_string">No Notifications</string>
<string name="notification_screen_delete_msg_string">Are you sure you want to delete?</string>
<string name="go_to_notification_string">Go to Notification</string>
</resources>
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