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.
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
Overview
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
Overview
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
Overview
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
Overview
The getConversationCounters
method retrieves conversation counters (e.g., comment and reply counts) for a list of post IDs.
Parameters
- postIds: A list of
OWPostId
values representing the posts to fetch counters for. - callback: A
SpotCallback
that returns a map ofOWPostId
toConversationCounters
.
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
}
})
Additional Configurations
Overview
The setAdditionalConfigurations
method allows you to pass custom configurations to the SDK.
Parameters
- configuration: One or more
AdditionalConfiguration
objects 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
)
Updated 1 day ago