Skip to content

Commit

Permalink
chore: screen view usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mrehan27 committed Dec 13, 2024
1 parent 550e220 commit f3629e3
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
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 @@ -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
42 changes: 41 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,46 @@
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: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 +282,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 settings</string>
<string name="screen_view_use_settings_analytics">Analytics</string>
<string name="screen_view_use_settings_in_app">InApp</string>

</resources>

0 comments on commit f3629e3

Please sign in to comment.