Skip to content

Commit

Permalink
chore: Improve public settings screen UX (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmoud-elmorabea authored Oct 16, 2024
1 parent ffa1f75 commit c89791b
Show file tree
Hide file tree
Showing 7 changed files with 536 additions and 395 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.customer.android.sample.java_layout.support.Optional;
import io.customer.android.sample.java_layout.utils.StringUtils;
import io.customer.datapipelines.extensions.RegionExtKt;
import io.customer.sdk.core.util.CioLogLevel;
import io.customer.sdk.data.model.Region;

/**
Expand All @@ -23,20 +24,24 @@ private static class Keys {
static final String SITE_ID = "cio_sdk_site_id";
static final String API_HOST = "cio_sdk_api_host";
static final String CDN_HOST = "cio_sdk_cdn_host";
static final String FLUSH_INTERVAL = "cio_sdk_flush_interval";
static final String FLUSH_AT = "cio_sdk_flush_at";
static final String TRACK_SCREENS = "cio_sdk_track_screens";
static final String TRACK_DEVICE_ATTRIBUTES = "cio_sdk_track_device_attributes";
static final String DEBUG_MODE = "cio_sdk_debug_mode";
static final String LOG_LEVEL = "cio_sdk_log_level";
static final String REGION = "cio_sdk_region";
static final String TRACK_APPLICATION_LIFECYCLE = "cio_sdk_track_application_lifecycle";
static final String TEST_MODE_ENABLED = "cio_sdk_test_mode";
static final String IN_APP_MESSAGING_ENABLED = "cio_sdk_in_app_messaging_enabled";
}

public static CustomerIOSDKConfig getDefaultConfigurations() {
return new CustomerIOSDKConfig(BuildConfig.CDP_API_KEY,
BuildConfig.SITE_ID,
RegionExtKt.apiHost(Region.US.INSTANCE),
RegionExtKt.cdnHost(Region.US.INSTANCE),
30,
20,
true,
true,
CioLogLevel.DEBUG,
Region.US.INSTANCE,
true,
true,
true);
Expand All @@ -53,21 +58,25 @@ public static Optional<CustomerIOSDKConfig> fromMap(@NonNull Map<String, String>
CustomerIOSDKConfig defaultConfig = getDefaultConfigurations();
String apiHost = bundle.get(Keys.API_HOST);
String cdnHost = bundle.get(Keys.CDN_HOST);
Integer flushInterval = StringUtils.parseInteger(bundle.get(Keys.FLUSH_INTERVAL), defaultConfig.flushInterval);
Integer flushAt = StringUtils.parseInteger(bundle.get(Keys.FLUSH_AT), defaultConfig.flushAt);
boolean screenTrackingEnabled = StringUtils.parseBoolean(bundle.get(Keys.TRACK_SCREENS), defaultConfig.screenTrackingEnabled);
boolean deviceAttributesTrackingEnabled = StringUtils.parseBoolean(bundle.get(Keys.TRACK_DEVICE_ATTRIBUTES), defaultConfig.deviceAttributesTrackingEnabled);
boolean debugModeEnabled = StringUtils.parseBoolean(bundle.get(Keys.DEBUG_MODE), defaultConfig.debugModeEnabled);
CioLogLevel logLevel = CioLogLevel.Companion.getLogLevel(bundle.get(Keys.LOG_LEVEL), CioLogLevel.DEBUG);
Region region = Region.Companion.getRegion(bundle.get(Keys.REGION), Region.US.INSTANCE);
boolean applicationLifecycleTrackingEnabled = StringUtils.parseBoolean(bundle.get(Keys.TRACK_APPLICATION_LIFECYCLE), defaultConfig.applicationLifecycleTrackingEnabled);
boolean testModeEnabled = StringUtils.parseBoolean(bundle.get(Keys.TEST_MODE_ENABLED), defaultConfig.testModeEnabled);
boolean inAppMessagingEnabled = StringUtils.parseBoolean(bundle.get(Keys.IN_APP_MESSAGING_ENABLED), defaultConfig.inAppMessagingEnabled);

CustomerIOSDKConfig config = new CustomerIOSDKConfig(cdpApiKey,
siteId,
apiHost,
cdnHost,
flushInterval,
flushAt,
screenTrackingEnabled,
deviceAttributesTrackingEnabled,
debugModeEnabled);
logLevel,
region,
applicationLifecycleTrackingEnabled,
testModeEnabled,
inAppMessagingEnabled);
return Optional.of(config);
}

Expand All @@ -78,11 +87,13 @@ public static Map<String, String> toMap(@NonNull CustomerIOSDKConfig config) {
bundle.put(Keys.SITE_ID, config.siteId);
bundle.put(Keys.API_HOST, config.apiHost);
bundle.put(Keys.CDN_HOST, config.cdnHost);
bundle.put(Keys.FLUSH_INTERVAL, StringUtils.fromInteger(config.flushInterval));
bundle.put(Keys.FLUSH_AT, StringUtils.fromInteger(config.flushAt));
bundle.put(Keys.TRACK_SCREENS, StringUtils.fromBoolean(config.screenTrackingEnabled));
bundle.put(Keys.TRACK_DEVICE_ATTRIBUTES, StringUtils.fromBoolean(config.deviceAttributesTrackingEnabled));
bundle.put(Keys.DEBUG_MODE, StringUtils.fromBoolean(config.debugModeEnabled));
bundle.put(Keys.LOG_LEVEL, config.logLevel.name());
bundle.put(Keys.REGION, config.getRegion().getCode());
bundle.put(Keys.TRACK_APPLICATION_LIFECYCLE, StringUtils.fromBoolean(config.applicationLifecycleTrackingEnabled));
bundle.put(Keys.TEST_MODE_ENABLED, StringUtils.fromBoolean(config.testModeEnabled));
bundle.put(Keys.IN_APP_MESSAGING_ENABLED, StringUtils.fromBoolean(config.inAppMessagingEnabled));
return bundle;
}

Expand All @@ -94,35 +105,38 @@ public static Map<String, String> toMap(@NonNull CustomerIOSDKConfig config) {
private final String apiHost;
@Nullable
private final String cdnHost;
@Nullable
private final Integer flushInterval;
@Nullable
private final Integer flushAt;
@Nullable
private final Boolean screenTrackingEnabled;
@Nullable
private final Boolean deviceAttributesTrackingEnabled;
@Nullable
private final Boolean debugModeEnabled;
private final boolean screenTrackingEnabled;
private final boolean deviceAttributesTrackingEnabled;
@NonNull
private final CioLogLevel logLevel;
@NonNull
private final Region region;
private final boolean applicationLifecycleTrackingEnabled;
private final boolean testModeEnabled;
private final boolean inAppMessagingEnabled;

public CustomerIOSDKConfig(@NonNull String cdpApiKey,
@NonNull String siteId,
@Nullable String apiHost,
@Nullable String cdnHost,
@Nullable Integer flushInterval,
@Nullable Integer flushAt,
@Nullable Boolean screenTrackingEnabled,
@Nullable Boolean deviceAttributesTrackingEnabled,
@Nullable Boolean debugModeEnabled) {
boolean screenTrackingEnabled,
boolean deviceAttributesTrackingEnabled,
@NonNull CioLogLevel logLevel,
@NonNull Region region,
boolean applicationLifecycleTrackingEnabled,
boolean testModeEnabled,
boolean inAppMessagingEnabled) {
this.cdpApiKey = cdpApiKey;
this.siteId = siteId;
this.apiHost = apiHost;
this.cdnHost = cdnHost;
this.flushInterval = flushInterval;
this.flushAt = flushAt;
this.screenTrackingEnabled = screenTrackingEnabled;
this.deviceAttributesTrackingEnabled = deviceAttributesTrackingEnabled;
this.debugModeEnabled = debugModeEnabled;
this.logLevel = logLevel;
this.region = region;
this.applicationLifecycleTrackingEnabled = applicationLifecycleTrackingEnabled;
this.testModeEnabled = testModeEnabled;
this.inAppMessagingEnabled = inAppMessagingEnabled;
}

@NonNull
Expand All @@ -145,48 +159,33 @@ public String getCdnHost() {
return cdnHost;
}

@Nullable
public Integer getFlushInterval() {
return flushInterval;
}

@Nullable
public Integer getFlushAt() {
return flushAt;
}


@Nullable
public Boolean isScreenTrackingEnabled() {
public boolean isScreenTrackingEnabled() {
return screenTrackingEnabled;
}

@Nullable
public Boolean isDeviceAttributesTrackingEnabled() {
public boolean isDeviceAttributesTrackingEnabled() {
return deviceAttributesTrackingEnabled;
}

@Nullable
public Boolean isDebugModeEnabled() {
return debugModeEnabled;
@NonNull
public CioLogLevel getLogLevel() {
return logLevel;
}

/**
* Features by default are nullable to help differentiate between default/null values and
* values set by user.
* Unwrapping nullable values here for ease of use by keeping single source of truth for whole
* sample app.
*/
public boolean isTestModeEnabled() {
return testModeEnabled;
}

public boolean screenTrackingEnabled() {
return Boolean.FALSE != screenTrackingEnabled;
public boolean isInAppMessagingEnabled() {
return inAppMessagingEnabled;
}

public boolean deviceAttributesTrackingEnabled() {
return Boolean.FALSE != deviceAttributesTrackingEnabled;
public boolean isApplicationLifecycleTrackingEnabled() {
return applicationLifecycleTrackingEnabled;
}

public boolean debugModeEnabled() {
return Boolean.FALSE != debugModeEnabled;
@NonNull
public Region getRegion() {
return region;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import io.customer.messagingpush.ModuleMessagingPushFCM;
import io.customer.sdk.CustomerIO;
import io.customer.sdk.CustomerIOBuilder;
import io.customer.sdk.core.util.CioLogLevel;
import io.customer.sdk.data.model.Region;

/**
* Repository class to hold all Customer.io related operations at single place
Expand All @@ -31,24 +29,22 @@ public void initializeSdk(SampleApplication application) {
// Initialize Customer.io SDK builder
CustomerIOBuilder builder = new CustomerIOBuilder(application, sdkConfig.getCdpApiKey());

// Enable detailed logging for debug builds.
if (sdkConfig.debugModeEnabled()) {
builder.logLevel(CioLogLevel.DEBUG);
}
// Modify SDK settings for testing purposes only.
// If you don't need to override any of these settings, you can skip this line.
configureSdk(builder, sdkConfig);

// Enable optional features of the SDK by adding desired modules.
// Enables push notification
builder.addCustomerIOModule(new ModuleMessagingPushFCM());
// Enables in-app messages
builder.addCustomerIOModule(new ModuleMessagingInApp(
new MessagingInAppModuleConfig.Builder(sdkConfig.getSiteId(), Region.US.INSTANCE)
.setEventListener(new InAppMessageEventListener(appGraph.getLogger()))
.build()
));

// Modify SDK settings for testing purposes only.
// If you don't need to override any of these settings, you can skip this line.
configureSdk(builder, sdkConfig);
// Enables in-app messages
if (sdkConfig.isInAppMessagingEnabled()) {
builder.addCustomerIOModule(new ModuleMessagingInApp(
new MessagingInAppModuleConfig.Builder(sdkConfig.getSiteId(), sdkConfig.getRegion())
.setEventListener(new InAppMessageEventListener(appGraph.getLogger()))
.build()
));
}

// Finally, build to finish initializing the SDK.
builder.build();
Expand All @@ -72,21 +68,15 @@ private void configureSdk(CustomerIOBuilder builder, final CustomerIOSDKConfig s
builder.cdnHost(cdnHost);
}

if (sdkConfig.getFlushAt() != null) {
builder.flushAt(sdkConfig.getFlushAt());
}
if (sdkConfig.getFlushInterval() != null) {
builder.flushInterval(sdkConfig.getFlushInterval());
if (sdkConfig.isTestModeEnabled()) {
builder.flushAt(1);
}

final Boolean screenTrackingEnabled = sdkConfig.isScreenTrackingEnabled();
if (screenTrackingEnabled != null) {
builder.autoTrackActivityScreens(screenTrackingEnabled);
}
final Boolean deviceAttributesTrackingEnabled = sdkConfig.isDeviceAttributesTrackingEnabled();
if (deviceAttributesTrackingEnabled != null) {
builder.autoTrackDeviceAttributes(deviceAttributesTrackingEnabled);
}
builder.autoTrackActivityScreens(sdkConfig.isScreenTrackingEnabled());
builder.autoTrackDeviceAttributes(sdkConfig.isDeviceAttributesTrackingEnabled());
builder.trackApplicationLifecycleEvents(sdkConfig.isApplicationLifecycleTrackingEnabled());
builder.region(sdkConfig.getRegion());
builder.logLevel(sdkConfig.getLogLevel());
}

public void identify(@NonNull String email, @NonNull Map<String, String> attributes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,13 @@ private static CustomerIOSDKConfig createNewSettings(CustomerIOSDKConfig current
currentSettings.getSiteId(),
apiHost,
cdnHost,
currentSettings.getFlushInterval(),
currentSettings.getFlushAt(),
currentSettings.isScreenTrackingEnabled(),
currentSettings.isDeviceAttributesTrackingEnabled(),
currentSettings.isDebugModeEnabled()
currentSettings.getLogLevel(),
currentSettings.getRegion(),
currentSettings.isApplicationLifecycleTrackingEnabled(),
currentSettings.isTestModeEnabled(),
currentSettings.isInAppMessagingEnabled()
);
}

Expand Down
Loading

0 comments on commit c89791b

Please sign in to comment.