use of com.optimizely.ab.android.shared.Cache in project android-sdk by optimizely.
the class DatafileRescheduler method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
if ((context != null && intent != null) && (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED) || intent.getAction().equals(Intent.ACTION_MY_PACKAGE_REPLACED))) {
logger.info("Received intent with action {}", intent.getAction());
BackgroundWatchersCache backgroundWatchersCache = new BackgroundWatchersCache(new Cache(context, LoggerFactory.getLogger(Cache.class)), LoggerFactory.getLogger(BackgroundWatchersCache.class));
Dispatcher dispatcher = new Dispatcher(context, backgroundWatchersCache, LoggerFactory.getLogger(Dispatcher.class));
dispatcher.dispatch();
} else {
logger.warn("Received invalid broadcast to data file rescheduler");
}
}
use of com.optimizely.ab.android.shared.Cache in project android-sdk by optimizely.
the class DefaultDatafileHandler method enableBackgroundCache.
private void enableBackgroundCache(Context context, DatafileConfig datafileConfig) {
BackgroundWatchersCache backgroundWatchersCache = new BackgroundWatchersCache(new Cache(context, LoggerFactory.getLogger(Cache.class)), LoggerFactory.getLogger(BackgroundWatchersCache.class));
backgroundWatchersCache.setIsWatching(datafileConfig, true);
}
use of com.optimizely.ab.android.shared.Cache in project android-sdk by optimizely.
the class DefaultDatafileHandler method loadSavedDatafile.
/**
* Load a cached datafile if it exists.
*
* @param context application context
* @param datafileConfig DatafileConfig for the datafile
* @return the datafile cached or null if it was not available
*/
public String loadSavedDatafile(Context context, DatafileConfig datafileConfig) {
DatafileCache datafileCache = new DatafileCache(datafileConfig.getKey(), new Cache(context, LoggerFactory.getLogger(Cache.class)), LoggerFactory.getLogger(DatafileCache.class));
JSONObject datafile = datafileCache.load();
if (datafile != null) {
return datafile.toString();
}
return null;
}
use of com.optimizely.ab.android.shared.Cache in project android-sdk by optimizely.
the class DefaultDatafileHandler method clearBackgroundCache.
private void clearBackgroundCache(Context context, DatafileConfig projectId) {
BackgroundWatchersCache backgroundWatchersCache = new BackgroundWatchersCache(new Cache(context, LoggerFactory.getLogger(Cache.class)), LoggerFactory.getLogger(BackgroundWatchersCache.class));
backgroundWatchersCache.setIsWatching(projectId, false);
}
use of com.optimizely.ab.android.shared.Cache in project android-sdk by optimizely.
the class DefaultDatafileHandler method downloadDatafile.
/**
* Asynchronous download data file.
* <p>
* We create a DatafileService intent, create a DataService connection, and bind it to the application context.
* After we receive the datafile, we unbind the service and cleanup the service connection.
* This gets the project file from the Optimizely CDN.
*
* @param context application context
* @param datafileConfig DatafileConfig for the datafile to get
* @param listener listener to call when datafile download complete
*/
public void downloadDatafile(final Context context, DatafileConfig datafileConfig, final DatafileLoadedListener listener) {
DatafileClient datafileClient = new DatafileClient(new Client(new OptlyStorage(context.getApplicationContext()), LoggerFactory.getLogger(OptlyStorage.class)), LoggerFactory.getLogger(DatafileClient.class));
DatafileCache datafileCache = new DatafileCache(datafileConfig.getKey(), new Cache(context, LoggerFactory.getLogger(Cache.class)), LoggerFactory.getLogger(DatafileCache.class));
String datafileUrl = datafileConfig.getUrl();
DatafileLoader datafileLoader = new DatafileLoader(context, datafileClient, datafileCache, LoggerFactory.getLogger(DatafileLoader.class));
datafileLoader.getDatafile(datafileUrl, new DatafileLoadedListener() {
@Override
public void onDatafileLoaded(@Nullable String dataFile) {
if (listener != null) {
listener.onDatafileLoaded(dataFile);
}
}
});
}
Aggregations