Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project restructure #46

Merged
merged 6 commits into from
Mar 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 53 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,54 @@ branchUniversalObj.showShareSheet({
});
```

##### Share Sheet Callbacks (Android ONLY)

To implement the callback, you must add listeners to the following events:

###### onShareSheetLaunched

The event fires when the share sheet is presented.

```js
branchUniversalObj.onShareSheetLaunched(function () {
console.log('Share sheet launched');
});
```

###### onShareSheetDismissed

The event fires when the share sheet is dismissed.

```js
branchUniversalObj.onShareSheetDismissed(function () {
console.log('Share sheet dimissed');
});
```

###### onLinkShareResponse

The event returns a dictionary of the response data.

```js
branchUniversalObj.onLinkShareResponse(function (res) {
console.log('Share link response: ' + JSON.stringify(res));
});
```

###### onChannelSelected

The event fires when a channel is selected.

```js
branchUniversalObj.onChannelSelected(function (res) {
console.log('Channel selected: ' + JSON.stringify(res));
});
```

**Note:** Callbacks in iOS are ignored. There is no need to implement them as the events are handled by `UIActivityViewController`.

**Note:** Avoid passing `alias` in iOS. Adding an `alias` key in the `options` parameter will return a Non-Universal link which will not work in iOS 9.2.

### <a id="listOnSpotlight"></a>listOnSpotlight()

**Note: iOS only.** Used for Spotlight listing
Expand Down Expand Up @@ -422,11 +470,14 @@ Redeems a reward with the given amount/value.

**Parameters**

**value**: `int` - Amount to be redeemed.
| KEY | TYPE | MEANING
| -------- | -------- |------------------------
| value | `int` | Amount to be redeemed.
| bucket | `int` | Bucket where the amount will be redeemed. _optional_
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aaustin @jestoniyap should this type be string?


##### Usage
```js
Branch.redeemRewards(100).then(function (res) {
Branch.redeemRewards(100, "default").then(function (res) {
// Success Callback
console.log(res);
}).catch(function (err) {
Expand Down
79 changes: 77 additions & 2 deletions src/android/io/branch/BranchSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ static class BranchLinkProperties extends io.branch.referral.util.LinkProperties
// Private Method Properties
private BranchUniversalObject branchObj;
private CallbackContext callbackContext;
private CallbackContext onShareLinkDialogLaunched;
private CallbackContext onShareLinkDialogDismissed;
private CallbackContext onLinkShareResponse;
private CallbackContext onChannelSelected;
private Activity activity;
private Branch instance;

Expand All @@ -43,6 +47,10 @@ public BranchSDK()
this.instance = null;
this.branchObj = null;
this.callbackContext = null;
this.onShareLinkDialogLaunched = null;
this.onShareLinkDialogDismissed = null;
this.onLinkShareResponse = null;
this.onChannelSelected = null;
}

/**
Expand Down Expand Up @@ -134,7 +142,11 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
this.loadRewards();
return true;
} else if (action.equals("redeemRewards")) {
this.redeemRewards(args.getInt(0));
if (args.length() == 1) {
this.redeemRewards(args.getInt(0));
} else if (args.length() == 2) {
this.redeemRewards(args.getInt(0), args.getString(1));
}
return true;
} else if (action.equals("getCreditHistory")) {
this.getCreditHistory();
Expand All @@ -151,6 +163,18 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
} else if (action.equals("showShareSheet")) {
this.showShareSheet(args.getJSONObject(0), args.getJSONObject(1));
return true;
} else if (action.equals("onShareLinkDialogLaunched")) {
this.onShareLinkDialogLaunched = callbackContext;
return true;
} else if (action.equals("onShareLinkDialogDismissed")) {
this.onShareLinkDialogDismissed = callbackContext;
return true;
} else if (action.equals("onLinkShareResponse")) {
this.onLinkShareResponse = callbackContext;
return true;
} else if (action.equals("onChannelSelected")) {
this.onChannelSelected = callbackContext;
return true;
}
}
}
Expand Down Expand Up @@ -200,7 +224,7 @@ private void logout()
* @param count A {@link Integer} specifying the number of credits to attempt to redeem from
* the bucket.
*/
private void redeemRewards(int value)
private void redeemRewards(final int value)
{

Log.d(LCAT, "start redeemRewards()");
Expand All @@ -209,6 +233,23 @@ private void redeemRewards(int value)

}

/**
* <p>Redeems the specified number of credits from the "default" bucket, if there are sufficient
* credits within it. If the number to redeem exceeds the number available in the bucket, all of
* the available credits will be redeemed instead.</p>
*
* @param count A {@link Integer} specifying the number of credits to attempt to redeem from
* the bucket.
*/
private void redeemRewards(int value, String bucket)
{

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

this.instance.redeemRewards(bucket, value, new LoadRewardsListener());

}

/**
* <p>Retrieves rewards for the current session, with a callback to perform a predefined
* action following successful report of state change. You'll then need to call getCredits
Expand Down Expand Up @@ -730,11 +771,29 @@ protected class ShowShareSheetListener implements Branch.BranchLinkShareListener
@Override
public void onShareLinkDialogLaunched() {
Log.d(LCAT, "inside onShareLinkDialogLaunched");

if (onShareLinkDialogLaunched != null) {
PluginResult result = new PluginResult(PluginResult.Status.OK);

result.setKeepCallback(true);

onShareLinkDialogLaunched.sendPluginResult(result);
}

}

@Override
public void onShareLinkDialogDismissed() {
Log.d(LCAT, "inside onShareLinkDialogDismissed");

if (onShareLinkDialogDismissed != null) {
PluginResult result = new PluginResult(PluginResult.Status.OK);

result.setKeepCallback(true);

onShareLinkDialogDismissed.sendPluginResult(result);
}

}

@Override
Expand Down Expand Up @@ -771,6 +830,14 @@ public void onLinkShareResponse(String sharedLink, String sharedChannel, BranchE

Log.d(LCAT, response.toString());

if (onLinkShareResponse != null) {
PluginResult result = new PluginResult(PluginResult.Status.OK, response);

result.setKeepCallback(true);

onLinkShareResponse.sendPluginResult(result);
}

}

@Override
Expand All @@ -790,6 +857,14 @@ public void onChannelSelected(String channelName) {

Log.d(LCAT, response.toString());

if (onChannelSelected != null) {
PluginResult result = new PluginResult(PluginResult.Status.OK, response);

result.setKeepCallback(true);

onChannelSelected.sendPluginResult(result);
}

}
}

Expand Down
82 changes: 58 additions & 24 deletions src/ios/BranchSDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -280,34 +280,68 @@ - (void)loadRewards:(CDVInvokedUrlCommand*)command
- (void)redeemRewards:(CDVInvokedUrlCommand*)command
{
NSLog(@"start redeemRewards");

NSInteger amount = ((NSNumber *)[command.arguments objectAtIndex:0]).integerValue;
Branch *branch = [self getInstance];

[branch redeemRewards:amount callback:^(BOOL changed, NSError *error) {
NSLog(@"inside redeemRewards block");
CDVPluginResult* pluginResult = nil;
if (!error) {
NSNumber *changedValue = [NSNumber numberWithBool:changed];
NSError *err;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:@{@"changed":changedValue}
options:0
error:&err];
if (!jsonData) {
NSLog(@"Parsing Error: %@", [err localizedDescription]);
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[err localizedDescription]];
} else {
NSLog(@"Success");
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:jsonString];
if ([command.arguments count] == 2) {

NSString *bucket = [command.arguments objectAtIndex:1];

[branch redeemRewards:(NSInteger)amount forBucket:(NSString *)bucket callback:^(BOOL changed, NSError *error) {
NSLog(@"inside redeemRewards:forBucket block");
CDVPluginResult* pluginResult = nil;
if (!error) {
NSNumber *changedValue = [NSNumber numberWithBool:changed];
NSError *err;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:@{@"changed":changedValue}
options:0
error:&err];
if (!jsonData) {
NSLog(@"Parsing Error: %@", [err localizedDescription]);
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[err localizedDescription]];
} else {
NSLog(@"Success");
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:jsonString];
}
}
}
else {
NSLog(@"Redeem Rewards Error: %@", [error localizedDescription]);
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]];
}
NSLog(@"returning data to js interface..");
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
else {
NSLog(@"Redeem Rewards Error: %@", [error localizedDescription]);
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]];
}
NSLog(@"returning data to js interface..");
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
} else {
[branch redeemRewards:amount callback:^(BOOL changed, NSError *error) {
NSLog(@"inside redeemRewards block");
CDVPluginResult* pluginResult = nil;
if (!error) {
NSNumber *changedValue = [NSNumber numberWithBool:changed];
NSError *err;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:@{@"changed":changedValue}
options:0
error:&err];
if (!jsonData) {
NSLog(@"Parsing Error: %@", [err localizedDescription]);
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[err localizedDescription]];
} else {
NSLog(@"Success");
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:jsonString];
}
}
else {
NSLog(@"Redeem Rewards Error: %@", [error localizedDescription]);
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]];
}
NSLog(@"returning data to js interface..");
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}


}

- (void)getCreditHistory:(CDVInvokedUrlCommand*)command
Expand Down
Empty file.
Empty file modified testbed/init.sh
100755 → 100644
Empty file.
15 changes: 15 additions & 0 deletions testbed/www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,21 @@ function ShowShareSheet()
};

branchUniversalObj.showShareSheet(properties, controlParams);

// Set listeners
branchUniversalObj.onShareSheetLaunched(function () {
console.log('Share sheet launched');
});
branchUniversalObj.onShareSheetDismissed(function () {
console.log('Share sheet dimissed');
});
branchUniversalObj.onLinkShareResponse(function (res) {
console.log('Share link response: ' + JSON.stringify(res));
});
branchUniversalObj.onChannelSelected(function (res) {
console.log('Channel selected: ' + JSON.stringify(res));
});

}

function ListOnSpotlight()
Expand Down
Loading