Skip to content

Commit 90452c2

Browse files
committed
feat: restore interfaces and methods
- Restore BranchLastAttributedTouchDataListener and BranchNativeLinkShareListener interfaces for handling callbacks related to last attributed touch data and native link sharing. - Restore methods in the Branch class to fetch last attributed touch data with optional attribution window. - Restore GCLID expiration window management in PrefHelper. - Restore ServerRequestGetLATD to support new callback mechanisms for data retrieval success and failure. - This update restore the SDK's capabilities for handling attribution data and link sharing events.
1 parent c22fcd0 commit 90452c2

File tree

3 files changed

+174
-3
lines changed

3 files changed

+174
-3
lines changed

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

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,56 @@ public interface BranchLinkCreateListener {
14651465
void onLinkCreate(String url, BranchError error);
14661466
}
14671467

1468+
/**
1469+
* Interface for handling last attributed touch data callbacks.
1470+
*
1471+
* @see JSONObject
1472+
* @see BranchError
1473+
*/
1474+
public interface BranchLastAttributedTouchDataListener {
1475+
/**
1476+
* Called when last attributed touch data is successfully retrieved.
1477+
*
1478+
* @param jsonObject The last attributed touch data as a JSONObject
1479+
* @param error null if successful, otherwise contains error information
1480+
*/
1481+
void onDataFetched(JSONObject jsonObject, BranchError error);
1482+
}
1483+
1484+
/**
1485+
* Interface for handling native link share callbacks.
1486+
*
1487+
* @see String
1488+
* @see BranchError
1489+
*/
1490+
public interface BranchNativeLinkShareListener {
1491+
/**
1492+
* Called when a link is shared successfully.
1493+
*
1494+
* @param sharedLink The shared link URL
1495+
* @param sharedBy The channel through which the link was shared
1496+
* @param error null if successful, otherwise contains error information
1497+
*/
1498+
void onLinkShareResponse(String sharedLink, String sharedBy, BranchError error);
1499+
1500+
/**
1501+
* Called when a channel is selected for sharing.
1502+
*
1503+
* @param selectedChannel The name of the selected channel
1504+
*/
1505+
void onChannelSelected(String selectedChannel);
1506+
1507+
/**
1508+
* Called when the share link dialog is launched.
1509+
*/
1510+
void onShareLinkDialogLaunched();
1511+
1512+
/**
1513+
* Called when the share link dialog is dismissed.
1514+
*/
1515+
void onShareLinkDialogDismissed();
1516+
}
1517+
14681518
/**
14691519
* <p>An Interface class that is implemented by all classes that make use of
14701520
@@ -2307,4 +2357,97 @@ private void launchExternalBrowser(String url) {
23072357
BranchLogger.e("launchExternalBrowser caught exception: " + ex);
23082358
}
23092359
}
2360+
2361+
/**
2362+
* Sets the referrer GCLID valid for window.
2363+
*
2364+
* Minimum of 0 milliseconds
2365+
* Maximum of 3 years
2366+
* @param window A {@link Long} value specifying the number of milliseconds to wait before
2367+
* deleting the locally persisted GCLID value.
2368+
*/
2369+
public void setReferrerGclidValidForWindow(long window){
2370+
if(prefHelper_ != null){
2371+
prefHelper_.setReferrerGclidValidForWindow(window);
2372+
}
2373+
}
2374+
2375+
/**
2376+
* Enables referring url attribution for preinstalled apps.
2377+
*
2378+
* By default, Branch prioritizes preinstall attribution on preinstalled apps.
2379+
* Some clients prefer the referring link, when present, to be prioritized over preinstall attribution.
2380+
*/
2381+
public static void setReferringLinkAttributionForPreinstalledAppsEnabled() {
2382+
referringLinkAttributionForPreinstalledAppsEnabled = true;
2383+
}
2384+
2385+
/**
2386+
* Returns whether referring link attribution for preinstalled apps is enabled.
2387+
*
2388+
* @return {@link Boolean} true if referring link attribution for preinstalled apps is enabled, false otherwise.
2389+
*/
2390+
public static boolean isReferringLinkAttributionForPreinstalledAppsEnabled() {
2391+
return referringLinkAttributionForPreinstalledAppsEnabled;
2392+
}
2393+
2394+
/**
2395+
* Sets whether user agent synchronization is enabled.
2396+
*
2397+
* @param sync {@link Boolean} true to enable user agent synchronization, false to disable.
2398+
*/
2399+
public static void setIsUserAgentSync(boolean sync){
2400+
userAgentSync = sync;
2401+
}
2402+
2403+
/**
2404+
* Returns whether user agent synchronization is enabled.
2405+
*
2406+
* @return {@link Boolean} true if user agent synchronization is enabled, false otherwise.
2407+
*/
2408+
public static boolean getIsUserAgentSync(){
2409+
return userAgentSync;
2410+
}
2411+
2412+
/**
2413+
* Gets the available last attributed touch data. The attribution window is set to the value last
2414+
* saved via PreferenceHelper.setLATDAttributionWindow(). If no value has been saved, Branch
2415+
* defaults to a 30 day attribution window (SDK sends -1 to request the default from the server).
2416+
*
2417+
* @param callback An instance of {@link io.branch.referral.ServerRequestGetLATD.BranchLastAttributedTouchDataListener}
2418+
* to callback with last attributed touch data
2419+
*
2420+
*/
2421+
public void getLastAttributedTouchData(@NonNull BranchLastAttributedTouchDataListener callback) {
2422+
if (context_ != null) {
2423+
requestQueue_.handleNewRequest(new ServerRequestGetLATD(context_, Defines.RequestPath.GetLATD, callback));
2424+
}
2425+
}
2426+
2427+
/**
2428+
* Gets the available last attributed touch data with a custom set attribution window.
2429+
*
2430+
* @param callback An instance of {@link io.branch.referral.ServerRequestGetLATD.BranchLastAttributedTouchDataListener}
2431+
* to callback with last attributed touch data
2432+
* @param attributionWindow An {@link int} to bound the the window of time in days during which
2433+
* the attribution data is considered valid. Note that, server side, the
2434+
* maximum value is 90.
2435+
*
2436+
*/
2437+
public void getLastAttributedTouchData(BranchLastAttributedTouchDataListener callback, int attributionWindow) {
2438+
if (context_ != null) {
2439+
requestQueue_.handleNewRequest(new ServerRequestGetLATD(context_, Defines.RequestPath.GetLATD, callback, attributionWindow));
2440+
}
2441+
}
2442+
2443+
/**
2444+
* Gets the link share listener callback.
2445+
*
2446+
* @return {@link Branch.BranchNativeLinkShareListener} the current link share listener callback, or null if not set.
2447+
*/
2448+
public Branch.BranchNativeLinkShareListener getLinkShareListenerCallback() {
2449+
// This method was removed during modernization but is kept for backward compatibility
2450+
// The actual link sharing functionality has been moved to NativeShareLinkManager
2451+
return null;
2452+
}
23102453
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,19 @@ public long getReferrerGclidValidForWindow() {
819819
return getLong(KEY_GCLID_VALID_FOR_WINDOW, DEFAULT_VALID_WINDOW_FOR_REFERRER_GCLID);
820820
}
821821

822+
/**
823+
* Sets the GCLID expiration window in milliseconds
824+
* @param window The expiration window in milliseconds
825+
*/
826+
public void setReferrerGclidValidForWindow(long window) {
827+
if (window >= MIN_VALID_WINDOW_FOR_REFERRER_GCLID && window <= MAX_VALID_WINDOW_FOR_REFERRER_GCLID) {
828+
setLong(KEY_GCLID_VALID_FOR_WINDOW, window);
829+
} else {
830+
BranchLogger.w("Invalid GCLID expiration window: " + window + ". Must be between " +
831+
MIN_VALID_WINDOW_FOR_REFERRER_GCLID + " and " + MAX_VALID_WINDOW_FOR_REFERRER_GCLID);
832+
}
833+
}
834+
822835
/**
823836
* <p> Set the KEY_APP_LINK {@link String} values that has been started the application. </p>
824837
*

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class ServerRequestGetLATD extends ServerRequest {
1010
// defaultAttributionWindow is the "default" for the SDK's side, server interprets it as 30 days
1111
protected static final int defaultAttributionWindow = -1;
1212
private int attributionWindow;
13+
private Branch.BranchLastAttributedTouchDataListener callback;
1314

1415
ServerRequestGetLATD(Context context, Defines.RequestPath requestPath) {
1516
this(context, requestPath, PrefHelper.getInstance(context).getLATDAttributionWindow());
@@ -27,6 +28,16 @@ public class ServerRequestGetLATD extends ServerRequest {
2728
updateEnvironment(context, reqBody);
2829
}
2930

31+
ServerRequestGetLATD(Context context, Defines.RequestPath requestPath, Branch.BranchLastAttributedTouchDataListener callback) {
32+
this(context, requestPath);
33+
this.callback = callback;
34+
}
35+
36+
ServerRequestGetLATD(Context context, Defines.RequestPath requestPath, Branch.BranchLastAttributedTouchDataListener callback, int attributionWindow) {
37+
this(context, requestPath, attributionWindow);
38+
this.callback = callback;
39+
}
40+
3041
protected int getAttributionWindow() {
3142
return attributionWindow;
3243
}
@@ -38,12 +49,16 @@ public boolean handleErrors(Context context) {
3849

3950
@Override
4051
public void onRequestSucceeded(ServerResponse response, Branch branch) {
41-
// Remove the callback logic as per the instructions
52+
if (callback != null) {
53+
callback.onDataFetched(response.getObject(), null);
54+
}
4255
}
4356

4457
@Override
4558
public void handleFailure(int statusCode, String causeMsg) {
46-
// Remove the callback logic as per the instructions
59+
if (callback != null) {
60+
callback.onDataFetched(null, new BranchError(causeMsg, statusCode));
61+
}
4762
}
4863

4964
@Override
@@ -53,7 +68,7 @@ public boolean isGetRequest() {
5368

5469
@Override
5570
public void clearCallbacks() {
56-
// Remove the callback logic as per the instructions
71+
callback = null;
5772
}
5873

5974
@Override

0 commit comments

Comments
 (0)