Skip to content

Commit

Permalink
[FEAT] Added set listener callback for share sheet method. (Android/p…
Browse files Browse the repository at this point in the history
…lugin)
  • Loading branch information
Renemari Padillo authored and Renemari Padillo committed Mar 1, 2016
1 parent 2aa8e28 commit bff6c97
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 4 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,50 @@ branchUniversalObj.showShareSheet({
});
```

##### Share Sheet Callbacks

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));
});
```

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

**Note: iOS only.** Used for Spotlight listing
Expand Down
54 changes: 54 additions & 0 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 @@ -155,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 @@ -751,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 @@ -792,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 @@ -811,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
Empty file.
Empty file modified testbed/init.sh
100755 → 100644
Empty file.
66 changes: 62 additions & 4 deletions www/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ var _API_CLASS = 'BranchSDK'; // SDK Class
/**
* Execute SDK method using cordova.exec()
*
* @param (String) method - The class method to execute
* @param (Array) params - Method parameter(s) to pass
* @param (String) method - The class method to execute.
* @param (Array) params - Method parameter(s) to pass.
*
* @return (Promise)
*/
function execute(method, params) {

params = ( ! params) ? [] : params;

var self = this;

return new Promise(function (resolve, reject) {
exec(function (res) {
resolve(res);
Expand All @@ -32,6 +30,22 @@ function execute(method, params) {

}

/**
* Set listener callback for SDK method.
*
* @param (String) method - The class method to execute.
* @param (Function) callback - The method listener callback.
*
* @return (Promise)
*/
function executeCallback(method, callback) {

exec(callback, function (err) {
console.error(err);
}, _API_CLASS, method, []);

}

/**
* @class Branch
*/
Expand Down Expand Up @@ -264,6 +278,50 @@ Branch.prototype.createBranchUniversalObject = function (options) {

};

/**
* Set on share sheet launched listener callback.
*
* @param (Function) callback
*/
res.onShareSheetLaunched = function (callback) {

executeCallback('onShareLinkDialogLaunched', callback);

};

/**
* Set on share sheet dismissed listener callback.
*
* @param (Function) callback
*/
res.onShareSheetDismissed = function (callback) {

executeCallback('onShareLinkDialogDismissed', callback);

};

/**
* Set on link share listener callback.
*
* @param (Function) callback
*/
res.onLinkShareResponse = function (callback) {

executeCallback('onLinkShareResponse', callback);

};

/**
* Set on channel select listener callback.
*
* @param (Function) callback
*/
res.onChannelSelected = function (callback) {

executeCallback('onChannelSelected', callback);

};

/**
* List item on Spotlight (iOS Only).
*/
Expand Down

0 comments on commit bff6c97

Please sign in to comment.