/**
* This method creates and assigns VISIT and STOPOVER type actions to the current user on
* HyperTrack API Server for the current job's orderID.
*
* @param orderID Internal order_id which maps to the current job being performed
*/
private void createActionsForJob(String orderID) {
/**
* Construct a place object for Action's expected place
*
* @NOTE: Either the coordinates for the Service Visit's location
* or it's address can be used to construct the expected place for the Action
*/
Place expectedPlace = new Place().setLocation(28.56217, 77.16160)
.setAddress("HyperTrack, Vasant Vihar")
.setName("HyperTrack");
/**
* Create ActionParams object specifying the Visit Action parameters including ExpectedPlace,
* ExpectedAt time and Lookup_id.
*/
ActionParams visitTypeActionParams = new ActionParamsBuilder()
.setExpectedPlace(expectedPlace)
.setExpectedAt(new Date())
.setType(Action.ACTION_TYPE_VISIT)
.setLookupId(orderID)
.build();
/**
* Call createAndAssignAction to assign Visit action to the current user configured
* in the SDK using the ActionParams created above.
*/
HyperTrack.createAndAssignAction(visitTypeActionParams, new HyperTrackCallback() {
@Override
public void onSuccess(@NonNull SuccessResponse response) {
// Handle createAndAssignAction API success here
Action action = (Action) response.getResponseObject();
SharedPreferenceStore.setVisitActionId(MainActivity.this, action.getId());
/**
* The VISIT Action just created has the tracking url which can be shared with your customers.
* This will enable the customer to live track the Service professional.
*
* @NOTE You can now share this tracking_url with your customers via an SMS
* or via your Customer app using in-app notifications.
*/
String trackingUrl = action.getTrackingURL();
/**
* Yay! VISIT Type Action has been successfully created and assigned to current user.
* Now, we need to createAndAssignAction for STOPOVER Type Action using same
* expected place and same lookup_id.
*/
assignStopoverActionForJob(action.getExpectedPlace().getId(), action.getLookupID());
}
@Override
public void onError(@NonNull ErrorResponse errorResponse) {
if (mProgressDialog != null) {
mProgressDialog.dismiss();
}
Toast.makeText(MainActivity.this, "Action assigned failed: " + errorResponse.getErrorMessage(),
Toast.LENGTH_SHORT).show();
}
});
}
/**
* This method creates and assigns STOPOVER type action using given expectedPlaceId and lookup_id
*
* @param expectedPlaceID ExpectedPlace Id created on HyperTrack API Server for the VISIT type action.
* @param lookupID Internal order_id which maps to the current job being performed.
*/
private void assignStopoverActionForJob(String expectedPlaceID, String lookupID) {
/**
* Create ActionParams object specifying the Stopover Action parameters including
* already created ExpectedPlaceId, ExpectedAt time and same Lookup_id as for the Visit type action.
*/
ActionParams stopOverTypeActionParams = new ActionParamsBuilder()
.setExpectedPlaceId(expectedPlaceID)
.setExpectedAt(new Date())
.setType(Action.ACTION_TYPE_STOPOVER)
.setLookupId(lookupID)
.build();
/**
* Call createAndAssignAction to assign Stopover action to the current user configured
* in the SDK using the ActionParams created above.
*/
HyperTrack.createAndAssignAction(stopOverTypeActionParams, new HyperTrackCallback() {
@Override
public void onSuccess(@NonNull SuccessResponse response) {
if (mProgressDialog != null) {
mProgressDialog.dismiss();
}
// Handle createAndAssignAction API success here
Action action = (Action) response.getResponseObject();
SharedPreferenceStore.setStopoverActionId(MainActivity.this, action.getId());
Toast.makeText(MainActivity.this, "Job (id = " + action.getId() + ") accepted successfully.",
Toast.LENGTH_SHORT).show();
}
@Override
public void onError(@NonNull ErrorResponse errorResponse) {
if (mProgressDialog != null) {
mProgressDialog.dismiss();
}
Toast.makeText(MainActivity.this, "Action assigned failed: " + errorResponse.getErrorMessage(),
Toast.LENGTH_SHORT).show();
}
});
}