Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.util.Log;
- import com.google.gson.GsonBuilder;
- import com.quickersupport.crewgo.helpers.DateHelperMethods;
- import com.quickersupport.crewgo.helpers.SwipetoDeleteListView.DateFormatHelper;
- import com.quickersupport.crewgo.retrofit.ApiClient;
- import com.quickersupport.crewgo.retrofit.ApiInterface;
- import com.quickersupport.crewgo.helpers.CommonDef;
- import com.quickersupport.crewgo.jobList.EventsList;
- import com.quickersupport.crewgo.login.loginParent.model.LoginResponse;
- import java.net.UnknownHostException;
- import java.util.ArrayList;
- import retrofit2.Call;
- import retrofit2.Callback;
- import retrofit2.Response;
- public class JobsModel {
- private IjobsModel ijobsModel;
- public JobsModel(IjobsModel ijobsModel) {
- this.ijobsModel = ijobsModel;
- }
- public void getWeeklyJobList(String auth_key, int jobType, int timeDifference) {
- ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);
- Call<BookingsWeeklyJobListResponse> call = apiInterface.getWeeklyJobList(auth_key,timeDifference);
- call.enqueue(new Callback<BookingsWeeklyJobListResponse>() {
- @Override
- public void onResponse(Call<BookingsWeeklyJobListResponse> call, Response<BookingsWeeklyJobListResponse> response) {
- if (response.isSuccessful()) {
- Log.e("Jobs list", new GsonBuilder().setPrettyPrinting().create().toJson(response));
- ArrayList<EventsList> list = new ArrayList<>();
- for (BookingsWeeklyJobListResponse.Week week : response.body().weeks) {
- EventsList eventsList = new EventsList();
- eventsList.isHeader = true;
- eventsList.setHeader_title(week.weekTitle);
- list.add(eventsList);
- for (BookingsWeeklyJobListResponse.Week.Day day : week.days){
- String prevDate = "";
- for (int i = 0; i < day.jobs.size() ; i++) {
- eventsList = new EventsList();
- eventsList.setJob_id(day.jobs.get(i).jobId);
- eventsList.setJob_title(day.jobs.get(i).jobTitle);
- eventsList.setJob_title_number(day.jobs.get(i).jobTitleNumber);
- eventsList.setJob_number(day.jobs.get(i).jobNumber);
- eventsList.setJob_full_address(day.jobs.get(i).jobFullAddress);
- eventsList.setJob_status(day.jobs.get(i).jobStatus);
- eventsList.setShift_status(day.jobs.get(i).shiftStatus);
- eventsList.setStart_date_time(day.jobs.get(i).startDate);
- eventsList.setEnd_date_time(day.jobs.get(i).endDate);
- eventsList.setSkillList(day.jobs.get(i).skills);
- eventsList.setShiftList(day.jobs.get(i).shiftList);
- eventsList.setUtc_start_time(day.jobs.get(i).startDateUtc);
- eventsList.setUtc_end_time(day.jobs.get(i).endDateUtc);
- eventsList.setStart_date(day.jobs.get(i).startDate);
- eventsList.setJobMeetingAddress(day.jobs.get(i).jobMeetingAddress);
- eventsList.setAllShiftList(day.jobs.get(i).allShifts);
- eventsList.setIsInductionRequired(day.jobs.get(i).hasInduction);
- eventsList.setCustomer_name(day.jobs.get(i).customerName);
- eventsList.setRefDate(day.jobs.get(i).refDate);
- String currDate = DateHelperMethods.getStringDateFormat1(DateHelperMethods.getDateFromUTCDateTime(eventsList.getRefDate()));
- if (i == 0 || !prevDate.equals(currDate)) {
- eventsList.isDateRequired = true;
- }
- list.add(eventsList);
- prevDate = currDate;
- }
- }
- eventsList = new EventsList();
- eventsList.isDivider = true;
- list.add(eventsList);
- }
- ijobsModel.onGetJobList(list);
- }
- else if (response.body().code.equalsIgnoreCase("0006")) {
- ijobsModel.onLoginError(response.body().msg);
- }
- else {
- ijobsModel.onError(response.body().msg);
- }
- }
- @Override
- public void onFailure(Call<BookingsWeeklyJobListResponse> call, Throwable t) {
- ijobsModel.onError(CommonDef.Network_Error);
- }
- });
- }
- public void getJobList(String auth_key, int jobType, int timeDifference) {
- Call<BookingsJobsListResponse> call;
- ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);
- if (jobType == CommonDef.JOBS) {
- call = apiInterface.getJobList(auth_key, timeDifference);
- }
- else {
- call = apiInterface.getSavedJobList(auth_key, timeDifference);
- }
- call.enqueue(new Callback<BookingsJobsListResponse>() {
- @Override
- public void onResponse(Call<BookingsJobsListResponse> call, Response<BookingsJobsListResponse> response) {
- if (response.isSuccessful()) {
- if (response.body().code.equalsIgnoreCase("0001")) {
- Log.e("Jobs list", new GsonBuilder().setPrettyPrinting().create().toJson(response));
- ArrayList<EventsList> list = new ArrayList<>();
- EventsList eventsList;
- for (int i = 0; i < response.body().jobs.size(); i++) {
- String prevDate = "";
- for (int j = 0; j < response.body().jobs.get(i).jobs.size(); j++) {
- eventsList = new EventsList();
- eventsList.setJob_id(response.body().jobs.get(i).jobs.get(j).jobId);
- eventsList.setJob_title(response.body().jobs.get(i).jobs.get(j).jobTitle);
- eventsList.setJob_title_number(response.body().jobs.get(i).jobs.get(j).jobTitleNumber);
- eventsList.setJob_number(response.body().jobs.get(i).jobs.get(j).jobNumber);
- eventsList.setJob_full_address(response.body().jobs.get(i).jobs.get(j).jobFullAddress);
- eventsList.setJob_status(response.body().jobs.get(i).jobs.get(j).jobStatus);
- eventsList.setShift_status(response.body().jobs.get(i).jobs.get(j).shiftStatus);
- eventsList.setStart_date_time(response.body().jobs.get(i).jobs.get(j).startDate);
- eventsList.setEnd_date_time(response.body().jobs.get(i).jobs.get(j).endDate);
- eventsList.setSkillList(response.body().jobs.get(i).jobs.get(j).skills);
- eventsList.setShiftList(response.body().jobs.get(i).jobs.get(j).shiftList);
- eventsList.setUtc_start_time(response.body().jobs.get(i).jobs.get(j).startDateUtc);
- eventsList.setUtc_end_time(response.body().jobs.get(i).jobs.get(j).endDateUtc);
- eventsList.setStart_date(response.body().jobs.get(i).date);
- eventsList.setJobMeetingAddress(response.body().jobs.get(i).jobs.get(j).jobMeetingAddress);
- eventsList.setAllShiftList(response.body().jobs.get(i).jobs.get(j).allShifts);
- eventsList.setIsInductionRequired(response.body().jobs.get(i).jobs.get(j).hasInduction);
- eventsList.setCustomer_name(response.body().jobs.get(i).jobs.get(j).customerName);
- eventsList.setRefDate(response.body().jobs.get(i).jobs.get(j).refDate);
- String currDate = DateHelperMethods.getStringDateFormat1(DateHelperMethods.getDateFromUTCDateTime(eventsList.getRefDate()));
- if (i == 0 ||!prevDate.equals(currDate)) {
- eventsList.isDateRequired = true;
- }
- list.add(eventsList);
- prevDate = currDate;
- }
- }
- ijobsModel.onGetJobList(list);
- } else if (response.body().code.equalsIgnoreCase("0006")) {
- ijobsModel.onLoginError(response.body().msg);
- } else {
- ijobsModel.onError(response.body().msg);
- }
- } else {
- ijobsModel.onError(CommonDef.Network_Error);
- }
- }
- @Override
- public void onFailure(Call<BookingsJobsListResponse> call, Throwable t) {
- if (t instanceof UnknownHostException) {
- ijobsModel.onError(CommonDef.No_Connection_Error);
- } else {
- ijobsModel.onError(CommonDef.Network_Error);
- }
- }
- });
- }
- public void deleteJob(String auth_key, String id) {
- ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);
- Call<LoginResponse> call = apiInterface.deleteJob(auth_key, id);
- call.enqueue(new Callback<LoginResponse>() {
- @Override
- public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) {
- if (response.isSuccessful()) {
- if (response.body().code.equalsIgnoreCase("0001")) {
- ijobsModel.onDeleteSuccessfull(id);
- } else {
- ijobsModel.onError(response.body().msg);
- }
- } else {
- ijobsModel.onError(CommonDef.Network_Error);
- }
- }
- @Override
- public void onFailure(Call<LoginResponse> call, Throwable t) {
- if (t instanceof UnknownHostException) {
- ijobsModel.onError(CommonDef.No_Connection_Error);
- } else {
- ijobsModel.onError(CommonDef.Network_Error);
- }
- }
- });
- }
- public void cancelJob(String auth_key, String id) {
- ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);
- Call<LoginResponse> call = apiInterface.cancelJob(auth_key, id);
- call.enqueue(new Callback<LoginResponse>() {
- @Override
- public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) {
- if (response.isSuccessful()) {
- if (response.body().code.equalsIgnoreCase("0001")) {
- ijobsModel.onDeleteSuccessfull(id);
- } else {
- ijobsModel.onError(response.body().msg);
- }
- } else {
- ijobsModel.onError(CommonDef.Network_Error);
- }
- }
- @Override
- public void onFailure(Call<LoginResponse> call, Throwable t) {
- if (t instanceof UnknownHostException) {
- ijobsModel.onError(CommonDef.No_Connection_Error);
- } else {
- ijobsModel.onError(CommonDef.Network_Error);
- }
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement