Skip to content

Commit

Permalink
[FEAT] Implemented loadRewards() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Renemari Padillo committed Jan 14, 2016
1 parent 9c2021f commit faf80df
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/android/BranchSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ private void setDebug(boolean isEnable) {
instance.setDebug();
}

callbackContext.success("Success");

}

/**
Expand All @@ -113,6 +115,8 @@ private void setIdentity(String newIdentity) {

instance.setIdentity(newIdentity);

callbackContext.success("Success");

}

/**
Expand All @@ -129,6 +133,22 @@ private void userCompletedAction(String action) {

instance.userCompletedAction(action);

callbackContext.success("Success");

}

/**
* Get user current points/rewards.
*/
private void loadRewards() {

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

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

instance.loadRewards(new LoadRewardsListener());

}

//////////////////////////////////////////////////
Expand Down Expand Up @@ -172,4 +192,30 @@ public void onInitFinished(JSONObject referringParams, BranchError error) {

}

protected class LoadRewardsListener implements Branch.BranchReferralInitListener
{

@Override
public void onStateChanged(boolean isChanged, BranchError error) {

Log.d(LCAT, "LoadRewardsListener onStateChanged()");

if (error == null) {
final Activity currentActivity = this.cordova.getActivity();
final Branch currentBranch = Branch.getInstance(currentActivity);
int credits = instance.getCredits();

callbackContext.success(credits);
} else {
String errorMessage = error.getMessage();

Log.d(LCAT, errorMessage);

callbackContext.error(errorMessage);
}

}

}

}

0 comments on commit faf80df

Please sign in to comment.