Skip to content

Commit eb5c4ba

Browse files
Added share button functionality
Added share button functionality
1 parent 5a37852 commit eb5c4ba

File tree

3 files changed

+84
-40
lines changed

3 files changed

+84
-40
lines changed

Branch-SDK/src/main/java/io/branch/referral/validators/LinkingValidatorDialog.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ private enum ROUTING_TYPE { CANONICAL_URL, DEEPLINK_PATH, CUSTOM }
3535
private EditText customKeyEditText;
3636
private EditText customValueEditText;
3737
private Context context;
38-
private String regularBranchLink; //ordinary Branch link to test App Links / Universal Links
39-
private String uriFallbackBranchLink; //Branch link with URI redirect mode of 2
40-
private String webOnlyBranchLink; //Web-only Branch link
41-
private String missingDeeplinkDataBranchLink; //Branch link with empty deep link data (to test graceful handling when data is missing)
4238
private LinkingValidatorDialogRowItem row1;
4339
private LinkingValidatorDialogRowItem row2;
4440
private LinkingValidatorDialogRowItem row3;
@@ -139,11 +135,6 @@ void GenerateBranchLinks() {
139135
ctaButton.setText(LinkingValidatorConstants.step3ButtonText);
140136
linkingValidatorRowsLayout.setVisibility(View.VISIBLE);
141137

142-
row1.InitializeRow(LinkingValidatorConstants.linkingValidatorRow1Title, LinkingValidatorConstants.infoButton1Copy);
143-
row2.InitializeRow(LinkingValidatorConstants.linkingValidatorRow2Title, LinkingValidatorConstants.infoButton2Copy);
144-
row3.InitializeRow(LinkingValidatorConstants.linkingValidatorRow3Title, LinkingValidatorConstants.infoButton3Copy);
145-
row4.InitializeRow(LinkingValidatorConstants.linkingValidatorRow4Title, LinkingValidatorConstants.infoButton4Copy);
146-
147138
customKeyEditText = findViewById(R.id.keyEditText);
148139
customValueEditText = findViewById(R.id.valueEditText);
149140

@@ -153,19 +144,9 @@ void GenerateBranchLinks() {
153144
routingValue = customValueEditText.getText().toString();
154145
}
155146

156-
regularBranchLink = GenerateBranchLink("regularBranchLink", routingKey, routingValue);
157-
uriFallbackBranchLink = GenerateBranchLink("uriFallbackBranchLink", "$uri_redirect_mode", "2", routingKey, routingValue);
158-
webOnlyBranchLink = GenerateBranchLink("webOnlyBranchLink", "$web_only", "true", routingKey, routingValue);
159-
missingDeeplinkDataBranchLink = GenerateBranchLink("missingDataBranchLink", routingKey, "");
160-
161-
}
162-
163-
String GenerateBranchLink(String identifierForBUO, String... params) {
164-
LinkProperties lp = new LinkProperties();
165-
for(int i = 0; i < params.length; i+=2) {
166-
lp.addControlParameter(params[i], params[i+1]);
167-
}
168-
BranchUniversalObject buo = new BranchUniversalObject().setCanonicalIdentifier(identifierForBUO);
169-
return buo.getShortUrl(context, lp);
147+
row1.InitializeRow(LinkingValidatorConstants.linkingValidatorRow1Title, LinkingValidatorConstants.infoButton1Copy, routingKey, routingValue, "regularBranchLink");
148+
row2.InitializeRow(LinkingValidatorConstants.linkingValidatorRow2Title, LinkingValidatorConstants.infoButton2Copy, routingKey, routingValue, "uriFallbackBranchLink", "$uri_redirect_mode", "2");
149+
row3.InitializeRow(LinkingValidatorConstants.linkingValidatorRow3Title, LinkingValidatorConstants.infoButton3Copy, routingKey, routingValue, "webOnlyBranchLink", "$web_only", "true");
150+
row4.InitializeRow(LinkingValidatorConstants.linkingValidatorRow4Title, LinkingValidatorConstants.infoButton4Copy, routingKey, "", "missingDataBranchLink");
170151
}
171152
}
Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
11
package io.branch.referral.validators;
22

3+
import android.app.Activity;
34
import android.app.AlertDialog;
45
import android.content.Context;
6+
import android.content.ContextWrapper;
7+
import android.os.Build;
58
import android.util.AttributeSet;
69
import android.view.LayoutInflater;
710
import android.view.View;
811
import android.widget.Button;
912
import android.widget.LinearLayout;
1013
import android.widget.TextView;
1114

15+
import java.util.HashMap;
16+
17+
import io.branch.indexing.BranchUniversalObject;
18+
import io.branch.referral.Branch;
19+
import io.branch.referral.BranchError;
1220
import io.branch.referral.R;
21+
import io.branch.referral.util.LinkProperties;
1322

1423
public class LinkingValidatorDialogRowItem extends LinearLayout {
1524

16-
Context context;
25+
private static final String TAG = "BranchSDK";
26+
1727
TextView titleText;
1828
Button infoButton;
1929
String infoText;
30+
Button shareButton;
31+
HashMap<String, String> linkDataParams;
32+
String routingKey;
33+
String routingValue;
34+
String canonicalIdentifier;
35+
Context context;
2036

2137
public LinkingValidatorDialogRowItem(Context context, AttributeSet attrs) {
2238
super(context, attrs);
@@ -28,18 +44,73 @@ public LinkingValidatorDialogRowItem(Context context, AttributeSet attrs, int de
2844
this.context = context;
2945
}
3046

31-
public void InitializeRow(String title, String infoText) {
47+
public void InitializeRow(String title, String infoText, String routingKey, String routingValue, String canonicalIdentifier, String... params) {
3248
View view = LayoutInflater.from(getContext()).inflate(R.layout.linking_validator_dialog_row_item, null);
3349
this.addView(view);
3450
titleText = view.findViewById(R.id.linkingValidatorRowTitleText);
3551
infoButton = view.findViewById(R.id.linkingValidatorRowInfoButton);
52+
shareButton = view.findViewById(R.id.linkingValidatorRowShareButton);
53+
3654
titleText.setText(title);
3755
this.infoText = infoText;
56+
this.routingKey = routingKey;
57+
this.routingValue = routingValue;
58+
this.canonicalIdentifier = canonicalIdentifier;
59+
60+
linkDataParams = new HashMap<>();
61+
62+
for (int i = 0; i < params.length; i += 2) {
63+
linkDataParams.put(params[i], params[i + 1]);
64+
}
65+
3866
infoButton.setOnClickListener(view1 -> {
39-
AlertDialog.Builder builder = new AlertDialog.Builder(context);
40-
builder.setMessage(infoText).setTitle(titleText.getText());
41-
AlertDialog dialog = builder.create();
42-
dialog.show();
67+
HandleInfoButtonClicked();
68+
});
69+
70+
shareButton.setOnClickListener(view2 -> {
71+
HandleShareButtonClicked();
4372
});
4473
}
74+
75+
private void HandleInfoButtonClicked() {
76+
AlertDialog.Builder builder = new AlertDialog.Builder(context);
77+
builder.setMessage(infoText).setTitle(titleText.getText());
78+
AlertDialog dialog = builder.create();
79+
dialog.show();
80+
}
81+
82+
private void HandleShareButtonClicked() {
83+
LinkProperties lp = new LinkProperties();
84+
for (String key : linkDataParams.keySet()) {
85+
lp.addControlParameter(key, linkDataParams.get(key));
86+
}
87+
BranchUniversalObject buo = new BranchUniversalObject().setCanonicalIdentifier(canonicalIdentifier);
88+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
89+
Branch.getInstance().share(getActivity(context), buo, lp, new Branch.BranchNativeLinkShareListener() {
90+
@Override
91+
public void onLinkShareResponse(String sharedLink, BranchError error) {
92+
}
93+
94+
@Override
95+
public void onChannelSelected(String channelName) {
96+
}
97+
},
98+
titleText.getText().toString(),
99+
infoText);
100+
}
101+
}
102+
103+
public Activity getActivity(Context context) {
104+
if (context == null) {
105+
return null;
106+
} else if (context instanceof ContextWrapper) {
107+
if (context instanceof Activity) {
108+
return (Activity) context;
109+
} else {
110+
return getActivity(((ContextWrapper) context).getBaseContext());
111+
}
112+
}
113+
114+
return null;
115+
}
45116
}

Branch-SDK/src/main/res/layout/linking_validator_dialog_row_item.xml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,23 @@
2121
android:id="@+id/linkingValidatorRowInfoButton"
2222
android:layout_width="0dp"
2323
android:layout_height="match_parent"
24-
android:layout_weight="0.15"
24+
android:layout_weight="0.2"
2525
android:text="Info"
2626
android:textSize="9sp" />
2727

28-
<Button
29-
android:id="@+id/linkingValidatorRowCopyButton"
30-
android:layout_width="0dp"
31-
android:layout_height="match_parent"
32-
android:layout_weight="0.15"
33-
android:text="Copy"
34-
android:textSize="9sp" />
35-
3628
<Button
3729
android:id="@+id/linkingValidatorRowShareButton"
3830
android:layout_width="0dp"
3931
android:layout_height="match_parent"
40-
android:layout_weight="0.15"
32+
android:layout_weight="0.2"
4133
android:text="Share"
4234
android:textSize="9sp" />
4335

4436
<Button
4537
android:id="@+id/linkingValidatorRowDebugButton"
4638
android:layout_width="0dp"
4739
android:layout_height="match_parent"
48-
android:layout_weight="0.15"
40+
android:layout_weight="0.2"
4941
android:text="Debug"
5042
android:textSize="9sp" />
5143

0 commit comments

Comments
 (0)