Skip to content

Commit

Permalink
[FIX] Updated SDK to follow the plugin convention wherein "Debug mode…
Browse files Browse the repository at this point in the history
…" must be set first before you can initialize the session.
  • Loading branch information
renesansz committed Jan 22, 2016
1 parent ce14304 commit 3c878ab
Showing 1 changed file with 74 additions and 62 deletions.
136 changes: 74 additions & 62 deletions src/android/io/branch/BranchSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static class BranchLinkProperties extends io.branch.referral.util.LinkProperties
private BranchUniversalObject branchObj;
private CallbackContext callbackContext;
private Activity activity;
private Branch instance;
private Branch instance = null;

/**
* Called when the activity will start interacting with the user.
Expand All @@ -48,12 +48,11 @@ static class BranchLinkProperties extends io.branch.referral.util.LinkProperties
public void onResume(boolean multitasking)
{

Log.d(LCAT, "(Re)Initialize SDK session");
Log.d(LCAT, "SDK On Resume");

this.activity = this.cordova.getActivity();
this.instance = Branch.getAutoInstance(this.activity.getApplicationContext());

initSession();
if (this.instance != null) {
initSession();
}

}

Expand All @@ -64,9 +63,12 @@ public void onResume(boolean multitasking)
public void onStop()
{

Log.d(LCAT, "Stopping SDK session");
Log.d(LCAT, "SDK On Stop");

this.instance.closeSession();
if (this.instance != null) {
Log.d(LCAT, "instance.closeSession()");
this.instance.closeSession();
}

}

Expand All @@ -86,64 +88,68 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo

this.callbackContext = callbackContext;

if (action.equals("initSession")) {
this.initSession();
return true;
} else if (action.equals("setDebug")) {
if (action.equals("setDebug")) {
if (args.length() == 1) {
this.setDebug(args.getBoolean(0));
}
return true;
} else if (action.equals("setIdentity")) {
if (args.length() == 1) {
this.setIdentity(args.getString(0));
}
return true;
} else if (action.equals("userCompletedAction")) {
if (args.length() == 2) {
this.userCompletedAction (args.getString(0), args.getJSONObject(1));
} else if (args.length() == 1) {
this.userCompletedAction(args.getString(0));
}
return true;
} else if (action.equals("getFirstReferringParams")) {
this.getFirstReferringParams();
return true;
} else if (action.equals("getLatestReferringParams")) {
this.getLatestReferringParams();
return true;
} else if (action.equals("logout")) {
this.logout();
return true;
} else if (action.equals("loadRewards")) {
this.loadRewards();
return true;
} else if (action.equals("redeemRewards")) {
if (args.length() == 1) {
this.redeemRewards(args.getInt(0));
}
return true;
} else if (action.equals("creditHistory")) {
this.creditHistory();
return true;
} else if (action.equals("createBranchUniversalObject")) {
if (args.length() == 1) {
this.createBranchUniversalObject(args.getJSONObject(0));
}
return true;
} else if (action.equals(("generateShortUrl"))) {
if (args.length() == 2) {
this.generateShortUrl(args.getJSONObject(0), args.getJSONObject(1));
}
return true;
} else if (action.equals("registerView")) {
this.registerView();
} else if (action.equals("initSession")) {
this.initSession();
return true;
} else if (action.equals("showShareSheet")) {
if (args.length() == 2) {
this.showShareSheet(args.getJSONObject(0), args.getJSONObject(1));
} else {
if (this.instance != null) {
if (action.equals("setIdentity")) {
if (args.length() == 1) {
this.setIdentity(args.getString(0));
}
return true;
} else if (action.equals("userCompletedAction")) {
if (args.length() == 2) {
this.userCompletedAction (args.getString(0), args.getJSONObject(1));
} else if (args.length() == 1) {
this.userCompletedAction(args.getString(0));
}
return true;
} else if (action.equals("getFirstReferringParams")) {
this.getFirstReferringParams();
return true;
} else if (action.equals("getLatestReferringParams")) {
this.getLatestReferringParams();
return true;
} else if (action.equals("logout")) {
this.logout();
return true;
} else if (action.equals("loadRewards")) {
this.loadRewards();
return true;
} else if (action.equals("redeemRewards")) {
if (args.length() == 1) {
this.redeemRewards(args.getInt(0));
}
return true;
} else if (action.equals("creditHistory")) {
this.creditHistory();
return true;
} else if (action.equals("createBranchUniversalObject")) {
if (args.length() == 1) {
this.createBranchUniversalObject(args.getJSONObject(0));
}
return true;
} else if (action.equals(("generateShortUrl"))) {
if (args.length() == 2) {
this.generateShortUrl(args.getJSONObject(0), args.getJSONObject(1));
}
return true;
} else if (action.equals("registerView")) {
this.registerView();
return true;
} else if (action.equals("showShareSheet")) {
if (args.length() == 2) {
this.showShareSheet(args.getJSONObject(0), args.getJSONObject(1));
}
return true;
}
}
return true;
}

return false;
Expand All @@ -163,6 +169,8 @@ private void initSession()

Log.d(LCAT, "start initSession()");

this.activity = this.cordova.getActivity();
this.instance = Branch.getAutoInstance(this.activity.getApplicationContext());
this.instance.initSession(new SessionListener(), activity.getIntent().getData(), activity);

}
Expand Down Expand Up @@ -527,11 +535,15 @@ private void setDebug(boolean isEnable)

Log.d(LCAT, "start setDebug()");

Activity act = this.cordova.getActivity();
Branch inst = Branch.getAutoInstance(act.getApplicationContext());

if (isEnable) {
this.instance.setDebug();
this.callbackContext.success("Success");
inst.setDebug();
}

this.callbackContext.success("Success");

}

/**
Expand Down

0 comments on commit 3c878ab

Please sign in to comment.