Skip to content

Commit 8cd6de8

Browse files
committed
fix: restore sharing functionality in Branch SDK
1 parent 26e0e57 commit 8cd6de8

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

Branch-SDK-TestBed/src/main/java/io/branch/branchandroidtestbed/MainActivity.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,19 @@ public void onClick(View view) {
353353
.addControlParameter("$android_deeplink_path", "custom/path/*")
354354
.addControlParameter("$ios_url", "http://example.com/ios")
355355
.setDuration(100);
356-
Branch.init().share(MainActivity.this, branchUniversalObject, linkProperties, "Sharing Branch Short URL", "Using Native Chooser Dialog");
356+
Branch.init().share(MainActivity.this, branchUniversalObject, linkProperties, new Branch.BranchNativeLinkShareListener() {
357+
@Override
358+
public void onLinkShareResponse(String sharedLink, BranchError error) {
359+
Log.d("Native Share Sheet:", "Link Shared: " + sharedLink);
360+
}
361+
362+
@Override
363+
public void onChannelSelected(String channelName) {
364+
Log.d("Native Share Sheet:", "Channel Selected: " + channelName);
365+
}
366+
367+
},
368+
"Sharing Branch Short URL", "Using Native Chooser Dialog");
357369
}
358370
});
359371

@@ -584,8 +596,14 @@ public void onFailure(Exception e) {
584596
findViewById(R.id.logout_btn).setOnClickListener(new OnClickListener() {
585597
@Override
586598
public void onClick(View v) {
587-
Branch.init().logout();
588-
Toast.makeText(getApplicationContext(), "Logged Out", Toast.LENGTH_LONG).show();
599+
Branch.init().logout(new Branch.LogoutStatusListener() {
600+
@Override
601+
public void onLogoutFinished(boolean loggedOut, BranchError error) {
602+
Log.d("BranchSDK_Tester", "onLogoutFinished " + loggedOut + " errorMessage " + error);
603+
Toast.makeText(getApplicationContext(), "Logged Out", Toast.LENGTH_LONG).show();
604+
}
605+
});
606+
589607
}
590608
});
591609

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -950,13 +950,18 @@ public boolean isUserIdentified() {
950950
* <p>This method should be called if you know that a different person is about to use the app. For example,
951951
* if you allow users to log out and let their friend use the app, you should call this to notify Branch
952952
* to create a new user for this device. This will clear the first and latest params, as a new session is created.</p>
953+
*
954+
* @param callback An instance of {@link io.branch.referral.Branch.LogoutStatusListener} to callback with the logout operation status.
953955
*/
954-
public void logout() {
956+
public void logout(LogoutStatusListener callback) {
955957
prefHelper_.setIdentity(PrefHelper.NO_STRING_VALUE);
956958
prefHelper_.clearUserValues();
957959
//On Logout clear the link cache and all pending requests
958960
linkCache_.clear();
959961
requestQueue_.clear();
962+
if (callback != null) {
963+
callback.onLogoutFinished(true, null);
964+
}
960965
}
961966

962967
/**
@@ -1102,13 +1107,13 @@ String generateShortLinkInternal(ServerRequestCreateUrl req) {
11021107
* @param activity The {@link Activity} to show native share sheet chooser dialog.
11031108
* @param buo A {@link BranchUniversalObject} value containing the deep link params.
11041109
* @param linkProperties An object of {@link LinkProperties} specifying the properties of this link
1105-
1110+
* @param callback A {@link Branch.BranchNativeLinkShareListener } instance for getting sharing status.
11061111
* @param title A {@link String } for setting title in native chooser dialog.
11071112
* @param subject A {@link String } for setting subject in native chooser dialog.
11081113
*/
11091114
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
1110-
public void share(@NonNull Activity activity, @NonNull BranchUniversalObject buo, @NonNull LinkProperties linkProperties, String title, String subject){
1111-
NativeShareLinkManager.getInstance().shareLink(activity, buo, linkProperties, title, subject);
1115+
public void share(@NonNull Activity activity, @NonNull BranchUniversalObject buo, @NonNull LinkProperties linkProperties, @Nullable BranchNativeLinkShareListener callback, String title, String subject){
1116+
NativeShareLinkManager.getInstance().shareLink(activity, buo, linkProperties, callback, title, subject);
11121117
}
11131118

11141119
/**

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import io.branch.indexing.BranchUniversalObject;
1919
import io.branch.referral.Branch;
20+
import io.branch.referral.BranchError;
2021
import io.branch.referral.R;
2122
import io.branch.referral.util.LinkProperties;
2223

@@ -112,7 +113,17 @@ private void HandleShareButtonClicked() {
112113
}
113114
BranchUniversalObject buo = new BranchUniversalObject().setCanonicalIdentifier(canonicalIdentifier);
114115
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
115-
Branch.init().share(getActivity(context), buo, lp, titleText.getText().toString(), infoText);
116+
Branch.init().share(getActivity(context), buo, lp, new Branch.BranchNativeLinkShareListener() {
117+
@Override
118+
public void onLinkShareResponse(String sharedLink, BranchError error) {
119+
}
120+
121+
@Override
122+
public void onChannelSelected(String channelName) {
123+
}
124+
},
125+
titleText.getText().toString(),
126+
infoText);
116127
}
117128
}
118129

0 commit comments

Comments
 (0)