Skip to content

Commit

Permalink
[MBL-1135] Add analytics value for session_force_dark_mode (#1930)
Browse files Browse the repository at this point in the history
* add session value for force_dark_mode

* add test and value for new session property
  • Loading branch information
mtgriego committed Jan 16, 2024
1 parent a20e8f9 commit 6c857bd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/src/main/java/com/kickstarter/libs/TrackingClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,17 @@ abstract class TrackingClient(
cm.getNetworkCapabilities(it)?.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)
} ?: false
}

override fun sessionForceDarkMode(): Boolean {
return if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
when (context.resources?.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK)) {
Configuration.UI_MODE_NIGHT_YES -> {
true
}
else -> false
}
} else {
false
}
}
}
2 changes: 2 additions & 0 deletions app/src/main/java/com/kickstarter/libs/TrackingClientType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ abstract class TrackingClientType {
protected abstract fun userCountry(user: User): String
protected abstract fun versionName(): String
protected abstract fun wifiConnection(): Boolean
protected abstract fun sessionForceDarkMode(): Boolean

abstract fun track(eventName: String, additionalProperties: Map<String, Any>)
abstract fun identify(u: User)
Expand Down Expand Up @@ -91,6 +92,7 @@ abstract class TrackingClientType {
this["user_agent"] = userAgent() ?: ""
this["user_is_logged_in"] = userIsLoggedIn
this["wifi_connection"] = wifiConnection()
this["force_dark_mode"] = sessionForceDarkMode()
}

return MapUtils.prefixKeys(properties, "session_")
Expand Down
4 changes: 4 additions & 0 deletions app/src/test/java/com/kickstarter/libs/MockTrackingClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ class MockTrackingClient(
return false
}

override fun sessionForceDarkMode(): Boolean {
return false
}

companion object {
private val DEFAULT_TIME = DateTime.parse("2018-11-02T18:42:05Z").millis / 1000
}
Expand Down
1 change: 1 addition & 0 deletions app/src/test/java/com/kickstarter/libs/SegmentTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,7 @@ class SegmentTest : KSRobolectricTestCase() {
assertEquals(user != null, expectedProperties["session_user_is_logged_in"])
assertEquals(false, expectedProperties["session_wifi_connection"])
assertEquals("android_example_experiment[control]", (expectedProperties["session_variants_internal"] as Array<*>).first())
assertEquals(false, expectedProperties["session_force_dark_mode"])
}

private fun assertUserProperties(isAdmin: Boolean) {
Expand Down

0 comments on commit 6c857bd

Please sign in to comment.