From ce09725065796bce9256232e4a92893b808f1cb3 Mon Sep 17 00:00:00 2001 From: Nasser Amini Date: Sat, 18 May 2024 12:04:53 +0330 Subject: [PATCH 1/4] feat: add `Builder` to `AdjustConfig` --- .../java/com/adjust/sdk/AdjustConfig.java | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/Adjust/sdk-core/src/main/java/com/adjust/sdk/AdjustConfig.java b/Adjust/sdk-core/src/main/java/com/adjust/sdk/AdjustConfig.java index ca0b77f42..47808d36c 100644 --- a/Adjust/sdk-core/src/main/java/com/adjust/sdk/AdjustConfig.java +++ b/Adjust/sdk-core/src/main/java/com/adjust/sdk/AdjustConfig.java @@ -454,4 +454,146 @@ private boolean checkEnvironment(String environment) { logger.error("Unknown environment '%s'", environment); return false; } + + public static Builder Builder(Context context, String appToken, String environment) { + return new Builder(context, appToken, environment); + } + + public static class Builder { + + public Builder(Context context, String appToken, String environment) { + adjustConfig = new AdjustConfig(context, appToken, environment); + } + + public AdjustConfig build() { + return adjustConfig; + } + + private static AdjustConfig adjustConfig = null; + + public Builder setEventBufferingEnabled(boolean eventBufferingEnabled) { + adjustConfig.setEventBufferingEnabled(eventBufferingEnabled); + return this; + } + + public Builder setSendInBackground(boolean sendInBackground) { + adjustConfig.setSendInBackground(sendInBackground); + return this; + } + + public Builder setLogLevel(LogLevel logLevel) { + adjustConfig.setLogLevel(logLevel); + return this; + } + + public Builder setDefaultTracker(String defaultTracker) { + adjustConfig.setDefaultTracker(defaultTracker); + return this; + } + + public Builder setOnAttributionChangedListener(OnAttributionChangedListener onAttributionChangedListener) { + adjustConfig.setOnAttributionChangedListener(onAttributionChangedListener); + return this; + } + + public Builder setDeviceKnown(boolean deviceKnown) { + adjustConfig.setDeviceKnown(deviceKnown); + return this; + } + + public Builder setDeepLinkComponent(Class deepLinkComponent) { + adjustConfig.setDeepLinkComponent(deepLinkComponent); + return this; + } + + public Builder setOnEventTrackingSucceededListener(OnEventTrackingSucceededListener onEventTrackingSucceededListener) { + adjustConfig.setOnEventTrackingSucceededListener(onEventTrackingSucceededListener); + return this; + } + + public Builder setOnEventTrackingFailedListener(OnEventTrackingFailedListener onEventTrackingFailedListener) { + adjustConfig.setOnEventTrackingFailedListener(onEventTrackingFailedListener); + return this; + } + + public Builder setOnSessionTrackingSucceededListener(OnSessionTrackingSucceededListener onSessionTrackingSucceededListener) { + adjustConfig.setOnSessionTrackingSucceededListener(onSessionTrackingSucceededListener); + return this; + } + + public Builder setOnSessionTrackingFailedListener(OnSessionTrackingFailedListener onSessionTrackingFailedListener) { + adjustConfig.setOnSessionTrackingFailedListener(onSessionTrackingFailedListener); + return this; + } + + public Builder setOnDeeplinkResponseListener(OnDeeplinkResponseListener onDeeplinkResponseListener) { + adjustConfig.setOnDeeplinkResponseListener(onDeeplinkResponseListener); + return this; + } + + public Builder setDelayStart(double delayStart) { + adjustConfig.setDelayStart(delayStart); + return this; + } + + public Builder setUserAgent(String userAgent) { + adjustConfig.setUserAgent(userAgent); + return this; + } + + public Builder setAppSecret(long secretId, long info1, long info2, long info3, long info4) { + adjustConfig.setAppSecret(secretId, info1, info2, info3, info4); + return this; + } + + public Builder setExternalDeviceId(String externalDeviceId) { + adjustConfig.setExternalDeviceId(externalDeviceId); + return this; + } + + public Builder setPreinstallTrackingEnabled(boolean preinstallTrackingEnabled) { + adjustConfig.setPreinstallTrackingEnabled(preinstallTrackingEnabled); + return this; + } + + public Builder setPreinstallFilePath(String preinstallFilePath) { + adjustConfig.setPreinstallFilePath(preinstallFilePath); + return this; + } + + public Builder setNeedsCost(boolean needsCost) { + adjustConfig.setNeedsCost(needsCost); + return this; + } + + public Builder setPlayStoreKidsAppEnabled(boolean playStoreKidsAppEnabled) { + adjustConfig.setPlayStoreKidsAppEnabled(playStoreKidsAppEnabled); + return this; + } + + public Builder setCoppaCompliantEnabled(boolean coppaCompliantEnabled) { + adjustConfig.setCoppaCompliantEnabled(coppaCompliantEnabled); + return this; + } + + public Builder setFinalAttributionEnabled(boolean finalAttributionEnabled){ + adjustConfig.setFinalAttributionEnabled(finalAttributionEnabled); + return this; + } + + public Builder setFbAppId(String fbAppId){ + adjustConfig.setFbAppId(fbAppId); + return this; + } + + public Builder setUrlStrategy(String urlStrategy){ + adjustConfig.setUrlStrategy(urlStrategy); + return this; + } + + public Builder setReadDeviceInfoOnceEnabled(boolean readDeviceInfoOnceEnabled){ + adjustConfig.setReadDeviceInfoOnceEnabled(readDeviceInfoOnceEnabled); + return this; + } + } } \ No newline at end of file From dc74f30d59a31a7bc02f8ad0647a665bce01d977 Mon Sep 17 00:00:00 2001 From: Nasser Amini Date: Sat, 18 May 2024 12:05:21 +0330 Subject: [PATCH 2/4] feat: update example for `AdjustConfig` `Builder` --- .../adjust/examples/GlobalApplication.java | 110 +++++++++++++----- 1 file changed, 79 insertions(+), 31 deletions(-) diff --git a/Adjust/example-app-java/src/main/java/com/adjust/examples/GlobalApplication.java b/Adjust/example-app-java/src/main/java/com/adjust/examples/GlobalApplication.java index 2c569df99..0388c3c54 100644 --- a/Adjust/example-app-java/src/main/java/com/adjust/examples/GlobalApplication.java +++ b/Adjust/example-app-java/src/main/java/com/adjust/examples/GlobalApplication.java @@ -33,58 +33,46 @@ public void onCreate() { String appToken = "2fm9gkqubvpc"; String environment = AdjustConfig.ENVIRONMENT_SANDBOX; - AdjustConfig config = new AdjustConfig(this, appToken, environment); - - // Change the log level. - config.setLogLevel(LogLevel.VERBOSE); - - // Set attribution delegate. - config.setOnAttributionChangedListener(new OnAttributionChangedListener() { +// AdjustConfig config = new AdjustConfig(this, appToken, environment); + AdjustConfig config = AdjustConfig.Builder(this,appToken,environment).setLogLevel( + LogLevel.VERBOSE + ).setOnAttributionChangedListener(new OnAttributionChangedListener() { @Override public void onAttributionChanged(AdjustAttribution attribution) { Log.d("example", "Attribution callback called!"); Log.d("example", "Attribution: " + attribution.toString()); } - }); - - // Set event success tracking delegate. - config.setOnEventTrackingSucceededListener(new OnEventTrackingSucceededListener() { + }).setOnEventTrackingSucceededListener(new OnEventTrackingSucceededListener() { @Override public void onFinishedEventTrackingSucceeded(AdjustEventSuccess eventSuccessResponseData) { Log.d("example", "Event success callback called!"); Log.d("example", "Event success data: " + eventSuccessResponseData.toString()); } - }); - - // Set event failure tracking delegate. - config.setOnEventTrackingFailedListener(new OnEventTrackingFailedListener() { + }).setOnEventTrackingFailedListener(new OnEventTrackingFailedListener() { @Override public void onFinishedEventTrackingFailed(AdjustEventFailure eventFailureResponseData) { Log.d("example", "Event failure callback called!"); Log.d("example", "Event failure data: " + eventFailureResponseData.toString()); } - }); - - // Set session success tracking delegate. - config.setOnSessionTrackingSucceededListener(new OnSessionTrackingSucceededListener() { + }).setOnEventTrackingFailedListener(new OnEventTrackingFailedListener() { + @Override + public void onFinishedEventTrackingFailed(AdjustEventFailure eventFailureResponseData) { + Log.d("example", "Event failure callback called!"); + Log.d("example", "Event failure data: " + eventFailureResponseData.toString()); + } + }).setOnSessionTrackingSucceededListener(new OnSessionTrackingSucceededListener() { @Override public void onFinishedSessionTrackingSucceeded(AdjustSessionSuccess sessionSuccessResponseData) { Log.d("example", "Session success callback called!"); Log.d("example", "Session success data: " + sessionSuccessResponseData.toString()); } - }); - - // Set session failure tracking delegate. - config.setOnSessionTrackingFailedListener(new OnSessionTrackingFailedListener() { + }).setOnSessionTrackingFailedListener(new OnSessionTrackingFailedListener() { @Override - public void onFinishedSessionTrackingFailed(AdjustSessionFailure sessionFailureResponseData) { + public void onFinishedSessionTrackingFailed(AdjustSessionFailure failureResponseData) { Log.d("example", "Session failure callback called!"); - Log.d("example", "Session failure data: " + sessionFailureResponseData.toString()); + Log.d("example", "Session failure data: " + failureResponseData.toString()); } - }); - - // Evaluate deferred deep link to be launched. - config.setOnDeeplinkResponseListener(new OnDeeplinkResponseListener() { + }).setOnDeeplinkResponseListener(new OnDeeplinkResponseListener() { @Override public boolean launchReceivedDeeplink(Uri deeplink) { Log.d("example", "Deferred deep link callback called!"); @@ -92,7 +80,67 @@ public boolean launchReceivedDeeplink(Uri deeplink) { return true; } - }); + }).setSendInBackground(true) + .build(); + + // Change the log level. +// config.setLogLevel(LogLevel.VERBOSE); + + // Set attribution delegate. +// config.setOnAttributionChangedListener(new OnAttributionChangedListener() { +// @Override +// public void onAttributionChanged(AdjustAttribution attribution) { +// Log.d("example", "Attribution callback called!"); +// Log.d("example", "Attribution: " + attribution.toString()); +// } +// }); + + // Set event success tracking delegate. +// config.setOnEventTrackingSucceededListener(new OnEventTrackingSucceededListener() { +// @Override +// public void onFinishedEventTrackingSucceeded(AdjustEventSuccess eventSuccessResponseData) { +// Log.d("example", "Event success callback called!"); +// Log.d("example", "Event success data: " + eventSuccessResponseData.toString()); +// } +// }); + + // Set event failure tracking delegate. +// config.setOnEventTrackingFailedListener(new OnEventTrackingFailedListener() { +// @Override +// public void onFinishedEventTrackingFailed(AdjustEventFailure eventFailureResponseData) { +// Log.d("example", "Event failure callback called!"); +// Log.d("example", "Event failure data: " + eventFailureResponseData.toString()); +// } +// }); + + // Set session success tracking delegate. +// config.setOnSessionTrackingSucceededListener(new OnSessionTrackingSucceededListener() { +// @Override +// public void onFinishedSessionTrackingSucceeded(AdjustSessionSuccess sessionSuccessResponseData) { +// Log.d("example", "Session success callback called!"); +// Log.d("example", "Session success data: " + sessionSuccessResponseData.toString()); +// } +// }); + + // Set session failure tracking delegate. +// config.setOnSessionTrackingFailedListener(new OnSessionTrackingFailedListener() { +// @Override +// public void onFinishedSessionTrackingFailed(AdjustSessionFailure sessionFailureResponseData) { +// Log.d("example", "Session failure callback called!"); +// Log.d("example", "Session failure data: " + sessionFailureResponseData.toString()); +// } +// }); + + // Evaluate deferred deep link to be launched. +// config.setOnDeeplinkResponseListener(new OnDeeplinkResponseListener() { +// @Override +// public boolean launchReceivedDeeplink(Uri deeplink) { +// Log.d("example", "Deferred deep link callback called!"); +// Log.d("example", "Deep link URL: " + deeplink); +// +// return true; +// } +// }); // Set default tracker. // config.setDefaultTracker("{YourDefaultTracker}"); @@ -101,7 +149,7 @@ public boolean launchReceivedDeeplink(Uri deeplink) { // config.setProcessName("com.adjust.examples"); // Allow to send in the background. - config.setSendInBackground(true); +// config.setSendInBackground(true); // Enable event buffering. // config.setEventBufferingEnabled(true); From f473da8f0959c7bbe5f7a2438680524d0c7b1226 Mon Sep 17 00:00:00 2001 From: Nasser Amini Date: Tue, 28 May 2024 14:47:30 +0330 Subject: [PATCH 3/4] feat: add Builder pattern for creation of "AdjustEvent" --- .../main/java/com/adjust/sdk/AdjustEvent.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/Adjust/sdk-core/src/main/java/com/adjust/sdk/AdjustEvent.java b/Adjust/sdk-core/src/main/java/com/adjust/sdk/AdjustEvent.java index 00da98923..b0af87baa 100644 --- a/Adjust/sdk-core/src/main/java/com/adjust/sdk/AdjustEvent.java +++ b/Adjust/sdk-core/src/main/java/com/adjust/sdk/AdjustEvent.java @@ -152,4 +152,69 @@ private boolean checkRevenue(Double revenue, String currency) { } return true; } + + public static Builder Builder(String eventToken) { + return new Builder(eventToken); + } + + public static class Builder { + public Builder(String eventToken) { + event = new AdjustEvent(eventToken); + } + + private static AdjustEvent event = null; + + public Builder setRevenue(double revenue, String currency) { + event.setRevenue(revenue, currency); + return this; + } + + public Builder addCallbackParameter(String key, String value) { + event.addCallbackParameter(key, value); + return this; + } + + public Builder addCallbackParameterMap(Map parameters) { + for (Map.Entry entry : parameters.entrySet()) { + event.addCallbackParameter(entry.getKey(), entry.getValue()); + } + return this; + } + + public Builder addPartnerParameter(String key, String value) { + event.addPartnerParameter(key, value); + return this; + } + + public Builder addPartnerParameterMap(Map parameters) { + for (Map.Entry entry : parameters.entrySet()) { + event.addPartnerParameter(entry.getKey(), entry.getValue()); + } + return this; + } + + public Builder setOrderId(String orderId) { + event.setOrderId(orderId); + return this; + } + + public Builder setCallbackId(String callbackId) { + event.setCallbackId(callbackId); + return this; + } + + public Builder setProductId(String productId) { + event.setProductId(productId); + return this; + } + + public Builder setPurchaseToken(String purchaseToken) { + event.setPurchaseToken(purchaseToken); + return this; + } + + public AdjustEvent build() { + return event; + } + } } From 678d975936c217ea0a981371596342f534a83d67 Mon Sep 17 00:00:00 2001 From: Nasser Amini Date: Tue, 28 May 2024 14:47:36 +0330 Subject: [PATCH 4/4] feat: update implementation of events in Java example app --- .../com/adjust/examples/MainActivity.java | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/Adjust/example-app-java/src/main/java/com/adjust/examples/MainActivity.java b/Adjust/example-app-java/src/main/java/com/adjust/examples/MainActivity.java index 5ca6f5bd5..602a8b06a 100644 --- a/Adjust/example-app-java/src/main/java/com/adjust/examples/MainActivity.java +++ b/Adjust/example-app-java/src/main/java/com/adjust/examples/MainActivity.java @@ -73,36 +73,40 @@ public boolean onOptionsItemSelected(MenuItem item) { } public void onTrackSimpleEventClick(View v) { - AdjustEvent event = new AdjustEvent(EVENT_TOKEN_SIMPLE); - - Adjust.trackEvent(event); +// AdjustEvent event = new AdjustEvent(EVENT_TOKEN_SIMPLE); +// +// Adjust.trackEvent(event); + Adjust.trackEvent(AdjustEvent.Builder(EVENT_TOKEN_SIMPLE).build()); } public void onTrackRevenueEventClick(View v) { - AdjustEvent event = new AdjustEvent(EVENT_TOKEN_REVENUE); - - // Add revenue 1 cent of an euro. - event.setRevenue(0.01, "EUR"); - - Adjust.trackEvent(event); +// AdjustEvent event = new AdjustEvent(EVENT_TOKEN_REVENUE); +// +// // Add revenue 1 cent of an euro. +// event.setRevenue(0.01, "EUR"); +// +// Adjust.trackEvent(event); + Adjust.trackEvent(AdjustEvent.Builder(EVENT_TOKEN_REVENUE).setRevenue(0.01, "EUR").build()); } public void onTrackCallbackEventClick(View v) { - AdjustEvent event = new AdjustEvent(EVENT_TOKEN_CALLBACK); - - // Add callback parameters to this parameter. - event.addCallbackParameter("key", "value"); - - Adjust.trackEvent(event); +// AdjustEvent event = new AdjustEvent(EVENT_TOKEN_CALLBACK); +// +// // Add callback parameters to this parameter. +// event.addCallbackParameter("key", "value"); +// +// Adjust.trackEvent(event); + Adjust.trackEvent(AdjustEvent.Builder(EVENT_TOKEN_CALLBACK).addCallbackParameter("key", "value").build()); } public void onTrackPartnerEventClick(View v) { - AdjustEvent event = new AdjustEvent(EVENT_TOKEN_PARTNER); - - // Add partner parameters to this parameter. - event.addPartnerParameter("foo", "bar"); - - Adjust.trackEvent(event); +// AdjustEvent event = new AdjustEvent(EVENT_TOKEN_PARTNER); +// +// // Add partner parameters to this parameter. +// event.addPartnerParameter("foo", "bar"); +// +// Adjust.trackEvent(event); + Adjust.trackEvent(AdjustEvent.Builder(EVENT_TOKEN_PARTNER).addPartnerParameter("foo", "bar").build()); } public void onEnableDisableOfflineModeClick(View v) {