11package io .branch .referral .validators ;
22
3+ import android .app .Activity ;
34import android .app .AlertDialog ;
45import android .content .Context ;
6+ import android .content .ContextWrapper ;
7+ import android .os .Build ;
58import android .util .AttributeSet ;
69import android .view .LayoutInflater ;
710import android .view .View ;
811import android .widget .Button ;
912import android .widget .LinearLayout ;
1013import 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 ;
1220import io .branch .referral .R ;
21+ import io .branch .referral .util .LinkProperties ;
1322
1423public 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}
0 commit comments