Skip to content

Commit

Permalink
[FIX] Added metaData parameter for userCompletedAction().
Browse files Browse the repository at this point in the history
  • Loading branch information
Renemari Padillo committed Jan 14, 2016
1 parent 9c6a883 commit 0df8866
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 191 deletions.
173 changes: 130 additions & 43 deletions src/android/BranchSDK.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.branch;

import android.app.Activity;
import android.net.LinkAddress;
import android.util.Log;

import io.branch.referral.Branch;
Expand All @@ -19,7 +18,8 @@
import java.util.HashMap;
import java.util.Map;

public class BranchSDK extends CordovaPlugin {
public class BranchSDK extends CordovaPlugin
{

// Standard Debugging Variables
private static final String LCAT = "CordovaBranchSDK";
Expand All @@ -30,37 +30,56 @@ public class BranchSDK extends CordovaPlugin {
private Branch instance;

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
public void initialize(CordovaInterface cordova, CordovaWebView webView)
{
super.initialize(cordova, webView);
// Initialization codes here
}

/**
* <p>
* cordova.exec() method reference.
* All exec() calls goes to this part.
* </p>
* <p>cordova.exec() method reference.</p>
* <p>All exec() calls goes to this part.</p>
*
* @param action [Action name/label to execute]
* @param args [Action parameters to pass]
* @param callbackContext [Callback function]
* @param action A {@link String} value method to be executed.
* @param args A {@link JSONArray} value parameters passed along with the action param.
* @param callbackContext A {@link CallbackContext} function passed for executing callbacks.
*/
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException
{

this.callbackContext = callbackContext;
this.activity = this.cordova.getActivity();
this.instance = Branch.getInstance(activity);

if (action.equals("initSession")) {
this.initSession();
return true;
} else if (action.equals("setDebug")) {
this.setDebug(args.getBoolean(0));
if (args.length() == 1) {
this.setDebug(args.getBoolean(0));
}
return true;
} else if (action.equals("setIdentity")) {
this.setIdentity(args.getString(0));
if (args.length() == 1) {
this.setIdentity(args.getString(0));
}
return true;
} else if (action.equals("userCompletedAction")) {
this.userCompletedAction(args.getString(0));
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;
}

Expand All @@ -69,22 +88,79 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
}

//////////////////////////////////////////////////
//=-------------- CLASS METHODS ----------------//
//--------------- CLASS METHODS ----------------//
//////////////////////////////////////////////////

/**
* <p>
* Initialize Branch Session.
* </p>
*/
private void initSession() {
private void initSession()
{

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

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

}

/**
* <p>
* Logout current session.
* </p>
*/
private void logout()
{

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

this.instance.logout();
this.callbackContext.success("Success");

}

/**
* <p>
* Get latest referring parameters.
* </p>
*/
private void getLatestReferringParams()
{

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

JSONObject sessionParams = this.instance.getLatestReferringParams();

if (sessionParams == null) {
Log.d(LCAT, "return is null");
} else {
Log.d(LCAT, sessionParams.toString());
}

this.callbackContext.success(sessionParams.toString());

}

/**
* <p>
* Get first referring parameters.
* </p>
*/
private void getFirstReferringParams()
{

instance.initSession(new SessionListener(), activity.getIntent().getData(), activity);
Log.d(LCAT, "start getFirstReferringParams()");

JSONObject installParams = this.instance.getFirstReferringParams();

if (installParams == null) {
Log.d(LCAT, "return is null");
} else {
Log.d(LCAT, installParams.toString());
}

this.callbackContext.success(installParams.toString());

}

Expand All @@ -93,41 +169,33 @@ private void initSession() {
* Enable debug mode for the app.
* </p>
*
* @param isEnable [Boolean flag value to enable/disable debugging mode]
*
* @param isEnable A {@link Boolean} value to enable/disable debugging mode for the app.
*/
private void setDebug(boolean isEnable) {

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

activity = this.cordova.getActivity();
instance = Branch.getInstance(activity);

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

callbackContext.success("Success");

}

/**
* <p>
* Set instance identity.
* </p>
*
* @param newIdentity [The identity name/identity for the current session]
* @param newIdentity A {@link String} value containing the unique identifier of the user.
*/
private void setIdentity(String newIdentity) {
private void setIdentity(String newIdentity)
{

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

activity = this.cordova.getActivity();
instance = Branch.getInstance(activity);

instance.setIdentity(newIdentity);

callbackContext.success("Success");
this.instance.setIdentity(newIdentity);
this.callbackContext.success("Success");

}

Expand All @@ -136,27 +204,46 @@ private void setIdentity(String newIdentity) {
* Set user completed action
* </p>
*
* @param action [Name of the completed user action]
* @param action A {@link String} value to be passed as an action that the user has carried out.
* For example "logged in" or "registered".
*/
private void userCompletedAction(String action) {
private void userCompletedAction(String action)
{

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

activity = this.cordova.getActivity();
instance = Branch.getInstance(activity);
this.instance.userCompletedAction(action);
this.callbackContext.success("Success");

}

/**
* <p>
* Set user completed action
* </p>
*
* @param action A {@link String} value to be passed as an action that the user has carried
* out. For example "logged in" or "registered".
* @param metaData A {@link JSONObject} containing app-defined meta-data to be attached to a
* user action that has just been completed.
*/
private void userCompletedAction(String action, JSONObject metaData)
{

instance.userCompletedAction(action);
Log.d(LCAT, "start userCompletedAction()");

callbackContext.success("Success");
this.instance.userCompletedAction(action, metaData);
this.callbackContext.success("Success");

}

/**
* <p>
* Creates a dictionary for session returns.
* </p>
*/
private Map createSessionDict(JSONObject data) {
private Map createSessionDict(JSONObject data)
{
Log.d(LCAT, "start createSessionDict()");

Map<String, String> sessionDict = new HashMap<String, String>();
Expand Down
Loading

0 comments on commit 0df8866

Please sign in to comment.