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

chore: update java sample app with screen view configuration #475

Merged
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 @@ -11,6 +11,7 @@
import io.customer.android.sample.java_layout.BuildConfig;
import io.customer.android.sample.java_layout.support.Optional;
import io.customer.android.sample.java_layout.utils.StringUtils;
import io.customer.datapipelines.config.ScreenView;
import io.customer.datapipelines.extensions.RegionExtKt;
import io.customer.sdk.core.util.CioLogLevel;
import io.customer.sdk.data.model.Region;
Expand All @@ -28,6 +29,7 @@ private static class Keys {
static final String TRACK_DEVICE_ATTRIBUTES = "cio_sdk_track_device_attributes";
static final String LOG_LEVEL = "cio_sdk_log_level";
static final String REGION = "cio_sdk_region";
static final String SCREEN_VIEW_USE = "cio_sdk_screen_view_use";
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";
Expand All @@ -42,6 +44,7 @@ public static CustomerIOSDKConfig getDefaultConfigurations() {
true,
CioLogLevel.DEBUG,
Region.US.INSTANCE,
ScreenView.Analytics,
true,
false,
true);
Expand All @@ -62,6 +65,7 @@ public static Optional<CustomerIOSDKConfig> fromMap(@NonNull Map<String, String>
boolean deviceAttributesTrackingEnabled = StringUtils.parseBoolean(bundle.get(Keys.TRACK_DEVICE_ATTRIBUTES), defaultConfig.deviceAttributesTrackingEnabled);
CioLogLevel logLevel = CioLogLevel.Companion.getLogLevel(bundle.get(Keys.LOG_LEVEL), CioLogLevel.DEBUG);
Region region = Region.Companion.getRegion(bundle.get(Keys.REGION), Region.US.INSTANCE);
ScreenView screenViewUse = ScreenView.Companion.getScreenView(bundle.get(Keys.SCREEN_VIEW_USE));
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);
Expand All @@ -74,6 +78,7 @@ public static Optional<CustomerIOSDKConfig> fromMap(@NonNull Map<String, String>
deviceAttributesTrackingEnabled,
logLevel,
region,
screenViewUse,
applicationLifecycleTrackingEnabled,
testModeEnabled,
inAppMessagingEnabled);
Expand All @@ -91,6 +96,7 @@ public static Map<String, String> toMap(@NonNull CustomerIOSDKConfig config) {
bundle.put(Keys.TRACK_DEVICE_ATTRIBUTES, StringUtils.fromBoolean(config.deviceAttributesTrackingEnabled));
bundle.put(Keys.LOG_LEVEL, config.logLevel.name());
bundle.put(Keys.REGION, config.getRegion().getCode());
bundle.put(Keys.SCREEN_VIEW_USE, config.getScreenViewUse().name());
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));
Expand All @@ -111,6 +117,7 @@ public static Map<String, String> toMap(@NonNull CustomerIOSDKConfig config) {
private final CioLogLevel logLevel;
@NonNull
private final Region region;
private final ScreenView screenViewUse;
private final boolean applicationLifecycleTrackingEnabled;
private final boolean testModeEnabled;
private final boolean inAppMessagingEnabled;
Expand All @@ -123,6 +130,7 @@ public CustomerIOSDKConfig(@NonNull String cdpApiKey,
boolean deviceAttributesTrackingEnabled,
@NonNull CioLogLevel logLevel,
@NonNull Region region,
@NonNull ScreenView screenViewUse,
boolean applicationLifecycleTrackingEnabled,
boolean testModeEnabled,
boolean inAppMessagingEnabled) {
Expand All @@ -134,6 +142,7 @@ public CustomerIOSDKConfig(@NonNull String cdpApiKey,
this.deviceAttributesTrackingEnabled = deviceAttributesTrackingEnabled;
this.logLevel = logLevel;
this.region = region;
this.screenViewUse = screenViewUse;
this.applicationLifecycleTrackingEnabled = applicationLifecycleTrackingEnabled;
this.testModeEnabled = testModeEnabled;
this.inAppMessagingEnabled = inAppMessagingEnabled;
Expand Down Expand Up @@ -188,4 +197,9 @@ public boolean isApplicationLifecycleTrackingEnabled() {
public Region getRegion() {
return region;
}

@NonNull
public ScreenView getScreenViewUse() {
return screenViewUse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private void configureSdk(CustomerIOBuilder builder, final CustomerIOSDKConfig s
builder.trackApplicationLifecycleEvents(sdkConfig.isApplicationLifecycleTrackingEnabled());
builder.region(sdkConfig.getRegion());
builder.logLevel(sdkConfig.getLogLevel());
builder.screenViewUse(sdkConfig.getScreenViewUse());
}

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 @@ -137,6 +137,7 @@ private static CustomerIOSDKConfig createNewSettings(CustomerIOSDKConfig current
currentSettings.isDeviceAttributesTrackingEnabled(),
currentSettings.getLogLevel(),
currentSettings.getRegion(),
currentSettings.getScreenViewUse(),
currentSettings.isApplicationLifecycleTrackingEnabled(),
currentSettings.isTestModeEnabled(),
currentSettings.isInAppMessagingEnabled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.customer.android.sample.java_layout.ui.dashboard.DashboardActivity;
import io.customer.android.sample.java_layout.utils.OSUtils;
import io.customer.android.sample.java_layout.utils.ViewUtils;
import io.customer.datapipelines.config.ScreenView;
import io.customer.sdk.core.util.CioLogLevel;
import io.customer.sdk.data.model.Region;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
Expand Down Expand Up @@ -128,6 +129,7 @@ private void updateIOWithConfig(@NonNull CustomerIOSDKConfig config) {
binding.settingsTrackDeviceAttrsValuesGroup.check(getCheckedAutoTrackDeviceAttributesButtonId(config.isDeviceAttributesTrackingEnabled()));
binding.settingsTrackScreenViewsValuesGroup.check(getCheckedTrackScreenViewsButtonId(config.isScreenTrackingEnabled()));
binding.settingsTrackAppLifecycleValuesGroup.check(getCheckedTrackAppLifecycleButtonId(config.isApplicationLifecycleTrackingEnabled()));
binding.screenViewUseSettingsValuesGroup.check(getCheckedScreenViewUseButtonId(config.getScreenViewUse()));
binding.settingsLogLevelValuesGroup.check(getCheckedLogLevelButtonId(config.getLogLevel()));
binding.settingsTestModeValuesGroup.check(getCheckedTestModeButtonId(config.isTestModeEnabled()));
binding.settingsInAppMessagingValuesGroup.check(getCheckedInAppMessagingButtonId(config.isInAppMessagingEnabled()));
Expand Down Expand Up @@ -173,6 +175,7 @@ private CustomerIOSDKConfig createNewSettings(String cdpApiKey, String siteId, C
boolean featInAppMessagingEnabled = binding.settingsInAppMessagingValuesGroup.getCheckedButtonId() == R.id.settings_in_app_messaging_yes_button;
CioLogLevel logLevel = getSelectedLogLevel();
Region region = getSelectedRegion();
ScreenView screenViewUse = getSelectedScreenViewUse();

return new CustomerIOSDKConfig(cdpApiKey,
siteId,
Expand All @@ -182,6 +185,7 @@ private CustomerIOSDKConfig createNewSettings(String cdpApiKey, String siteId, C
featTrackDeviceAttributes,
logLevel,
region,
screenViewUse,
featTrackApplicationLifecycle,
featTestModeEnabled,
featInAppMessagingEnabled);
Expand Down Expand Up @@ -213,6 +217,18 @@ private Region getSelectedRegion() {
throw new IllegalStateException();
}


@NonNull
private ScreenView getSelectedScreenViewUse() {
int checkedButton = binding.screenViewUseSettingsValuesGroup.getCheckedButtonId();
if (checkedButton == R.id.settings_screen_view_use_analytics_button) {
return ScreenView.Analytics;
} else if (checkedButton == R.id.settings_screen_view_use_in_app_button) {
return ScreenView.InApp;
}
throw new IllegalStateException();
}

private int getCheckedInAppMessagingButtonId(boolean enabled) {
return enabled ? R.id.settings_in_app_messaging_yes_button : R.id.settings_in_app_messaging_no_button;
}
Expand Down Expand Up @@ -256,6 +272,16 @@ private int getCheckedRegionButtonId(@NonNull Region region) {
: R.id.settings_region_eu_button;
}

private int getCheckedScreenViewUseButtonId(@NonNull ScreenView screenViewUse) {
switch (screenViewUse) {
case InApp:
return R.id.settings_screen_view_use_in_app_button;
case Analytics:
default:
return R.id.settings_screen_view_use_analytics_button;
}
}

private boolean updateErrorState(TextInputLayout textInputLayout,
boolean isErrorEnabled,
@StringRes int errorResId) {
Expand Down
43 changes: 42 additions & 1 deletion samples/java_layout/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,47 @@
android:text="@string/settings_no" />
</com.google.android.material.button.MaterialButtonToggleGroup>

<TextView
android:id="@+id/screen_view_use_settings_label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_default"
android:text="@string/screen_view_use_settings_label"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/settings_track_app_lifecycle_values_group" />

<com.google.android.material.button.MaterialButtonToggleGroup
android:id="@+id/screen_view_use_settings_values_group"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/screen_view_use_settings_label"
app:selectionRequired="true"
app:singleSelection="true">

<Button
android:id="@+id/settings_screen_view_use_analytics_button"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/screen_view_use_settings_analytics" />

<Button
android:id="@+id/settings_screen_view_use_in_app_button"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/screen_view_use_settings_in_app" />
</com.google.android.material.button.MaterialButtonToggleGroup>

<TextView
android:id="@+id/settings_features_label"
android:layout_width="wrap_content"
Expand All @@ -242,7 +283,7 @@
android:text="@string/features"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/settings_track_app_lifecycle_values_group" />
app:layout_constraintTop_toBottomOf="@+id/screen_view_use_settings_values_group" />

<TextView
android:id="@+id/settings_in_app_messaging_label"
Expand Down
3 changes: 3 additions & 0 deletions samples/java_layout/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,8 @@
<!--Internal settings screen-->
<string name="label_internal_settings_activity">InternalSettingsActivity</string>
<string name="error_url_input_field">This field must be a valid URL</string>
<string name="screen_view_use_settings_label">ScreenView use</string>
<string name="screen_view_use_settings_analytics">Analytics</string>
<string name="screen_view_use_settings_in_app">InApp</string>

</resources>
Loading