Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Builder for AdjustConfig and AdjustEvent objects added on top of current functionality #603

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,66 +33,114 @@ 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!");
Log.d("example", "Deep link URL: " + 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}");
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
142 changes: 142 additions & 0 deletions Adjust/sdk-core/src/main/java/com/adjust/sdk/AdjustConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Loading