Skip to content

Commit e3bee2c

Browse files
Merge pull request #706 from BranchMetrics/Staging
Merge Staging to master for v3.1.2 release
2 parents e190b48 + a989181 commit e3bee2c

22 files changed

+670
-496
lines changed

Branch-SDK-TestBed/AndroidManifest.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
android:versionCode="1"
55
android:versionName="1.0" >
66

7-
<uses-sdk
8-
android:minSdkVersion="16"
9-
android:targetSdkVersion="28" />
10-
117
<uses-permission android:name="android.permission.INTERNET" />
128

139
<application

Branch-SDK-TestBed/res/values/strings.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,12 @@
33

44
<string name="app_name">Branch-SDK-TestBed</string>
55

6+
<string name="rewards_empty">rewards =</string>
7+
<string name="rewards">rewards = %1$d</string>
8+
9+
<string name="install_count_empty">install count =</string>
10+
11+
<string name="launch_mode_branch">"Launched by Branch on auto deep linking!"</string>
12+
<string name="launch_mode_normal">"Launched by normal application flow"</string>
13+
614
</resources>

Branch-SDK-TestBed/src/io/branch/branchandroiddemo/AutoDeepLinkTestActivity.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import android.util.Log;
55
import android.widget.TextView;
66

7-
import java.util.Iterator;
8-
97
import io.branch.referral.Branch;
108

119
/**
@@ -21,19 +19,17 @@ protected void onResume() {
2119
super.onResume();
2220
setContentView(R.layout.auto_deep_link_test);
2321

24-
TextView launch_mode_txt = (TextView) findViewById(R.id.launch_mode_txt);
22+
TextView launch_mode_txt = findViewById(R.id.launch_mode_txt);
2523
if (Branch.isAutoDeepLinkLaunch(this)) {
26-
launch_mode_txt.setText("Launched by Branch on auto deep linking!");
24+
launch_mode_txt.setText(R.string.launch_mode_branch);
2725
Branch.getInstance().getLatestReferringParams();
2826
} else {
29-
launch_mode_txt.setText("Launched by normal application flow");
27+
launch_mode_txt.setText(R.string.launch_mode_normal);
3028
}
3129

3230
//You can also get linked params for the intent extra.
3331
if (getIntent().getExtras() != null && getIntent().getExtras().keySet() != null) {
34-
Iterator<?> keys = getIntent().getExtras().keySet().iterator();
35-
while (keys.hasNext()) {
36-
String key = (String) keys.next();
32+
for (String key : getIntent().getExtras().keySet()) {
3733
Log.i("BranchTestBed:", "Deep Linked Param " +
3834
key + " = " + getIntent().getExtras().getString(key));
3935
}

Branch-SDK-TestBed/src/io/branch/branchandroiddemo/CreditHistoryActivity.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.branch.branchandroiddemo;
22

3-
import android.annotation.SuppressLint;
43
import android.app.Activity;
54
import android.content.Context;
65
import android.os.Bundle;
@@ -20,37 +19,37 @@
2019
import java.text.SimpleDateFormat;
2120
import java.util.ArrayList;
2221
import java.util.Date;
22+
import java.util.Locale;
2323

2424
import io.branch.referral.Branch;
2525
import io.branch.referral.Branch.BranchListResponseListener;
2626
import io.branch.referral.BranchError;
2727

2828
public class CreditHistoryActivity extends Activity {
2929

30-
private static SimpleDateFormat DateParseFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSS'Z'");
31-
private static SimpleDateFormat DatePrintFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
32-
private Branch branch;
30+
private static SimpleDateFormat DateParseFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSS'Z'", Locale.US);
31+
private static SimpleDateFormat DatePrintFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.US);
3332
private ListView listview;
3433

3534
@Override
3635
protected void onCreate(Bundle savedInstanceState) {
3736
super.onCreate(savedInstanceState);
3837
setContentView(R.layout.activity_credit_history);
3938

40-
listview = (ListView) findViewById(R.id.list);
39+
listview = findViewById(R.id.list);
4140
}
4241

4342
@Override
4443
protected void onStart() {
4544
super.onStart();
4645

4746
final CreditHistoryActivity self = this;
48-
branch = Branch.getInstance();
47+
Branch branch = Branch.getInstance();
4948

5049
branch.getCreditHistory(new BranchListResponseListener() {
5150

5251
public void onReceivingResponse(JSONArray history, BranchError error) {
53-
ArrayList<CreditTransaction> list = new ArrayList<CreditTransaction>();
52+
ArrayList<CreditTransaction> list = new ArrayList<>();
5453
if (error != null) {
5554
Log.i("BranchTestBed", "branch load credit history failed. Caused by -" + error.getMessage());
5655
} else {
@@ -96,7 +95,7 @@ private class CreditHistoryArrayAdaptor extends BaseAdapter {
9695

9796
private LayoutInflater layoutInflater;
9897

99-
public CreditHistoryArrayAdaptor(Context context, ArrayList<CreditTransaction> listData) {
98+
CreditHistoryArrayAdaptor(Context context, ArrayList<CreditTransaction> listData) {
10099
this.listData = listData;
101100
layoutInflater = LayoutInflater.from(context);
102101
}
@@ -121,17 +120,17 @@ public View getView(int position, View convertView, ViewGroup parent) {
121120
if (convertView == null) {
122121
convertView = layoutInflater.inflate(R.layout.activity_credit_transaction, parent, false);
123122
holder = new ViewHolder();
124-
holder.transactionView = (TextView) convertView.findViewById(R.id.transaction);
125-
holder.referrerView = (TextView) convertView.findViewById(R.id.referrer);
126-
holder.dateView = (TextView) convertView.findViewById(R.id.date);
123+
holder.transactionView = convertView.findViewById(R.id.transaction);
124+
holder.referrerView = convertView.findViewById(R.id.referrer);
125+
holder.dateView = convertView.findViewById(R.id.date);
127126
convertView.setTag(holder);
128127
} else {
129128
holder = (ViewHolder) convertView.getTag();
130129
}
131130

132-
holder.transactionView.setText(((CreditTransaction)listData.get(position)).getTransaction());
133-
holder.referrerView.setText(((CreditTransaction)listData.get(position)).getReferInfo());
134-
holder.dateView.setText(((CreditTransaction)listData.get(position)).getDate());
131+
holder.transactionView.setText((listData.get(position)).getTransaction());
132+
holder.referrerView.setText((listData.get(position)).getReferInfo());
133+
holder.dateView.setText((listData.get(position)).getDate());
135134

136135
return convertView;
137136
}
@@ -150,42 +149,44 @@ private class CreditTransaction {
150149
private String referree;
151150
private Date date;
152151

153-
public CreditTransaction(String bucket) {
152+
CreditTransaction(String bucket) {
154153
this(bucket, null, null, null);
155154
}
156155

157-
public CreditTransaction(String transaction, String referrer, String referree, Date date) {
156+
CreditTransaction(String transaction, String referrer, String referree, Date date) {
158157
this.transaction = transaction;
159158
this.referrer = referrer;
160159
this.referree = referree;
161160
this.date = date;
162161
}
163162

164-
public String getTransaction() {
163+
String getTransaction() {
165164
return this.transaction;
166165
}
167166

168-
public String getReferInfo() {
167+
String getReferInfo() {
169168
StringBuilder sb = new StringBuilder();
170169
if (this.referrer != null || this.referree != null) {
171170
boolean hasReferrer = false;
172171
sb.append("(");
173172
if (this.referrer != null) {
174173
hasReferrer = true;
175-
sb.append("referrer: " + this.referrer);
174+
sb.append("referrer: ");
175+
sb.append(this.referrer);
176176
}
177177
if (this.referree != null) {
178178
if (hasReferrer) {
179179
sb.append(" -> ");
180180
}
181-
sb.append("referree: " + this.referree);
181+
sb.append("referree: ");
182+
sb.append(this.referree);
182183
}
183184
sb.append(")");
184185
}
185186
return sb.toString();
186187
}
187188

188-
public String getDate() {
189+
String getDate() {
189190
return this.date != null ? DatePrintFormat.format(this.date) : "";
190191
}
191192
}

Branch-SDK-TestBed/src/io/branch/branchandroiddemo/MainActivity.java

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import io.branch.referral.BranchError;
2525
import io.branch.referral.BranchViewHandler;
2626
import io.branch.referral.Defines;
27-
import io.branch.referral.validators.DeepLinkRoutingValidator;
2827
import io.branch.referral.SharingHelper;
2928
import io.branch.referral.util.BRANCH_STANDARD_EVENT;
3029
import io.branch.referral.util.BranchContentSchema;
@@ -34,26 +33,23 @@
3433
import io.branch.referral.util.LinkProperties;
3534
import io.branch.referral.util.ProductCategory;
3635
import io.branch.referral.util.ShareSheetStyle;
37-
import io.branch.referral.validators.IntegrationValidator;
3836

3937

4038
public class MainActivity extends Activity {
41-
Branch branch;
39+
private EditText txtShortUrl;
40+
private TextView txtInstallCount;
41+
private TextView txtRewardBalance;
4242

43-
EditText txtShortUrl;
44-
TextView txtInstallCount;
45-
TextView txtRewardBalance;
46-
47-
BranchUniversalObject branchUniversalObject;
43+
private BranchUniversalObject branchUniversalObject;
4844

4945
@Override
5046
protected void onCreate(Bundle savedInstanceState) {
5147
super.onCreate(savedInstanceState);
5248
setContentView(R.layout.activity_main);
5349

54-
txtShortUrl = (EditText) findViewById(R.id.editReferralShortUrl);
55-
txtInstallCount = (TextView) findViewById(R.id.txtInstallCount);
56-
txtRewardBalance = (TextView) findViewById(R.id.txtRewardBalance);
50+
txtShortUrl = findViewById(R.id.editReferralShortUrl);
51+
txtInstallCount = findViewById(R.id.txtInstallCount);
52+
txtRewardBalance = findViewById(R.id.txtRewardBalance);
5753
((ToggleButton) findViewById(R.id.tracking_cntrl_btn)).setChecked(Branch.getInstance().isTrackingDisabled());
5854

5955
// Create a BranchUniversal object for the content referred on this activity instance
@@ -90,7 +86,7 @@ protected void onCreate(Bundle savedInstanceState) {
9086
findViewById(R.id.cmdIdentifyUser).setOnClickListener(new OnClickListener() {
9187
@Override
9288
public void onClick(View v) {
93-
branch.setIdentity("test_user_10", new BranchReferralInitListener() {
89+
Branch.getInstance().setIdentity("test_user_10", new BranchReferralInitListener() {
9490
@Override
9591
public void onInitFinished(JSONObject referringParams, BranchError error) {
9692
if (error != null) {
@@ -106,22 +102,22 @@ public void onInitFinished(JSONObject referringParams, BranchError error) {
106102
findViewById(R.id.cmdClearUser).setOnClickListener(new OnClickListener() {
107103
@Override
108104
public void onClick(View v) {
109-
branch.logout(new Branch.LogoutStatusListener() {
105+
Branch.getInstance().logout(new Branch.LogoutStatusListener() {
110106
@Override
111107
public void onLogoutFinished(boolean loggedOut, BranchError error) {
112108
Log.i("BranchTestBed", "onLogoutFinished " + loggedOut + " errorMessage " + error);
113109
}
114110
});
115111

116-
txtRewardBalance.setText("rewards = ");
117-
txtInstallCount.setText("install count =");
112+
txtRewardBalance.setText(R.string.rewards_empty);
113+
txtInstallCount.setText(R.string.install_count_empty);
118114
}
119115
});
120116

121117
findViewById(R.id.cmdPrintInstallParam).setOnClickListener(new OnClickListener() {
122118
@Override
123119
public void onClick(View v) {
124-
JSONObject obj = branch.getFirstReferringParams();
120+
JSONObject obj = Branch.getInstance().getFirstReferringParams();
125121
Log.i("BranchTestBed", "install params = " + obj.toString());
126122
}
127123
});
@@ -139,33 +135,35 @@ public void onClick(View arg0) {
139135
.setDuration(100);
140136
//.setAlias("myContentName") // in case you need to white label your link
141137

142-
// Sync link create example
143-
txtShortUrl.setText(branchUniversalObject.getShortUrl(MainActivity.this, linkProperties));
138+
// Sync link create example. This makes a network call on the UI thread
139+
// txtShortUrl.setText(branchUniversalObject.getShortUrl(MainActivity.this, linkProperties));
144140

145141
// Async Link creation example
146-
/* branchUniversalObject.generateShortUrl(MainActivity.this, linkProperties, new Branch.BranchLinkCreateListener() {
142+
branchUniversalObject.generateShortUrl(MainActivity.this, linkProperties, new Branch.BranchLinkCreateListener() {
147143
@Override
148144
public void onLinkCreate(String url, BranchError error) {
149-
String shortUrl = url;
145+
if (error != null) {
146+
txtShortUrl.setText(error.getMessage());
147+
} else {
148+
txtShortUrl.setText(url);
149+
}
150150
}
151-
});*/
152-
151+
});
153152
}
154-
155153
});
156154

157155

158156
findViewById(R.id.cmdRefreshReward).setOnClickListener(new OnClickListener() {
159157
@Override
160158
public void onClick(View arg0) {
161-
branch.loadRewards(new BranchReferralStateChangedListener() {
159+
Branch.getInstance().loadRewards(new BranchReferralStateChangedListener() {
162160
@Override
163161
public void onStateChanged(boolean changed, BranchError error) {
164162
if (error != null) {
165163
Log.i("BranchTestBed", "branch load rewards failed. Caused by -" + error.getMessage());
166164
} else {
167165
Log.i("BranchTestBed", "changed = " + changed);
168-
txtRewardBalance.setText("rewards = " + branch.getCredits());
166+
txtRewardBalance.setText(getString(R.string.rewards, Branch.getInstance().getCredits()));
169167
}
170168
}
171169
});
@@ -175,15 +173,15 @@ public void onStateChanged(boolean changed, BranchError error) {
175173
findViewById(R.id.cmdRedeemFive).setOnClickListener(new OnClickListener() {
176174
@Override
177175
public void onClick(View v) {
178-
branch.redeemRewards(5, new BranchReferralStateChangedListener() {
176+
Branch.getInstance().redeemRewards(5, new BranchReferralStateChangedListener() {
179177
@Override
180178
public void onStateChanged(boolean changed, BranchError error) {
181179
if (error != null) {
182180
Log.i("BranchTestBed", "branch redeem rewards failed. Caused by -" + error.getMessage());
183181
} else {
184182
if (changed) {
185183
Log.i("BranchTestBed", "redeemed rewards = " + true);
186-
txtRewardBalance.setText("rewards = " + branch.getCredits());
184+
txtRewardBalance.setText(getString(R.string.rewards, Branch.getInstance().getCredits()));
187185
} else {
188186
Log.i("BranchTestBed", "redeem rewards unknown error ");
189187
}
@@ -196,7 +194,7 @@ public void onStateChanged(boolean changed, BranchError error) {
196194
findViewById(R.id.cmdCommitBuyAction).setOnClickListener(new OnClickListener() {
197195
@Override
198196
public void onClick(View v) {
199-
branch.userCompletedAction("buy", new BranchViewHandler.IBranchViewEvents() {
197+
Branch.getInstance().userCompletedAction("buy", new BranchViewHandler.IBranchViewEvents() {
200198
@Override
201199
public void onBranchViewVisible(String action, String branchViewID) {
202200
Log.i("BranchTestBed", "onBranchViewVisible");
@@ -233,7 +231,7 @@ public void onClick(View arg0) {
233231
} catch (JSONException e) {
234232
e.printStackTrace();
235233
}
236-
branch.userCompletedAction("buy", params);
234+
Branch.getInstance().userCompletedAction("buy", params);
237235
}
238236

239237
});
@@ -263,7 +261,6 @@ public void onClick(View v) {
263261
findViewById(R.id.share_btn).setOnClickListener(new OnClickListener() {
264262
@Override
265263
public void onClick(View view) {
266-
JSONObject obj = new JSONObject();
267264
LinkProperties linkProperties = new LinkProperties()
268265
.addTag("myShareTag1")
269266
.addTag("myShareTag2")
@@ -307,7 +304,7 @@ public void onLinkShareResponse(String sharedLink, String sharedChannel, BranchE
307304
public void onChannelSelected(String channelName) {
308305
}
309306

310-
/**
307+
/*
311308
* Use {@link io.branch.referral.Branch.ExtendedBranchLinkShareListener} if the params need to be modified according to the channel selected by the user.
312309
* This allows modification of content or link properties through callback {@link #onChannelSelected(String, BranchUniversalObject, LinkProperties)} }
313310
*/
@@ -381,7 +378,7 @@ public void onClick(View v) {
381378
((ToggleButton) findViewById(R.id.tracking_cntrl_btn)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
382379
@Override
383380
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
384-
branch.getInstance().disableTracking(isChecked);
381+
Branch.getInstance().disableTracking(isChecked);
385382
}
386383
});
387384

@@ -391,8 +388,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
391388
@Override
392389
protected void onStart() {
393390
super.onStart();
394-
branch = Branch.getInstance();
395-
branch.initSession(new Branch.BranchUniversalReferralInitListener() {
391+
Branch.getInstance().initSession(new Branch.BranchUniversalReferralInitListener() {
396392
@Override
397393
public void onInitFinished(BranchUniversalObject branchUniversalObject, LinkProperties linkProperties, BranchError error) {
398394
if (error != null) {

0 commit comments

Comments
 (0)