Search in sources :

Example 1 with OptimizelyExperimentsClient

use of com.kickstarter.libs.OptimizelyExperimentsClient in project android-oss by kickstarter.

the class ApplicationModule method provideOptimizely.

@Provides
@Singleton
@NonNull
ExperimentsClientType provideOptimizely(@ApplicationContext @NonNull final Context context, @NonNull final ApiEndpoint apiEndpoint, @NonNull final Build build) {
    final OptimizelyEnvironment optimizelyEnvironment;
    if (apiEndpoint == ApiEndpoint.PRODUCTION) {
        optimizelyEnvironment = OptimizelyEnvironment.PRODUCTION;
    } else if (apiEndpoint == ApiEndpoint.STAGING) {
        optimizelyEnvironment = OptimizelyEnvironment.STAGING;
    } else {
        optimizelyEnvironment = OptimizelyEnvironment.DEVELOPMENT;
    }
    final OptimizelyManager optimizelyManager = OptimizelyManager.builder().withSDKKey(optimizelyEnvironment.getSdkKey()).withDatafileDownloadInterval(15, TimeUnit.MINUTES).withEventDispatchInterval(2L, TimeUnit.MILLISECONDS).build(context);
    optimizelyManager.initialize(context, null, optimizely -> {
        if (!optimizely.isValid()) {
            FirebaseCrashlytics.getInstance().recordException(new Throwable("Optimizely failed to initialize."));
        } else {
            if (build.isDebug()) {
                Timber.d(ApplicationModule.class.getSimpleName(), "🔮 Optimizely successfully initialized.");
            }
            context.sendBroadcast(new Intent(ExperimentsClientTypeKt.EXPERIMENTS_CLIENT_READY));
        }
    });
    return new OptimizelyExperimentsClient(optimizelyManager, optimizelyEnvironment);
}
Also used : OptimizelyExperimentsClient(com.kickstarter.libs.OptimizelyExperimentsClient) OptimizelyEnvironment(com.kickstarter.libs.models.OptimizelyEnvironment) Intent(android.content.Intent) OptimizelyManager(com.optimizely.ab.android.sdk.OptimizelyManager) Singleton(javax.inject.Singleton) NonNull(androidx.annotation.NonNull) Provides(dagger.Provides)

Aggregations

Intent (android.content.Intent)1 NonNull (androidx.annotation.NonNull)1 OptimizelyExperimentsClient (com.kickstarter.libs.OptimizelyExperimentsClient)1 OptimizelyEnvironment (com.kickstarter.libs.models.OptimizelyEnvironment)1 OptimizelyManager (com.optimizely.ab.android.sdk.OptimizelyManager)1 Provides (dagger.Provides)1 Singleton (javax.inject.Singleton)1