Helpers
The Helpers section provides essential utility classes and configurations for customizing and optimizing your integration with the OpenWeb Android SDK.
These helpers allow you to tailor the experience to match your app's requirements, including logging, localization, and more.
OWHelpers Interface
The OWHelpers interface offers various tools and configurations to enhance the SDK's functionality, including:
- loggerConfiguration: Configures the logging behavior of the SDK.
- languageStrategy: Defines the strategy for setting the language used within the SDK.
- localeStrategy: Manages locale-specific behavior.
- orientationEnforcement: Controls orientation settings within the SDK.
- getConversationCounters(postIds: List**, callback: SpotCallback<Map<OWPostId, ConversationCounters>>)**: Fetches the conversation counters (comments, replies) for a list of post IDs.
- setAdditionalConfigurations(vararg configuration: AdditionalConfiguration): Sets additional configurations for the SDK.
- getRoutingData(intent: Intent): Extracts
OWRoutingDatafrom a push-notification tap intent. See Push Notifications for the full flow.
Logger Configuration
The OWLoggerConfiguration allows you to manage the logging behavior of the SDK, including setting log levels and logging methods.
Example:
val helpers = OpenWeb.manager.helpers
// Set logger configuration
helpers.loggerConfiguration.apply {
level = OWLogLevel.DEBUG
methods = listOf(OWLogMethod.Logcat)
}Language Strategy
The languageStrategy property lets you define how the SDK determines the language used within its components. This can help align the SDK's language with your app's language settings.
Strategy Types
- Device: Uses the device's current language settings.
- Custom: Allows you to specify a custom language.
- ServerConfig: Uses the language configuration provided by the server.
Supported Languages
| Language | Code |
|---|---|
| English | en |
| Arabic | ar |
| Dutch | nl |
| French | fr |
| German | de |
| Hebrew | he |
| Hungarian | hu |
| Indonesian | id |
| Italian | it |
| Japanese | ja |
| Korean | ko |
| Portuguese | pt |
| Spanish | es |
| Thai | th |
| Turkish | tr |
| Vietnamese | vi |
Example:
val helpers = OpenWeb.manager.helpers
// Set a custom language strategy
helpers.languageStrategy = OWLanguageStrategy.Custom(
language = OWSupportedLanguage.English
)Locale Strategy
The localeStrategy property allows you to define locale-specific behavior for the SDK. This can be used to adapt the SDK to regional preferences.
Strategy Types
- Device: Uses the device's current locale settings.
- Custom: Allows you to specify a custom locale.
- ServerConfig: Uses the locale configuration provided by the server.
Example:
val helpers = OpenWeb.manager.helpers
// Set a custom locale strategy
helpers.localeStrategy = OWLocaleStrategy.Custom(
locale = Locale.US
)Orientation Enforcement
The orientationEnforcement property lets you enforce specific screen orientations for the SDK's components. This is useful for ensuring a consistent user experience.
Enforcement Types
- EnableAll: Allows all orientations.
- Enable: Restricts to a specific orientation, e.g., portrait or landscape.
Example:
val helpers = OpenWeb.manager.helpers
// Set orientation enforcement
helpers.orientationEnforcement = OWOrientationEnforcement.Enable(
orientation = OWOrientation.PORTRAIT
)Fetching Conversation Counters
The getConversationCounters method retrieves conversation counters (e.g., comment and reply counts) for a list of post IDs.
Parameters
- postIds: A list of
OWPostIdvalues representing the posts to fetch counters for. - callback: A
SpotCallbackthat returns a map ofOWPostIdtoConversationCounters.
Example:
val helpers = OpenWeb.manager.helpers
// Fetch conversation counters
helpers.getConversationCounters(listOf("postId1", "postId2"), object : SpotCallback<Map<OWPostId, ConversationCounters>> {
override fun onSuccess(result: Map<OWPostId, ConversationCounters>) {
// Handle success
}
override fun onFailure(exception: SpotException) {
// Handle failure
}
})Notification Routing Data
The getRoutingData method extracts routing information from an Intent delivered by a push-notification tap, so you can open the conversation the notification refers to.
Parameters
- intent: The
Intentyour activity received (inonCreateoronNewIntent).
Returns an OWRoutingData (postId and an OWConversationRoute), or null if the intent did not originate from an OpenWeb notification.
Example:
val helpers = OpenWeb.manager.helpers
val routingData = helpers.getRoutingData(intent) ?: return
// routingData.postId, routingData.routeNote: For the complete notification-handling flow — configuring the tap intent and forwarding the route into OWUIComponents — see Push Notifications.
Additional Configurations
The setAdditionalConfigurations method allows you to pass custom configurations to the SDK.
Parameters
- configuration: One or more
AdditionalConfigurationobjects to apply.
Available Options
| Property | Description |
|---|---|
SUPPRESS_FINMB_FILTER | Suppresses specific filters applied by the SDK. |
USE_ENCRYPTED_SHARED_PREFERENCES | Enables the use of encrypted shared preferences for storing data securely. |
Example:
val helpers = OpenWeb.manager.helpers
// Set additional configurations
helpers.setAdditionalConfigurations(
AdditionalConfiguration.SUPPRESS_FINMB_FILTER,
AdditionalConfiguration.USE_ENCRYPTED_SHARED_PREFERENCES
)