Last active
September 4, 2018 20:24
-
-
Save adrianhall/f5acd51b27dc66daae681675c6f1b5ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Where the preferences are stored on the system | |
*/ | |
private val preferencesFile: String | |
get() = "${this::class.java.simpleName}.prefs" | |
/** | |
* The name of the custom attribute | |
*/ | |
private val categoriesAttributeName = "categories" | |
/** | |
* The shared preferences area object | |
*/ | |
private var prefs: SharedPreferences = context.getSharedPreferences(preferencesFile, 0) | |
init { | |
// Read the current categories list, if present | |
val categories = prefs.getStringSet(categoriesAttributeName, emptySet()) | |
if (categories.size > 0) { | |
val endpoint = pinpoint.targetingClient.currentEndpoint() | |
endpoint.addAttribute(categoriesAttributeName, categories.toList()) | |
pinpoint.targetingClient.updateEndpointProfile(endpoint) | |
} | |
pinpoint.sessionClient.startSession() | |
pinpoint.analyticsClient.submitEvents() | |
} | |
/** | |
* Update the categories within the endpoint profile | |
*/ | |
override fun updateCategories(categories: List<String>) { | |
prefs.edit().putStringSet(categoriesAttributeName, categories.toSet()).apply() | |
val endpoint = pinpoint.targetingClient.currentEndpoint() | |
endpoint.addAttribute(categoriesAttributeName, categories) | |
pinpoint.targetingClient.updateEndpointProfile(endpoint) | |
recordEvent("_endpoint.updateCategories") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment