Commit 48cbd1ba by Kunj Gupta

Added two new features -

Get all pending approvals list.
Update pending approval with Approve and Reject state.
parent 7208b9b9
Showing with 1492 additions and 14 deletions
...@@ -109,6 +109,7 @@ dependencies { ...@@ -109,6 +109,7 @@ dependencies {
compile 'com.android.support:support-media-compat:27.1.0' compile 'com.android.support:support-media-compat:27.1.0'
compile 'com.android.support:support-v4:27.1.0' compile 'com.android.support:support-v4:27.1.0'
compile 'com.google.firebase:firebase-messaging:12.0.1' compile 'com.google.firebase:firebase-messaging:12.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
} }
apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.gms.google-services'
\ No newline at end of file
package com.vsoft.servicenow.adapters;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import com.vsoft.servicenow.R;
import com.vsoft.servicenow.db.models.HRCase;
import com.vsoft.servicenow.db.models.PendingApprovals;
import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.Util;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Kunj on 26/04/18.
*/
public class PendingApprovalsAdapter extends BaseAdapter {
private final List<PendingApprovals> mPendingApprovalsList = new ArrayList<>(0);
private LayoutInflater mInflater;
private Context mContext;
public PendingApprovalsAdapter(Context context) {
mContext = context;
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void setPendingApprovalsList(List<PendingApprovals> pendingApprovalsList) {
mPendingApprovalsList.clear();
if(pendingApprovalsList!=null)
mPendingApprovalsList.addAll(pendingApprovalsList);
notifyDataSetChanged();
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return mPendingApprovalsList.size();
}
@Override
public PendingApprovals getItem(int position) {
// TODO Auto-generated method stub
return mPendingApprovalsList.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.pending_approvals_adapter, parent, false);
holder = new ViewHolder();
holder.sysApproval = convertView.findViewById(R.id.pending_approval_adapter_sysapproval);
holder.taskType = convertView.findViewById(R.id.pending_approval_adapter_task_type);
holder.shortDes = convertView.findViewById(R.id.pending_approval_adapter_short_des);
holder.openedFor = convertView.findViewById(R.id.pending_approval_adapter_opened_for);
holder.openedAt = convertView.findViewById(R.id.pending_approval_adapter_opened_at);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
PendingApprovals pendingApprovals = mPendingApprovalsList.get(position);
holder.sysApproval.setText(pendingApprovals.getSysapproval());
holder.taskType.setText(pendingApprovals.getTaskType());
holder.shortDes.setText(pendingApprovals.getShortDescription());
holder.openedFor.setText(pendingApprovals.getOpenedBy());
holder.openedAt.setText(Util.getDateTimePendingApprovalFromString(pendingApprovals.getOpenedAt()));
return convertView;
}
static class ViewHolder {
private TextView sysApproval, taskType, shortDes, openedFor, openedAt;
}
}
\ No newline at end of file
package com.vsoft.servicenow.api.interfaces;
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;
/**
* @since 1.0
* @author Created by Kunj on 26/04/2018.
*
*/
public interface PendingApprovalsApi {
String APPROVER = "approver";
String STATE = "state";
String STATE_VALUE = "requested";
String PUT_STATE_JSON_OBJECT_NAME = "state";
String PUT_COMMENT_JSON_OBJECT_NAME = "comments";
String PUT_STATE_APPROVED = "approved";
String PUT_STATE_REJECTED = "rejected";
String SYS_ID_OF_APPROVAL_RECORD = "sys_id_of_approval_record";
// Get All Pending Approvals API
@GET(Constants.URL_GET_ALL_PENDING_APPROVALS)
Call<ResponseBody> getAllPendingApprovals(@Query(APPROVER) String userSysId,
@Query(STATE) String stateValue);
@PUT(Constants.URL_PUT_PENDING_APPROVAL_STATE)
Call<ResponseBody> updatePendingApprovalState(@Path(SYS_ID_OF_APPROVAL_RECORD) String sysId,
@Body String stateBody);
}
...@@ -9,7 +9,6 @@ import retrofit2.http.GET; ...@@ -9,7 +9,6 @@ import retrofit2.http.GET;
import retrofit2.http.PUT; import retrofit2.http.PUT;
import retrofit2.http.Path; import retrofit2.http.Path;
import retrofit2.http.Query; import retrofit2.http.Query;
import retrofit2.http.Url;
/** /**
...@@ -24,7 +23,7 @@ public interface UserApi { ...@@ -24,7 +23,7 @@ public interface UserApi {
@GET(Constants.URL_GET_USERDETAILS) @GET(Constants.URL_GET_USERDETAILS)
Call<ResponseBody> getuserDetails(@Query(Constants.URL_PARAM_SYSPRM_USERNAME) String sysparmQuery); Call<ResponseBody> getuserDetails(@Query(Constants.URL_PARAM_SYSPRM_USERNAME) String sysparmQuery);
@PUT(Constants.URL_PUT_DEVICE_REGISTERATION) @PUT(Constants.URL_PUT_DEVICE_REGISTRATION)
Call<ResponseBody> putDeviceRegistration(@Path("user_sys_id") String userSysId, @Body String body); Call<ResponseBody> putDeviceRegistration(@Path("user_sys_id") String userSysId, @Body String body);
} }
......
package com.vsoft.servicenow.api.listeners.get;
import com.vsoft.servicenow.db.models.PendingApprovals;
import java.util.List;
/**
* @since 1.0
* @author Created by Kunj on 26/04/2018.
*
*/
public interface GetPendingApprovalsApiListener {
void onDoneApiCall(List<PendingApprovals> pendingApprovalsList);
void onFailApiCall();
}
package com.vsoft.servicenow.api.listeners.put;
/**
* @since 1.0
* @author Created by Kunj on 26/04/2018.
*
*/
public interface PutPendingApprovalApiListener {
void onDoneApiCall();
void onFailApiCall();
}
package com.vsoft.servicenow.api.managers;
import android.content.Context;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.vsoft.servicenow.api.RestClient;
import com.vsoft.servicenow.api.interfaces.PendingApprovalsApi;
import com.vsoft.servicenow.api.listeners.get.GetPendingApprovalsApiListener;
import com.vsoft.servicenow.api.listeners.put.PutPendingApprovalApiListener;
import com.vsoft.servicenow.db.models.PendingApprovals;
import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.PrefManager;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
/**
* Created by Kunj on 26/04/2018.
*/
public class PendingApprovalsApiManager {
public static SyncStatus getPendingApprovals(Context context, GetPendingApprovalsApiListener listener) {
String accessToken = PrefManager.getSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN);
String userSysId = PrefManager.getSharedPref(context, PrefManager.PREFERENCE_USER_SYS_ID);
if(accessToken.isEmpty()) {
listener.onFailApiCall();
return SyncStatus.FAIL;
}
final Retrofit retrofit = RestClient.getInitializedRestAdapter(accessToken);
Call<ResponseBody> call = retrofit.create(PendingApprovalsApi.class).getAllPendingApprovals(userSysId, PendingApprovalsApi.STATE_VALUE);
try {
//Retrofit synchronous call
Response<ResponseBody> response = call.execute();
if (response.isSuccessful()) {
try {
JSONObject jsonObject = new JSONObject(response.body().string());
JSONObject error = jsonObject.optJSONObject(Constants.RESPONSE_ERROR_OBJECT_NAME);
if (error == null) {
JSONArray pendingApprovalsJsonArray = jsonObject.getJSONArray(Constants.RESPONSE_RESULT_OBJECT_NAME);
if(pendingApprovalsJsonArray.length() > 0) {
Gson gson = new GsonBuilder()
.excludeFieldsWithoutExposeAnnotation()
.registerTypeAdapter(long.class, new JsonDeserializer<Long>() {
@Override
public Long deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
long value = 0;
try {
value = json.getAsLong();
} catch (NumberFormatException e) {
CatalogueLog.d("PendingApprovalsApiManager: getPendingApprovals: deserialize: long.class: NumberFormatException: ");
}
return value;
}
})
.registerTypeAdapter(int.class, new JsonDeserializer<Integer>() {
@Override
public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
int value = 0;
try {
value = json.getAsInt();
} catch (NumberFormatException e) {
CatalogueLog.d("PendingApprovalsApiManager: getPendingApprovals: deserialize: int.class: NumberFormatException: ");
}
return value;
}
})
.registerTypeAdapter(float.class, new JsonDeserializer<Float>() {
@Override
public Float deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
float value = 0;
try {
value = json.getAsFloat();
} catch (NumberFormatException e) {
CatalogueLog.e("PendingApprovalsApiManager: getPendingApprovals: deserialize: float.class: NumberFormatException: ", e);
}
return value;
}
})
.create();
List<PendingApprovals> pendingApprovalsArrayList = new ArrayList<>(pendingApprovalsJsonArray.length());
for (int i = 0; i < pendingApprovalsJsonArray.length(); i++) {
JSONObject pendingApprovalsJsonObject = pendingApprovalsJsonArray.getJSONObject(i);
PendingApprovals pendingApprovals = gson.fromJson(pendingApprovalsJsonObject.toString(), PendingApprovals.class);
pendingApprovals.parseJson(pendingApprovalsJsonObject);
pendingApprovalsArrayList.add(pendingApprovals);
}
listener.onDoneApiCall(pendingApprovalsArrayList);
} else {
listener.onDoneApiCall(new ArrayList<PendingApprovals>(0));
}
return SyncStatus.SUCCESS;
} else
return SyncStatus.FAIL;
} catch (JSONException e) {
CatalogueLog.e("PendingApprovalsApiManager: getPendingApprovals: onResponse: ", e);
return SyncStatus.FAIL;
} catch (IOException e) {
CatalogueLog.e("PendingApprovalsApiManager: getPendingApprovals: onResponse: ", e);
return SyncStatus.FAIL;
}
} else {
CatalogueLog.d("MyRequestApiManager: getMyRequest: response is not success");
if(response.code() == 401) {
Log.d(Constants.TAG, "-- is 401, try refresh token...");
SyncStatus status = LoginApiManager.refreshLogin(context, PrefManager.getSharedPref(context, PrefManager.PREFERENCE_REFRESH_TOKEN));
if(status == SyncStatus.SUCCESS) {
CatalogueLog.d("refresh token success, retry same...");
return getPendingApprovals(context, listener);
} else {
CatalogueLog.d("refresh token failed, return FAIL");
listener.onFailApiCall();
return SyncStatus.FAIL;
}
} else {
listener.onFailApiCall();
return SyncStatus.FAIL;
}
}
} catch (IOException e) {
CatalogueLog.e("PendingApprovalsApiManager: getPendingApprovals: IOException: ", e);
return SyncStatus.FAIL;
} catch (NullPointerException e) {
CatalogueLog.e("PendingApprovalsApiManager: getPendingApprovals: NullPointerException: ", e);
return SyncStatus.FAIL;
}
}
public static void updatePendingApprovalState(Context context, String pendingApprovalSysId, String stateBody, PutPendingApprovalApiListener listener) {
CatalogueLog.d("PendingApprovalsApiManager: updatePendingApprovalState");
String accessToken = PrefManager.getSharedPref(context, PrefManager.PREFERENCE_ACCESS_TOKEN);
if (accessToken.isEmpty()) {
listener.onFailApiCall();
return;
}
final Retrofit retrofit = RestClient.getInitializedRestAdapter(accessToken);
Call<ResponseBody> call = retrofit.create(PendingApprovalsApi.class).updatePendingApprovalState(pendingApprovalSysId, stateBody);
try {
Response<ResponseBody> response = call.execute();
if (response.isSuccessful()) {
listener.onDoneApiCall();
} else {
CatalogueLog.d("PendingApprovalsApiManager: updatePendingApprovalState: response is not success");
if (response.code() == 401) {
Log.d(Constants.TAG, "-- is 401, try refresh token...");
Log.d(Constants.TAG, "refresh token: " + PrefManager.getSharedPref(context, PrefManager.PREFERENCE_REFRESH_TOKEN));
SyncStatus status = LoginApiManager.refreshLogin(context, PrefManager.getSharedPref(context, PrefManager.PREFERENCE_REFRESH_TOKEN));
if (status == SyncStatus.SUCCESS) {
CatalogueLog.d("refresh token success, retry same...");
updatePendingApprovalState(context, pendingApprovalSysId, stateBody, listener);
} else {
CatalogueLog.d("refresh token failed, return FAIL");
}
} else {
listener.onFailApiCall();
}
}
} catch(IOException e) {
CatalogueLog.e("updatePendingApprovalState: IOException: ", e);
listener.onFailApiCall();
}
}
}
...@@ -29,6 +29,7 @@ public interface DBConstants { ...@@ -29,6 +29,7 @@ public interface DBConstants {
String TABLE_HR_CASE_VARIABLE_CHOICES = "hr_case_variable_choices"; String TABLE_HR_CASE_VARIABLE_CHOICES = "hr_case_variable_choices";
String TABLE_MY_HR_CASE_REQUEST = "hr_case_requests"; String TABLE_MY_HR_CASE_REQUEST = "hr_case_requests";
String TABLE_MY_HR_CASE_REQUEST_OPENED_BY = "hr_case_request_opened_by"; String TABLE_MY_HR_CASE_REQUEST_OPENED_BY = "hr_case_request_opened_by";
String TABLE_PENDING_APPROVALS = "pending_approval";
String ID = "_id"; String ID = "_id";
String SYS_ID = "sys_id"; String SYS_ID = "sys_id";
...@@ -650,4 +651,34 @@ public interface DBConstants { ...@@ -650,4 +651,34 @@ public interface DBConstants {
int INDEX_MY_HR_CASE_REQUEST_OPENED_BY_SYNC_DIRTY = 3; int INDEX_MY_HR_CASE_REQUEST_OPENED_BY_SYNC_DIRTY = 3;
int MY_HR_CASE_REQUEST_OPENED_BY_COLUMN_COUNT = 4; int MY_HR_CASE_REQUEST_OPENED_BY_COLUMN_COUNT = 4;
/**
* TABLE_PENDING_APPROVALS table
*/
String PENDING_APPROVALS_ID = ID;
String PENDING_APPROVALS_SYS_ID = SYS_ID;
String PENDING_APPROVALS_APPROVER = "approver";
String PENDING_APPROVALS_SYS_APPROVAL = "sys_approval";
String PENDING_APPROVALS_TASK_TYPE = "task_type";
String PENDING_APPROVALS_OPENED_FOR = "opened_for";
String PENDING_APPROVALS_SHORT_DESCRIPTION = "short_description";
String PENDING_APPROVALS_OPENED_BY = "opened_by";
String PENDING_APPROVALS_OPENED_AT = "opened_at";
String PENDING_APPROVALS_SYNC_DIRTY = SYNC_DIRTY;
/**
* TABLE_PENDING_APPROVALS table. *Use these only if you fetch all columns*
*/
int INDEX_PENDING_APPROVALS_ID = 0;
int INDEX_PENDING_APPROVALS_SYS_ID = 1;
int INDEX_PENDING_APPROVALS_APPROVER = 2;
int INDEX_PENDING_APPROVALS_SYS_APPROVAL = 3;
int INDEX_PENDING_APPROVALS_TASK_TYPE = 4;
int INDEX_PENDING_APPROVALS_OPENED_FOR = 5;
int INDEX_PENDING_APPROVALS_SHORT_DESCRIPTION = 6;
int INDEX_PENDING_APPROVALS_OPENED_BY = 7;
int INDEX_PENDING_APPROVALS_OPENED_AT = 8;
int INDEX_PENDING_APPROVALS_SYNC_DIRTY = 9;
int PENDING_APPROVALS_COLUMN_COUNT = 10;
} }
\ No newline at end of file
...@@ -62,6 +62,8 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants { ...@@ -62,6 +62,8 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
createMyHRCaseRequestTable(db); createMyHRCaseRequestTable(db);
createMyHRCaseRequestOpenedByTable(db); createMyHRCaseRequestOpenedByTable(db);
} }
createPendingApprovalsTable(db);
} }
@Override @Override
...@@ -359,4 +361,18 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants { ...@@ -359,4 +361,18 @@ public class DBManager extends SQLiteOpenHelper implements DBConstants {
+ MY_HR_CASE_REQUEST_OPENED_BY_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE + ");"); + MY_HR_CASE_REQUEST_OPENED_BY_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE + ");");
} }
private void createPendingApprovalsTable(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_PENDING_APPROVALS + "("
+ PENDING_APPROVALS_ID + " integer primary key autoincrement, "
+ PENDING_APPROVALS_SYS_ID + " text, "
+ PENDING_APPROVALS_APPROVER + " text, "
+ PENDING_APPROVALS_SYS_APPROVAL + " text, "
+ PENDING_APPROVALS_TASK_TYPE + " text, "
+ PENDING_APPROVALS_OPENED_FOR + " text, "
+ PENDING_APPROVALS_SHORT_DESCRIPTION + " text, "
+ PENDING_APPROVALS_OPENED_BY + " text, "
+ PENDING_APPROVALS_OPENED_AT + " real, "
+ PENDING_APPROVALS_SYNC_DIRTY + " integer default " + SYNC_FLAG_NONE + ");");
}
} }
package com.vsoft.servicenow.db.managers;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.db.DBConstants;
import com.vsoft.servicenow.db.models.PendingApprovals;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
*
* @author Kunj on 11/04/18.
*/
public class PendingApprovalsManager implements DBConstants {
public static long save(PendingApprovals pendingApprovals, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
pendingApprovals.setSyncDirty(syncDirty);
long id = db.insert(TABLE_PENDING_APPROVALS, null, getContentValues(pendingApprovals));
pendingApprovals.setId(id);
return id;
} else {
return -1;
}
}
public static int delete(PendingApprovals pendingApprovals) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
return db.delete(TABLE_PENDING_APPROVALS, DBConstants.PENDING_APPROVALS_ID + "=" + pendingApprovals.getId(), null);
}
return -1;
}
public static int update(PendingApprovals pendingApprovals, int syncDirty) {
return update(pendingApprovals, null, syncDirty);
}
public static int update(PendingApprovals pendingApprovals, List<String> column, int syncDirty) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
pendingApprovals.setSyncDirty(syncDirty);
if (column == null || column.size() == 0) {
return db.update(TABLE_PENDING_APPROVALS, getContentValues(pendingApprovals), PENDING_APPROVALS_ID + "=" + pendingApprovals.getId(), null);
} else {
ContentValues contentValues = new ContentValues(column.size());
contentValues.put(PENDING_APPROVALS_SYNC_DIRTY, pendingApprovals.getSyncDirty());
for (int i = 0; i < column.size(); i++) {
String columnName = column.get(i);
if (PENDING_APPROVALS_SYS_ID.equals(columnName)) {
contentValues.put(PENDING_APPROVALS_SYS_ID, pendingApprovals.getSysId());
} else if (PENDING_APPROVALS_APPROVER.equals(columnName)) {
contentValues.put(PENDING_APPROVALS_APPROVER, pendingApprovals.getApprover());
} else if (PENDING_APPROVALS_SYS_APPROVAL.equals(columnName)) {
contentValues.put(PENDING_APPROVALS_SYS_APPROVAL, pendingApprovals.getSysapproval());
} else if (PENDING_APPROVALS_TASK_TYPE.equals(columnName)) {
contentValues.put(PENDING_APPROVALS_TASK_TYPE, pendingApprovals.getTaskType());
} else if (PENDING_APPROVALS_OPENED_FOR.equals(columnName)) {
contentValues.put(PENDING_APPROVALS_OPENED_FOR, pendingApprovals.getOpenedFor());
} else if (PENDING_APPROVALS_SHORT_DESCRIPTION.equals(columnName)) {
contentValues.put(PENDING_APPROVALS_SHORT_DESCRIPTION, pendingApprovals.getShortDescription());
} else if (PENDING_APPROVALS_OPENED_BY.equals(columnName)) {
contentValues.put(PENDING_APPROVALS_OPENED_BY, pendingApprovals.getOpenedBy());
} else if (PENDING_APPROVALS_OPENED_AT.equals(columnName)) {
contentValues.put(PENDING_APPROVALS_OPENED_AT, pendingApprovals.getOpenedAt());
}
}
return db.update(TABLE_PENDING_APPROVALS, contentValues, PENDING_APPROVALS_ID + "=" + pendingApprovals.getId(), null);
}
} else {
return -1;
}
}
public static void handleGetPendingApprovals(List<PendingApprovals> serverPendingApprovalsList) {
if(serverPendingApprovalsList != null && !serverPendingApprovalsList.isEmpty()) {
/*pendingApprovalsSysIdMap contain all server response PendingApprovals Sys Id*/
HashMap<String, Integer> pendingApprovalsSysIdMap = new HashMap<>(0);
Integer intObj = Integer.valueOf(1);
for (int i = 0; i < serverPendingApprovalsList.size(); i++) {
String sysId = serverPendingApprovalsList.get(i).getSysId();
pendingApprovalsSysIdMap.put(sysId, intObj);
}
/*localPendingApprovalsList is contain all local PendingApprovals */
List<PendingApprovals> localPendingApprovalsList = getAllPendingApprovals();
if (localPendingApprovalsList != null && !localPendingApprovalsList.isEmpty()) {
for (int i = 0; i < localPendingApprovalsList.size(); i++) {
PendingApprovals localPendingApprovals = localPendingApprovalsList.get(i);
String localPendingApprovalsSysId = localPendingApprovals.getSysId();
if (localPendingApprovalsSysId != null
&& !localPendingApprovalsSysId.isEmpty()
&& !pendingApprovalsSysIdMap.containsKey(localPendingApprovalsSysId)) {
//Update sys_id with empty string because required to delete locally
localPendingApprovals.setSysId("");
delete(localPendingApprovals);
}
}
}
/*Check this PendingApprovals is exist in local DB or not
* If doesn't exist in local, save it
* If exist in local, update the local item with data from server item.
* */
for (int i = 0; i < serverPendingApprovalsList.size(); i++) {
PendingApprovals pendingApprovals = serverPendingApprovalsList.get(i);
PendingApprovals localPendingApprovals = getPendingApprovalsFromSysId(pendingApprovals.getSysId());
if (localPendingApprovals == null) {
save(pendingApprovals, DBConstants.SYNC_FLAG_NONE);
} else {
/*Update complete local PendingApprovals object with response PendingApprovals object*/
pendingApprovals.setId(localPendingApprovals.getId());
update(pendingApprovals, DBConstants.SYNC_FLAG_NONE);
}
}
} else {
/*That means there is no PendingApprovals category in server response, then all local items should be deleted those are contain sys_id*/
/*localPendingApprovalsList is contain all local PendingApprovals */
List<PendingApprovals> localPendingApprovalsList = getAllPendingApprovals();
if (localPendingApprovalsList != null && !localPendingApprovalsList.isEmpty()) {
for (int i = 0; i < localPendingApprovalsList.size(); i++) {
PendingApprovals localPendingApprovals = localPendingApprovalsList.get(i);
String localPendingApprovalsSysId = localPendingApprovals.getSysId();
if (localPendingApprovalsSysId != null
&& !localPendingApprovalsSysId.isEmpty()) {
//Update sys_id with empty string because required to delete locally
localPendingApprovals.setSysId("");
delete(localPendingApprovals);
}
}
}
}
}
public static List<PendingApprovals> getAllPendingApprovals() {
SQLiteDatabase db = CatalogueApplication.getDatabase();
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_PENDING_APPROVALS
+ " where " + PENDING_APPROVALS_SYNC_DIRTY
+ "!=" + DBConstants.SYNC_FLAG_DELETE, null);
ArrayList<PendingApprovals> approvalsArrayList;
if (c.getCount() > 0) {
approvalsArrayList = new ArrayList<>(c.getCount());
while (c.moveToNext()) {
PendingApprovals.PendingApprovalsBuilder builder = PendingApprovals.PendingApprovalsBuilder.aPendingApproval();
fillAllPendingApprovalsDetails(c, builder);
approvalsArrayList.add(builder.build());
}
} else {
approvalsArrayList = new ArrayList<>(0);
}
c.close();
return approvalsArrayList;
} else {
return new ArrayList<>(0);
}
}
public static PendingApprovals get(long pendingApprovalId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
PendingApprovals pendingApprovals = null;
if (db != null) {
Cursor c = db.rawQuery("select * from " + TABLE_PENDING_APPROVALS + " where " + PENDING_APPROVALS_ID + "=" + pendingApprovalId, null);
if (c.moveToFirst()) {
PendingApprovals.PendingApprovalsBuilder builder = PendingApprovals.PendingApprovalsBuilder.aPendingApproval();
fillAllPendingApprovalsDetails(c, builder);
pendingApprovals = builder.build();
}
c.close();
}
return pendingApprovals;
}
public static PendingApprovals getPendingApprovalsFromSysId(String sysId) {
SQLiteDatabase db = CatalogueApplication.getDatabase();
PendingApprovals pendingApprovals = null;
if(db!=null) {
Cursor c = db.rawQuery("select * from " + TABLE_PENDING_APPROVALS + " where " + PENDING_APPROVALS_SYS_ID + "='" + sysId + "'", null);
if (c.moveToFirst()) {
PendingApprovals.PendingApprovalsBuilder builder = PendingApprovals.PendingApprovalsBuilder.aPendingApproval();
fillAllPendingApprovalsDetails(c, builder);
pendingApprovals = builder.build();
}
c.close();
}
return pendingApprovals;
}
private static void fillAllPendingApprovalsDetails(Cursor c, PendingApprovals.PendingApprovalsBuilder builder) {
builder.setId(c.getLong(INDEX_PENDING_APPROVALS_ID));
builder.setSysId(c.getString(INDEX_PENDING_APPROVALS_SYS_ID));
builder.setApprover(c.getString(INDEX_PENDING_APPROVALS_APPROVER));
builder.setSysapproval(c.getString(INDEX_PENDING_APPROVALS_SYS_APPROVAL));
builder.setTaskType(c.getString(INDEX_PENDING_APPROVALS_TASK_TYPE));
builder.setOpenedFor(c.getString(INDEX_PENDING_APPROVALS_OPENED_FOR));
builder.setShortDescription(c.getString(INDEX_PENDING_APPROVALS_SHORT_DESCRIPTION));
builder.setOpenedBy(c.getString(INDEX_PENDING_APPROVALS_OPENED_BY));
builder.setOpenedAt(c.getLong(INDEX_PENDING_APPROVALS_OPENED_AT));
builder.setSyncDirty(c.getInt(INDEX_PENDING_APPROVALS_SYNC_DIRTY));
}
private static ContentValues getContentValues(PendingApprovals pendingApprovals) {
ContentValues cv = new ContentValues(PENDING_APPROVALS_COLUMN_COUNT - 1);
cv.put(PENDING_APPROVALS_SYS_ID, pendingApprovals.getSysId());
cv.put(PENDING_APPROVALS_APPROVER, pendingApprovals.getApprover());
cv.put(PENDING_APPROVALS_SYS_APPROVAL, pendingApprovals.getSysapproval());
cv.put(PENDING_APPROVALS_TASK_TYPE, pendingApprovals.getTaskType());
cv.put(PENDING_APPROVALS_OPENED_FOR, pendingApprovals.getOpenedFor());
cv.put(PENDING_APPROVALS_SHORT_DESCRIPTION, pendingApprovals.getShortDescription());
cv.put(PENDING_APPROVALS_OPENED_BY, pendingApprovals.getOpenedBy());
cv.put(PENDING_APPROVALS_OPENED_AT, pendingApprovals.getOpenedAt());
cv.put(PENDING_APPROVALS_SYNC_DIRTY, pendingApprovals.getSyncDirty());
return cv;
}
}
\ No newline at end of file
package com.vsoft.servicenow.db.models;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.vsoft.servicenow.utils.Util;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Created by Kunj on 26/04/2018.
*/
public class PendingApprovals {
private long id = -1;
@SerializedName("sys_id")
@Expose
private String sysId;
@SerializedName("approver")
@Expose
private String approver;
@SerializedName("sysapproval")
@Expose
private String sysapproval;
@SerializedName("taskType")
@Expose
private String taskType;
@SerializedName("opened_for")
@Expose
private String openedFor;
@SerializedName("short_description")
@Expose
private String shortDescription;
@SerializedName("opened_by")
@Expose
private String openedBy;
@SerializedName("opened_at")
// @Expose
private long openedAt;
private int syncDirty;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getSysId() {
return sysId;
}
public void setSysId(String sysId) {
this.sysId = sysId;
}
public static PendingApprovalsBuilder newPendingApprovalsBuilder() {
return new PendingApprovalsBuilder();
}
public String getApprover() {
return approver;
}
public void setApprover(String approver) {
this.approver = approver;
}
public String getSysapproval() {
return sysapproval;
}
public void setSysapproval(String sysapproval) {
this.sysapproval = sysapproval;
}
public String getTaskType() {
return taskType;
}
public void setTaskType(String taskType) {
this.taskType = taskType;
}
public String getOpenedFor() {
return openedFor;
}
public void setOpenedFor(String openedFor) {
this.openedFor = openedFor;
}
public String getShortDescription() {
return shortDescription;
}
public void setShortDescription(String shortDescription) {
this.shortDescription = shortDescription;
}
public String getOpenedBy() {
return openedBy;
}
public void setOpenedBy(String openedBy) {
this.openedBy = openedBy;
}
public long getOpenedAt() {
return openedAt;
}
public void setOpenedAt(long openedAt) {
this.openedAt = openedAt;
}
public int getSyncDirty() {
return syncDirty;
}
public void setSyncDirty(int syncDirty) {
this.syncDirty = syncDirty;
}
public void parseJson(JSONObject jsonObject) {
String dueDate = null;
try {
dueDate = jsonObject.getString(Json.OPENED_AT);
} catch (JSONException e) {
e.printStackTrace();
}
this.setOpenedAt(Util.getDateTimeForMyIncidentFromString(dueDate));
}
public static class Json {
public static final String OPENED_AT = "opened_at";
}
public static final class PendingApprovalsBuilder {
private long id;
private String sysId;
private String approver;
private String sysapproval;
private String taskType;
private String openedFor;
private String shortDescription;
private String openedBy;
private long openedAt;
private int syncDirty;
private PendingApprovalsBuilder() {
}
public static PendingApprovalsBuilder aPendingApproval() {
return new PendingApprovalsBuilder();
}
public PendingApprovalsBuilder setId(long val) {
id = val;
return this;
}
public PendingApprovalsBuilder setSysId(String val) {
sysId = val;
return this;
}
public PendingApprovalsBuilder setApprover(String val) {
approver = val;
return this;
}
public PendingApprovalsBuilder setSysapproval(String val) {
sysapproval = val;
return this;
}
public PendingApprovalsBuilder setTaskType(String val) {
taskType = val;
return this;
}
public PendingApprovalsBuilder setOpenedFor(String val) {
openedFor = val;
return this;
}
public PendingApprovalsBuilder setShortDescription(String val) {
shortDescription = val;
return this;
}
public PendingApprovalsBuilder setOpenedBy(String val) {
openedBy = val;
return this;
}
public PendingApprovalsBuilder setOpenedAt(long val) {
openedAt = val;
return this;
}
public PendingApprovalsBuilder setSyncDirty(int val) {
syncDirty = val;
return this;
}
public PendingApprovals build() {
PendingApprovals pendingApprovals = new PendingApprovals();
pendingApprovals.setId(id);
pendingApprovals.setSysId(sysId);
pendingApprovals.setSysapproval(sysapproval);
pendingApprovals.setApprover(approver);
pendingApprovals.setOpenedAt(openedAt);
pendingApprovals.setOpenedBy(openedBy);
pendingApprovals.setOpenedFor(openedFor);
pendingApprovals.setShortDescription(shortDescription);
pendingApprovals.setTaskType(taskType);
pendingApprovals.setSyncDirty(syncDirty);
return pendingApprovals;
}
}
@Override
public String toString() {
return "PendingApprovals{" +
"id=" + id +
", sysId='" + sysId + '\'' +
", approver='" + approver + '\'' +
", sysapproval='" + sysapproval + '\'' +
", taskType='" + taskType + '\'' +
", openedFor='" + openedFor + '\'' +
", shortDescription='" + shortDescription + '\'' +
", openedBy='" + openedBy + '\'' +
", openedAt=" + openedAt +
", syncDirty=" + syncDirty +
'}';
}
}
package com.vsoft.servicenow.menu;
import android.os.Parcel;
import android.os.Parcelable;
import com.vsoft.servicenow.ui.PendingApprovalsActivity;
/**
* Created by Kunj on 26/04/2018.
*/
public class ApprovalsMenuItemData extends HomeScreenMenuItemData implements Parcelable {
protected ApprovalsMenuItemData() {
}
protected ApprovalsMenuItemData(Parcel in) {
super(in);
}
public static final Creator<ApprovalsMenuItemData> CREATOR = new Creator<ApprovalsMenuItemData>() {
@Override
public ApprovalsMenuItemData createFromParcel(Parcel in) {
return new ApprovalsMenuItemData(in);
}
@Override
public ApprovalsMenuItemData[] newArray(int size) {
return new ApprovalsMenuItemData[size];
}
};
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
}
@Override
public int describeContents() {
return 0;
}
public static class Builder extends HomeScreenMenuItemData.Builder<Builder> {
public Builder() {
item = new ApprovalsMenuItemData();
setActivity(PendingApprovalsActivity.class);
}
}
}
...@@ -7,32 +7,22 @@ import android.os.AsyncTask; ...@@ -7,32 +7,22 @@ import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.GridView; import android.widget.GridView;
import com.google.android.gms.analytics.Tracker; import com.google.android.gms.analytics.Tracker;
import com.vsoft.servicenow.AppConfig;
import com.vsoft.servicenow.BuildConfig; import com.vsoft.servicenow.BuildConfig;
import com.vsoft.servicenow.CatalogueApplication; import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.MenuProvider; import com.vsoft.servicenow.MenuProvider;
import com.vsoft.servicenow.R; import com.vsoft.servicenow.R;
import com.vsoft.servicenow.adapters.HomeScreenAdapter; import com.vsoft.servicenow.adapters.HomeScreenAdapter;
import com.vsoft.servicenow.api.interfaces.LoginApi;
import com.vsoft.servicenow.api.listeners.get.GetCatalogueApiListener;
import com.vsoft.servicenow.api.listeners.put.PutLogoutApiListener; import com.vsoft.servicenow.api.listeners.put.PutLogoutApiListener;
import com.vsoft.servicenow.api.managers.CatalogueApiManager;
import com.vsoft.servicenow.api.managers.LoginApiManager; import com.vsoft.servicenow.api.managers.LoginApiManager;
import com.vsoft.servicenow.db.managers.CatalogueManager;
import com.vsoft.servicenow.db.models.Catalogue;
import com.vsoft.servicenow.enums.SyncStatus; import com.vsoft.servicenow.enums.SyncStatus;
import com.vsoft.servicenow.menu.HomeScreenMenuItemData; import com.vsoft.servicenow.menu.HomeScreenMenuItemData;
import com.vsoft.servicenow.utils.CatalogueLog;
import com.vsoft.servicenow.utils.Constants; import com.vsoft.servicenow.utils.Constants;
import com.vsoft.servicenow.utils.PrefManager; import com.vsoft.servicenow.utils.PrefManager;
import com.vsoft.servicenow.utils.Util; import com.vsoft.servicenow.utils.Util;
import java.util.List;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
......
package com.vsoft.servicenow.ui;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.google.android.gms.analytics.Tracker;
import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.R;
import com.vsoft.servicenow.adapters.PendingApprovalsAdapter;
import com.vsoft.servicenow.api.interfaces.PendingApprovalsApi;
import com.vsoft.servicenow.api.listeners.get.GetPendingApprovalsApiListener;
import com.vsoft.servicenow.api.listeners.put.PutPendingApprovalApiListener;
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.DialogUtils;
import com.vsoft.servicenow.utils.Util;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnItemClick;
/**
* Created by Kunj on 26/04/2018.
* */
public class PendingApprovalsActivity extends HandleNotificationActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar;
@BindView(R.id.pending_approvals_screen_list_view) ListView mListView;
@BindView(R.id.toolbar_refresh_icon) ImageView mRefreshIcon;
@BindView(R.id.toolbar_progress_icon) ProgressBar mProgressBar;
private List<PendingApprovals> mPendingApprovalsList;
private PendingApprovalsAdapter mAdapter;
private boolean isProgressRequire;
private CatalogueApplication mApplication;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.pending_approvals_list_screen);
ButterKnife.bind(this);
mApplication = (CatalogueApplication) getApplication();
setSupportActionBar(mToolbar);
ActionBar actionBar = getSupportActionBar();
if(actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setElevation(0);
actionBar.setTitle(R.string.pending_approvals_string);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
}
Tracker tracker = mApplication.getDefaultTracker();
// Send initial screen view hit.
Util.sendScreenName(tracker, actionBar.getTitle().toString());
mAdapter = new PendingApprovalsAdapter(PendingApprovalsActivity.this);
mListView.setAdapter(mAdapter);
mPendingApprovalsList = PendingApprovalsManager.getAllPendingApprovals();
if(!mPendingApprovalsList.isEmpty()) {
setData(mPendingApprovalsList);
}
if(mApplication.isNetConnected()) {
isProgressRequire = mPendingApprovalsList.isEmpty();
new FetchPendingApprovalsData().execute();
} else {
if(mPendingApprovalsList.isEmpty()) {
DialogUtils.showNoConnectionDialogWithCloseActivity(PendingApprovalsActivity.this);
} else {
setData(mPendingApprovalsList);
}
}
}
@OnItemClick(R.id.pending_approvals_screen_list_view)
void listViewOnClicked(int position) {
final PendingApprovals pendingApprovals = mPendingApprovalsList.get(position);
LayoutInflater inflater = getLayoutInflater();
View alertLayout = inflater.inflate(R.layout.pending_approval_action_dialog_layout, null);
final TextView titleTextView = alertLayout.findViewById(R.id.pending_approval_dialog_title_text_view);
final TextView contentTextView = alertLayout.findViewById(R.id.pending_approval_dialog_message_text_view);
final EditText commentEditView = alertLayout.findViewById(R.id.pending_approval_dialog_comment_edit_view);
final TextView commentErrorTextView = alertLayout.findViewById(R.id.pending_approval_dialog_comment_error_text_view);
final Button reject = alertLayout.findViewById(R.id.pending_approval_dialog_reject_button);
final Button approve = alertLayout.findViewById(R.id.pending_approval_dialog_approve_button);
final Button cancel = alertLayout.findViewById(R.id.pending_approval_dialog_cancel_button);
String messageString = (String.format(getString(R.string.pending_approvals_dialog_message_string),
pendingApprovals.getShortDescription(),
pendingApprovals.getOpenedFor(),
Util.getDateTimePendingApprovalFromString(pendingApprovals.getOpenedAt())));
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(alertLayout);
builder.setCancelable(false);
contentTextView.setText(Html.fromHtml(messageString));
titleTextView.setText(R.string.pending_approvals_approve_reject_dialog_title_string);
final AlertDialog alertDialog = builder.create();
alertDialog.show();
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
alertDialog.dismiss();
}
});
reject.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String commentsString = commentEditView.getText().toString();
if(TextUtils.isEmpty(commentsString)) {
commentErrorTextView.setVisibility(View.VISIBLE);
} else {
commentErrorTextView.setVisibility(View.GONE);
alertDialog.dismiss();
JSONObject jsonBody = new JSONObject();
try {
jsonBody.put(PendingApprovalsApi.PUT_STATE_JSON_OBJECT_NAME, PendingApprovalsApi.PUT_STATE_REJECTED);
jsonBody.put(PendingApprovalsApi.PUT_COMMENT_JSON_OBJECT_NAME, commentsString);
} catch (JSONException e) {
e.printStackTrace();
}
new UpdatePendingApprovalState(pendingApprovals.getSysId(), jsonBody.toString()).execute();
}
}
});
approve.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String commentsString = commentEditView.getText().toString();
if(TextUtils.isEmpty(commentsString)) {
commentErrorTextView.setVisibility(View.VISIBLE);
} else {
commentErrorTextView.setVisibility(View.GONE);
alertDialog.dismiss();
JSONObject jsonBody = new JSONObject();
try {
jsonBody.put(PendingApprovalsApi.PUT_STATE_JSON_OBJECT_NAME, PendingApprovalsApi.PUT_STATE_APPROVED);
jsonBody.put(PendingApprovalsApi.PUT_COMMENT_JSON_OBJECT_NAME, commentsString);
} catch (JSONException e) {
e.printStackTrace();
}
new UpdatePendingApprovalState(pendingApprovals.getSysId(), jsonBody.toString()).execute();
}
}
});
}
@OnClick(R.id.toolbar_refresh_icon)
void onRefreshClicked() {
if(mApplication.isNetConnected()) {
new FetchPendingApprovalsData().execute();
} else {
DialogUtils.showNoConnectionDialogWithCloseActivity(PendingApprovalsActivity.this);
}
}
private void setData(final List<PendingApprovals> pendingApprovalsList) {
Collections.sort(pendingApprovalsList, new StringDateComparator());
if(mAdapter == null) {
mAdapter = new PendingApprovalsAdapter(PendingApprovalsActivity.this);
mListView.setAdapter(mAdapter);
}
mAdapter.setPendingApprovalsList(pendingApprovalsList);
}
class StringDateComparator implements Comparator<PendingApprovals> {
public int compare(PendingApprovals lhs, PendingApprovals rhs) {
return lhs.getOpenedAt()>rhs.getOpenedAt() ? -1 : 1;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == android.R.id.home) {
finish();
}
return super.onOptionsItemSelected(menuItem);
}
private void showErrorDialog(int message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(message)
.setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
AlertDialog alert = builder.create();
alert.show();
}
class FetchPendingApprovalsData extends AsyncTask<String, Void, SyncStatus> {
private SyncStatus syncStatus = SyncStatus.FAIL;
private ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
if(isProgressRequire) {
progressDialog = new ProgressDialog(PendingApprovalsActivity.this);
progressDialog.setMessage(getString(R.string.loading_string));
progressDialog.show();
progressDialog.setCancelable(false);
} else {
mRefreshIcon.setVisibility(View.GONE);
mProgressBar.setVisibility(View.VISIBLE);
}
}
@Override
protected SyncStatus doInBackground(String... params) {
PendingApprovalsApiManager.getPendingApprovals(PendingApprovalsActivity.this, new GetPendingApprovalsApiListener() {
@Override
public void onDoneApiCall(List<PendingApprovals> pendingApprovalsList) {
PendingApprovalsManager.handleGetPendingApprovals(pendingApprovalsList);
syncStatus = SyncStatus.SUCCESS;
mPendingApprovalsList = pendingApprovalsList;
}
@Override
public void onFailApiCall() {
syncStatus = SyncStatus.FAIL;
}
});
return syncStatus;
}
@Override
protected void onPostExecute(SyncStatus syncStatus) {
super.onPostExecute(syncStatus);
if(progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
} else {
mRefreshIcon.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.GONE);
}
if(syncStatus == SyncStatus.SUCCESS) {
mPendingApprovalsList = PendingApprovalsManager.getAllPendingApprovals();
isProgressRequire = mPendingApprovalsList.isEmpty();
setData(mPendingApprovalsList);
} else {
showErrorDialog(R.string.failed_to_fetch_pending_approvals_string);
}
}
}
class UpdatePendingApprovalState extends AsyncTask<String, Void, SyncStatus> {
private SyncStatus syncStatus = SyncStatus.FAIL;
private String pendingApprovalSysId;
private ProgressDialog progressDialog;
private String requestBody;
public UpdatePendingApprovalState(String pendingApprovalSysId, String requestBody) {
this.pendingApprovalSysId = pendingApprovalSysId;
this.requestBody = requestBody;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(PendingApprovalsActivity.this);
progressDialog.setMessage(getString(R.string.loading_string));
progressDialog.show();
progressDialog.setCancelable(false);
}
@Override
protected SyncStatus doInBackground(String... params) {
PendingApprovalsApiManager.updatePendingApprovalState(PendingApprovalsActivity.this, pendingApprovalSysId, requestBody, new PutPendingApprovalApiListener() {
@Override
public void onDoneApiCall() {
syncStatus = SyncStatus.SUCCESS;
}
@Override
public void onFailApiCall() {
syncStatus = SyncStatus.FAIL;
}
});
return syncStatus;
}
@Override
protected void onPostExecute(SyncStatus syncStatus) {
super.onPostExecute(syncStatus);
if(progressDialog != null && progressDialog.isShowing()) {
isProgressRequire = false;
progressDialog.dismiss();
}
if(syncStatus == SyncStatus.SUCCESS) {
new FetchPendingApprovalsData().execute();
} else {
showErrorDialog(R.string.failed_to_update_pending_approvals_string);
}
}
}
}
...@@ -2,6 +2,7 @@ package com.vsoft.servicenow.utils; ...@@ -2,6 +2,7 @@ package com.vsoft.servicenow.utils;
import com.vsoft.servicenow.BuildConfig; import com.vsoft.servicenow.BuildConfig;
import com.vsoft.servicenow.AppConfig; import com.vsoft.servicenow.AppConfig;
import com.vsoft.servicenow.api.interfaces.PendingApprovalsApi;
/** /**
* @author Kunj on 11/8/16. * @author Kunj on 11/8/16.
...@@ -148,7 +149,7 @@ public class Constants { ...@@ -148,7 +149,7 @@ public class Constants {
/*Login API */ /*Login API */
public static final String URL_POST_LOGIN_ITEM = "/oauth_token.do"; 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_REFRESH_LOGIN = URL_POST_LOGIN_ITEM;
public static final String URL_PUT_DEVICE_REGISTERATION = "api/now/table/sys_user/{user_sys_id}"; public static final String URL_PUT_DEVICE_REGISTRATION = "api/now/table/sys_user/{user_sys_id}";
public static final String URL_GET_USERDETAILS = API_PATH + "sys_user"; public static final String URL_GET_USERDETAILS = API_PATH + "sys_user";
public static final String URL_PUT_LOGOUT = "/api/vsng2/uofl_mobile/logout"; public static final String URL_PUT_LOGOUT = "/api/vsng2/uofl_mobile/logout";
...@@ -192,7 +193,10 @@ public class Constants { ...@@ -192,7 +193,10 @@ public class Constants {
/*Get All My HRCase*/ /*Get All My HRCase*/
public static final String URL_GET_MY_HR_CASE = API_PATH + "hr_case"; public static final String URL_GET_MY_HR_CASE = API_PATH + "hr_case";
// https://vsoftconsultingdev.service-now.com/api/now/table/hr_case?opened_by=debf86ee4f1852005ee63d728110c7c7
/*Get All My HRCase*/
public static final String URL_GET_ALL_PENDING_APPROVALS = DOMAIN + "api/vsng2/uofl_mobile/manager_approval";
public static final String URL_PUT_PENDING_APPROVAL_STATE = API_PATH + "sysapproval_approver/{" + PendingApprovalsApi.SYS_ID_OF_APPROVAL_RECORD + "}";
/** /**
* Chat Server URL * Chat Server URL
......
...@@ -998,6 +998,11 @@ public class Util { ...@@ -998,6 +998,11 @@ public class Util {
return 0; return 0;
} }
public static String getDateTimePendingApprovalFromString(long timeStamp) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM, yyyy");
return dateFormat.format(timeStamp);
}
public static void createDynamicTableForIncidentFormValues() { public static void createDynamicTableForIncidentFormValues() {
StringBuilder queryString = new StringBuilder(); StringBuilder queryString = new StringBuilder();
......
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/pending_approval_dialog_title_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:gravity="center"
android:paddingBottom="8dp"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@android:color/black"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@android:color/black"
app:layout_constraintTop_toBottomOf="@+id/pending_approval_dialog_title_text_view" />
<TextView
android:id="@+id/pending_approval_dialog_message_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@android:color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view" />
<EditText
android:id="@+id/pending_approval_dialog_comment_edit_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:gravity="start"
android:hint="@string/pending_approval_dialog_comment_hint_text"
android:inputType="textMultiLine|textCapSentences"
android:lines="3"
android:singleLine="false"
android:textColor="@android:color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pending_approval_dialog_message_text_view" />
<TextView
android:id="@+id/pending_approval_dialog_comment_error_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/error_string"
android:textColor="#ff0000"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pending_approval_dialog_comment_edit_view" />
<Button
android:id="@+id/pending_approval_dialog_approve_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/pending_approvals_approve_string"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pending_approval_dialog_comment_error_text_view"
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="0.3" />
<Button
android:id="@+id/pending_approval_dialog_cancel_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="@string/cancel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pending_approval_dialog_comment_error_text_view"
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="0.3" />
<Button
android:id="@+id/pending_approval_dialog_reject_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/pending_approvals_reject_string"
app:layout_constraintEnd_toStartOf="@+id/pending_approval_dialog_cancel_button"
app:layout_constraintStart_toEndOf="@+id/pending_approval_dialog_approve_button"
app:layout_constraintTop_toBottomOf="@+id/pending_approval_dialog_comment_error_text_view"
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="0.3" />
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/list_view_item_bg_with_border">
<TextView
android:id="@+id/pending_approval_adapter_sysapproval"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@android:color/black"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/pending_approval_adapter_task_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@android:color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/pending_approval_adapter_short_des"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@android:color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pending_approval_adapter_sysapproval" />
<TextView
android:id="@+id/pending_approval_adapter_opened_for"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@android:color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pending_approval_adapter_short_des" />
<TextView
android:id="@+id/pending_approval_adapter_opened_at"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="@android:color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pending_approval_adapter_short_des" />
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/screen_bg_color"
android:orientation="vertical">
<include layout="@layout/toolbar_with_refresh_option" />
<ListView
android:id="@+id/pending_approvals_screen_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/normal_margin"
android:background="@android:color/white"
android:dividerHeight="10dp"
android:divider="@android:color/white"
android:padding="@dimen/normal_margin"
android:scrollbars="none" />
</LinearLayout>
\ No newline at end of file
...@@ -40,6 +40,8 @@ ...@@ -40,6 +40,8 @@
<string name="failed_to_fetch_hr_case_category_string">Failed to fetch HR Case Category.</string> <string name="failed_to_fetch_hr_case_category_string">Failed to fetch HR Case Category.</string>
<string name="failed_to_fetch_hr_case_items_category_string">Failed to fetch HR Case Category Items.</string> <string name="failed_to_fetch_hr_case_items_category_string">Failed to fetch HR Case Category Items.</string>
<string name="failed_to_logout_string">Failed to logout.</string> <string name="failed_to_logout_string">Failed to logout.</string>
<string name="failed_to_fetch_pending_approvals_string">Failed to fetch Pending Approvals.</string>
<string name="failed_to_update_pending_approvals_string">Failed to update Pending Approvals.</string>
<!--Login Screen--> <!--Login Screen-->
<string name="prompt_relogin_login_expired">Login expired, please login again&#8230;</string> <string name="prompt_relogin_login_expired">Login expired, please login again&#8230;</string>
...@@ -177,4 +179,13 @@ ...@@ -177,4 +179,13 @@
<!--MY All HRCase Screen--> <!--MY All HRCase Screen-->
<string name="my_hr_case_text_string">View HR Case</string> <string name="my_hr_case_text_string">View HR Case</string>
<string name="my_hr_case_item_text_string"><![CDATA[<b>Number: </b>%1$s<br><br><b>Updated: </b>%2$s<br><br><b>Opened by: </b>%3$s]]></string> <string name="my_hr_case_item_text_string"><![CDATA[<b>Number: </b>%1$s<br><br><b>Updated: </b>%2$s<br><br><b>Opened by: </b>%3$s]]></string>
<!--HRCase Screen-->
<string name="pending_approvals_string">Pending Approvals</string>
<string name="no_pending_approvals_string">No Pending Approvals&#8230;</string>
<string name="pending_approvals_approve_reject_dialog_title_string">Approve/Reject</string>
<string name="pending_approvals_approve_string">Approve</string>
<string name="pending_approvals_reject_string">Reject</string>
<string name="pending_approvals_dialog_message_string"><![CDATA[%1$s<br><b>Opened For </b>%2$s<br><b>Opened on </b>%3$s]]></string>
<string name="pending_approval_dialog_comment_hint_text">Comments</string>
</resources> </resources>
...@@ -32,6 +32,10 @@ ...@@ -32,6 +32,10 @@
android:name="com.vsoft.servicenow.ui.MyHRCaseActivity" android:name="com.vsoft.servicenow.ui.MyHRCaseActivity"
android:screenOrientation="portrait"/> android:screenOrientation="portrait"/>
<activity
android:name="com.vsoft.servicenow.ui.PendingApprovalsActivity"
android:screenOrientation="portrait"/>
<service android:name=".service.NotificationInstanceIdService" <service android:name=".service.NotificationInstanceIdService"
android:exported="false"> android:exported="false">
<intent-filter> <intent-filter>
......
package com.vsoft.servicenow; package com.vsoft.servicenow;
import com.vsoft.servicenow.menu.ApprovalsMenuItemData;
import com.vsoft.servicenow.menu.ChatMenuItemData; import com.vsoft.servicenow.menu.ChatMenuItemData;
import com.vsoft.servicenow.menu.CreateHRCaseMenuItemData; import com.vsoft.servicenow.menu.CreateHRCaseMenuItemData;
import com.vsoft.servicenow.menu.HomeScreenMenuItemData; import com.vsoft.servicenow.menu.HomeScreenMenuItemData;
...@@ -50,6 +51,10 @@ public class MenuProvider { ...@@ -50,6 +51,10 @@ public class MenuProvider {
new NotificationMenuItemData.Builder() new NotificationMenuItemData.Builder()
.setTitle(R.string.home_screen_notification_title) .setTitle(R.string.home_screen_notification_title)
.setMenuIconResId(R.string.home_screen_notification_icon) .setMenuIconResId(R.string.home_screen_notification_icon)
.build(),
new ApprovalsMenuItemData.Builder()
.setTitle(R.string.home_screen_approvals_title)
.setMenuIconResId(R.string.home_screen_approvals_icon)
.build() .build()
); );
} }
...@@ -26,5 +26,8 @@ ...@@ -26,5 +26,8 @@
<string name="home_screen_notification_title">Notifications</string> <string name="home_screen_notification_title">Notifications</string>
<string name="home_screen_notification_icon">notifications</string> <string name="home_screen_notification_icon">notifications</string>
<string name="home_screen_approvals_title">Approvals</string>
<string name="home_screen_approvals_icon">approvals</string>
<!--End--> <!--End-->
</resources> </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