Skip to content

Commit

Permalink
Merge pull request #382 from BranchMetrics/more_fixes
Browse files Browse the repository at this point in the history
More fixes
  • Loading branch information
ethanneff authored Oct 17, 2017
2 parents 4982186 + f3748a2 commit 7017650
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 102 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "branch-cordova-sdk",
"description": "Branch Metrics Cordova SDK",
"main": "src/branch.js",
"version": "2.6.14",
"version": "2.6.15",
"homepage": "https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion plugin.template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SOFTWARE.
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="branch-cordova-sdk"
version="2.6.14">
version="2.6.15">

<!-- DO NOT EDIT THIS FILE. MAKE ALL CHANGES TO plugin.template.xml INSTEAD -->

Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SOFTWARE.
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="branch-cordova-sdk"
version="2.6.14">
version="2.6.15">

<!-- DO NOT EDIT THIS FILE. MAKE ALL CHANGES TO plugin.template.xml INSTEAD -->

Expand Down
24 changes: 21 additions & 3 deletions src/android/io/branch/BranchSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.annotation.TargetApi;
import android.net.Uri;
import android.os.Build;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
Expand All @@ -15,8 +18,6 @@
import java.util.ArrayList;
import java.util.Iterator;

import android.net.Uri;

import io.branch.indexing.BranchUniversalObject;
import io.branch.referral.Branch;
import io.branch.referral.BranchError;
Expand Down Expand Up @@ -74,6 +75,23 @@ public void onNewIntent(Intent intent) {

}

/**
* Handle depreciated call to sendJavaScript for more recent method
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
private void sendJavascript(final String javascript) {
webView.getView().post(new Runnable() {
@Override
public void run() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webView.sendJavascript(javascript);
} else {
webView.loadUrl("javascript:" + javascript);
}
}
});
}

/**
* <p>
* cordova.exec() method reference.
Expand Down Expand Up @@ -808,7 +826,7 @@ public void onInitFinished(JSONObject referringParams, BranchError error) {
if (error == null && referringParams != null) {

out = String.format("DeepLinkHandler(%s)", referringParams.toString());
webView.sendJavascript(out);
sendJavascript(out);

if (this._callbackContext != null) {
this._callbackContext.success(referringParams);
Expand Down
6 changes: 3 additions & 3 deletions src/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ Branch.prototype.disableGlobalListenersWarnings = function () {
disableGlobalListenersWarnings = true
}

var previousLinkTimestamp = null
var runOnce = true
var previousLinkTimestamp = null
Branch.prototype.initSession = function (deepLinkDataListener) {
// handle double init from onResume on iOS
if (!runOnce) return new Promise(function (resolve, reject) {})
runOnce = (deviceVendor.indexOf('Apple') < 0)

// private method to filter out +clicked_branch_link = false in deep link callback
var deepLinkDataParser = function (deepLinkData) {
var timestamp = '+click_timestamp'
var isBranchLink = '+clicked_branch_link'
var isNonBranchLink = '+non_branch_link'
var timestamp = '+click_timestamp'

var isBranchLinkClick = deepLinkData.hasOwnProperty(isBranchLink) && deepLinkData[isBranchLink] === true
var isNonBranchLinkClick = deepLinkData.hasOwnProperty(isNonBranchLink)
var currentLinkTimestamp = deepLinkData.hasOwnProperty(timestamp) ? deepLinkData[timestamp] : null
var currentLinkTimestamp = deepLinkData.hasOwnProperty(timestamp) ? deepLinkData[timestamp] : Date.now()

// is +clicked_branch_link' = true || +non_branch_link && !previousLinkTimestamp
if ((isBranchLinkClick || isNonBranchLinkClick) && currentLinkTimestamp !== previousLinkTimestamp) {
Expand Down
42 changes: 25 additions & 17 deletions testbed/www/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,32 @@
background-color: #FFFFFF;
}
body {
padding: 0.8em 0em 0.2em 0em;
display: flex;
flex-direction: column;
padding: 1em 0em 0.5em 0em;
max-width: 40em;
margin: 0 auto;
}
fieldset {
border-color: #303030;
margin: 0.5em 1em;
padding: 0.75em;
}
fieldset > *:not(:first-child) {
margin-bottom: 0.5em;
}
fieldset > *:last-child {
margin-bottom: 0;
}
section {
display: flex;
flex-direction: row;
}
section > button:nth-child(even) {
margin-left: 0.5em;
}
section > button:nth-child(odd) {
margin-right: 0.5em;
}
button, input {
padding: 0.5em;
Expand All @@ -14,20 +38,4 @@ button, input {
}
button {
background-color: #F5F5F5;
}
div, fieldset {
border-color: #303030;
margin: 0.5em 0;
display: -webkit-box;
display: -webkit-flex;
display: flex;
justify-content: space-around;
-webkit-flex-direction: row;
flex-direction: row;
}
fieldset > div > *, div > * {
margin: 0 0.5em;
width: 0em;
-webkit-flex-grow: 1;
flex-grow: 1;
}
128 changes: 52 additions & 76 deletions testbed/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,84 +9,60 @@
<title>Branch Testing</title>
</head>
<body>
<div>
<fieldset>
<legend>Branch Universal Object</legend>
<div>
<button onclick="BranchUniversalObject()">Create</button>
</div>
</fieldset>
</div>
<div>
<fieldset>
<legend>Branch Deep Link</legend>
<div>
<input id="alias" name="alias" type="text" placeholder="Enter an alias">
</div>
<div>
<fieldset>
<legend>Branch Universal Object</legend>
<button onclick="BranchUniversalObject()">Create</button>
</fieldset>
<fieldset>
<legend>Branch Deep Link</legend>
<input id="alias" name="alias" type="text" placeholder="Deep link alias (optional)">
<section>
<button onclick="BranchDeepLink()">Create</button>
<button onclick="BranchShareSheet()">Share</button>
</div>
<div>
<input type="text" id="generated-url" placeholder="Deep Link" readonly>
</div>
</fieldset>
</div>
<div>
<fieldset>
<legend>Branch Deep Link Data</legend>
<div>
<button onclick="BranchFirstData()">First</button>
<button onclick="BranchLatestData()">Latest</button>
</div>
</fieldset>
</div>
<div>
<fieldset>
<legend>Branch Content</legend>
<div>
<button onclick="BranchView()">Create</button>
<button onclick="BranchSpotlight()">Share</button>
</div>
</fieldset>
</div>
<div>
<fieldset>
<legend>Branch User</legend>
<div>
<input type="text" id="identity" name="identity" placeholder="User Id">
</div>
<div>
<button onclick="BranchUser()">Login</button>
<button onclick="BranchLogout()">Logout</button>
</div>
</fieldset>
</div>
<div>
<fieldset>
<legend>Branch Event</legend>
<div>
<input type="text" id="custom-action" name="custom-action" placeholder="Event Name">
</div>
<div>
<button onclick="BranchEvent()">Create</button>
<button onclick="BranchCommerce()">Commerce</button>
</div>
</fieldset>
</div>
<div>
<fieldset>
<legend>Branch Referral</legend>
<div>
<button onclick="BranchReferralsReward()">Reward</button>
<button onclick="BranchReferralsLoad()">Load</button>
</div>
<div>
<button onclick="BranchReferralsRedeem()">Redeem</button>
<button onclick="BranchReferralsHistory()">History</button>
</div>
</fieldset>
</div>
</section>
<input type="text" id="generated-url" placeholder="Deep link" readonly>
</fieldset>
<fieldset>
<legend>Branch Deep Link Data</legend>
<section>
<button onclick="BranchFirstData()">First</button>
<button onclick="BranchLatestData()">Latest</button>
</section>
</fieldset>
<fieldset>
<legend>Branch Content</legend>
<section>
<button onclick="BranchView()">Create</button>
<button onclick="BranchSpotlight()">Share</button>
</section>
</fieldset>
<fieldset>
<legend>Branch User</legend>
<input type="text" id="identity" name="identity" placeholder="User Id">
<section>
<button onclick="BranchUser()">Login</button>
<button onclick="BranchLogout()">Logout</button>
</section>
</fieldset>
<fieldset>
<legend>Branch Event</legend>
<input type="text" id="custom-action" name="custom-action" placeholder="Event Name">
<section>
<button onclick="BranchEvent()">Create</button>
<button onclick="BranchCommerce()">Commerce</button>
</section>
</fieldset>
<fieldset>
<legend>Branch Referral</legend>
<section>
<button onclick="BranchReferralsReward()">Reward</button>
<button onclick="BranchReferralsLoad()">Load</button>
</section>
<section>
<button onclick="BranchReferralsRedeem()">Redeem</button>
<button onclick="BranchReferralsHistory()">History</button>
</section>
</fieldset>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
Expand Down

0 comments on commit 7017650

Please sign in to comment.