For #6836 - Limit Leanplum depending on current locale.
parent
9f30a7e6eb
commit
6d44ceceda
|
@ -10,8 +10,10 @@ import com.leanplum.Leanplum
|
||||||
import com.leanplum.LeanplumActivityHelper
|
import com.leanplum.LeanplumActivityHelper
|
||||||
import com.leanplum.annotations.Parser
|
import com.leanplum.annotations.Parser
|
||||||
import com.leanplum.internal.LeanplumInternal
|
import com.leanplum.internal.LeanplumInternal
|
||||||
|
import mozilla.components.support.locale.LocaleManager
|
||||||
import org.mozilla.fenix.BuildConfig
|
import org.mozilla.fenix.BuildConfig
|
||||||
import org.mozilla.fenix.ext.settings
|
import org.mozilla.fenix.ext.settings
|
||||||
|
import java.util.Locale
|
||||||
import java.util.UUID.randomUUID
|
import java.util.UUID.randomUUID
|
||||||
|
|
||||||
private val Event.name: String?
|
private val Event.name: String?
|
||||||
|
@ -54,6 +56,16 @@ class LeanplumMetricsService(private val application: Application) : MetricsServ
|
||||||
private val token = Token(LeanplumId, LeanplumToken)
|
private val token = Token(LeanplumId, LeanplumToken)
|
||||||
|
|
||||||
override fun start() {
|
override fun start() {
|
||||||
|
val applicationSetLocale = LocaleManager.getCurrentLocale(application)
|
||||||
|
val currentLocale = when (applicationSetLocale != null) {
|
||||||
|
true -> applicationSetLocale.isO3Language
|
||||||
|
false -> Locale.getDefault().isO3Language
|
||||||
|
}
|
||||||
|
if (!isLeanplumEnabled(currentLocale)) {
|
||||||
|
Log.i(LOGTAG, "Leanplum is not available for this locale: $currentLocale")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
when (token.type) {
|
when (token.type) {
|
||||||
Token.Type.Production -> Leanplum.setAppIdForProductionMode(token.id, token.token)
|
Token.Type.Production -> Leanplum.setAppIdForProductionMode(token.id, token.token)
|
||||||
Token.Type.Development -> Leanplum.setAppIdForDevelopmentMode(token.id, token.token)
|
Token.Type.Development -> Leanplum.setAppIdForDevelopmentMode(token.id, token.token)
|
||||||
|
@ -112,6 +124,10 @@ class LeanplumMetricsService(private val application: Application) : MetricsServ
|
||||||
token.type != Token.Type.Invalid && !event.name.isNullOrEmpty()
|
token.type != Token.Type.Invalid && !event.name.isNullOrEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isLeanplumEnabled(locale: String): Boolean {
|
||||||
|
return LEANPLUM_ENABLED_LOCALES.contains(locale)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val LOGTAG = "LeanplumMetricsService"
|
private const val LOGTAG = "LeanplumMetricsService"
|
||||||
|
|
||||||
|
@ -121,5 +137,24 @@ class LeanplumMetricsService(private val application: Application) : MetricsServ
|
||||||
private val LeanplumToken: String
|
private val LeanplumToken: String
|
||||||
// Debug builds have a null (nullable) LEANPLUM_TOKEN
|
// Debug builds have a null (nullable) LEANPLUM_TOKEN
|
||||||
get() = BuildConfig.LEANPLUM_TOKEN.orEmpty()
|
get() = BuildConfig.LEANPLUM_TOKEN.orEmpty()
|
||||||
|
// Leanplum needs to be enabled for the following locales.
|
||||||
|
// Irrespective of the actual device location.
|
||||||
|
private val LEANPLUM_ENABLED_LOCALES = listOf(
|
||||||
|
"eng", // English
|
||||||
|
"zho", // Chinese
|
||||||
|
"deu", // German
|
||||||
|
"fra", // French
|
||||||
|
"ita", // Italian
|
||||||
|
"ind", // Indonesian
|
||||||
|
"por", // Portuguese
|
||||||
|
"spa", // Spanish; Castilian
|
||||||
|
"pol", // Polish
|
||||||
|
"rus", // Russian
|
||||||
|
"hin", // Hindi
|
||||||
|
"per", // Persian
|
||||||
|
"fas", // Persian
|
||||||
|
"ara", // Arabic
|
||||||
|
"jpn" // Japanese
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue