Skip to content

Commit

Permalink
Updated destroy method (#20)
Browse files Browse the repository at this point in the history
* Updated SDK to include BACKGROUND_REFRESH policy for actions

* Updated ReadMe for BACKGROUND_REFRESH

* Add Destroy method
  • Loading branch information
sam-almighty authored and srinivasannanduri committed Jan 18, 2018
1 parent 3ad218f commit c670316
Showing 1 changed file with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public class AppLaunch {
// private AppLaunchUser appLaunchUser;

private AppLaunchCacheManager appLaunchCacheManager=null;
private boolean isInitialized = false;
private AppLaunchResponseListener myListener;
SharedPreferences prefs = null;
private JSONArray features = null;
Expand Down Expand Up @@ -134,7 +133,7 @@ public void init(Application context,ICRegion region, String appGuid, String cli
appContext = context;
//if app launch listener ==null create a dummy action listener
if(appLaunchActionListener==null) {
appLaunchActionListener = new AppLaunchListener() {
appLaunchActionListener = new AppLaunchListener() {
@Override
public void onSuccess(AppLaunchResponse response) {

Expand Down Expand Up @@ -168,6 +167,36 @@ public void onFailure(AppLaunchFailResponse failResponse) {
}
}

/**
*
* @param appLaunchListener
*/
public void destroy(final AppLaunchListener appLaunchListener){
//TODO : Cache Clearing Mechanism and Check device is registered or not
if (appLaunchConfig != null && this.clientSecret != null) {
//send all the analytics event to the server
sendLogs();
//construct registration url
String registrationUrl = appLaunchUrlBuilder.getAppRegistrationURL();
//post the body to the server
AppLaunchInternalListener appLaunchInternalListener = new AppLaunchInternalListener() {
@Override
public void onSuccess(AppLaunchResponse appLaunchResponse) {
// Clear all the cache

}

@Override
public void onFailure(AppLaunchFailResponse appLaunchFailResponse) {
appLaunchListener.onFailure(appLaunchFailResponse);
}
};
sendDeleteRequest(registrationUrl, appLaunchInternalListener);
}else{
throw new RuntimeException("Invalid Init paramters");
}
}


private void registerDevice(AppLaunchUser user,AppLaunchListener appLaunchActionListener) {
if(user.getUserId()==null)
Expand Down Expand Up @@ -758,6 +787,38 @@ public void onFailure(Response response, Throwable t, JSONObject extendedInfo) {
});
}

private void sendDeleteRequest(String url, final AppLaunchInternalListener appLaunchListener) {

Request postReq = new Request(url, Request.DELETE);
// postReq.addHeader("clientSecret",appLaunchConfig.getClientSecret());

Map<String, List<String>> headers = new HashMap<>();
List<String> secretValues = new ArrayList<>();
secretValues.add(appLaunchConfig.getClientSecret());
headers.put("clientSecret", secretValues);
postReq.setHeaders(headers);

postReq.send(appContext, new ResponseListener() {
@Override
public void onSuccess(Response response) {
Log.d("POST INVOKE FUNCTION::", response.getResponseText());
if(response.getStatus() == 202) {
AppLaunchResponse appLaunchResponse = new AppLaunchResponse();
appLaunchListener.onSuccess(appLaunchResponse);
} else {
AppLaunchFailResponse appLaunchFailResponse = new AppLaunchFailResponse(ErrorCode.UNREGISTRATION_FAILURE,response.getResponseText());
appLaunchListener.onFailure(appLaunchFailResponse);
}
}

@Override
public void onFailure(Response response, Throwable t, JSONObject extendedInfo) {
AppLaunchFailResponse appLaunchFailResponse = new AppLaunchFailResponse(ErrorCode.UNREGISTRATION_FAILURE,response.getResponseText());
appLaunchListener.onFailure(appLaunchFailResponse);
}
});
}



/**
Expand Down

0 comments on commit c670316

Please sign in to comment.