use of javax.inject.Singleton in project sqlbrite by square.
the class DbModule method provideDatabase.
@Provides
@Singleton
BriteDatabase provideDatabase(SqlBrite sqlBrite, Application application) {
Configuration configuration = Configuration.builder(application).name("todo.db").callback(new DbCallback()).build();
Factory factory = new FrameworkSQLiteOpenHelperFactory();
SupportSQLiteOpenHelper helper = factory.create(configuration);
BriteDatabase db = sqlBrite.wrapDatabaseHelper(helper, Schedulers.io());
db.setLoggingEnabled(true);
return db;
}
use of javax.inject.Singleton in project MVPArms by JessYanCoding.
the class ClientModule method provideClient.
/**
* 提供 {@link OkHttpClient}
*
* @param application {@link Application}
* @param configuration {@link OkhttpConfiguration}
* @param builder {@link OkHttpClient.Builder}
* @param intercept {@link Interceptor}
* @param interceptors {@link List<Interceptor>}
* @param handler {@link GlobalHttpHandler}
* @param executorService {@link ExecutorService}
* @return {@link OkHttpClient}
*/
@Singleton
@Provides
static OkHttpClient provideClient(Application application, @Nullable OkhttpConfiguration configuration, OkHttpClient.Builder builder, Interceptor intercept, @Nullable List<Interceptor> interceptors, @Nullable GlobalHttpHandler handler, ExecutorService executorService) {
builder.connectTimeout(TIME_OUT, TimeUnit.SECONDS).readTimeout(TIME_OUT, TimeUnit.SECONDS).addNetworkInterceptor(intercept);
if (handler != null) {
builder.addInterceptor(chain -> chain.proceed(handler.onHttpRequestBefore(chain, chain.request())));
}
// 如果外部提供了 Interceptor 的集合则遍历添加
if (interceptors != null) {
for (Interceptor interceptor : interceptors) {
builder.addInterceptor(interceptor);
}
}
// 为 OkHttp 设置默认的线程池
builder.dispatcher(new Dispatcher(executorService));
if (configuration != null) {
configuration.configOkhttp(application, builder);
}
return builder.build();
}
use of javax.inject.Singleton in project MVPArms by JessYanCoding.
the class ClientModule method provideRxCache.
/**
* 提供 {@link RxCache}
*
* @param application {@link Application}
* @param configuration {@link RxCacheConfiguration}
* @param cacheDirectory RxCache 缓存路径
* @param gson {@link Gson}
* @return {@link RxCache}
*/
@Singleton
@Provides
static RxCache provideRxCache(Application application, @Nullable RxCacheConfiguration configuration, @Named("RxCacheDirectory") File cacheDirectory, Gson gson) {
RxCache.Builder builder = new RxCache.Builder();
RxCache rxCache = null;
if (configuration != null) {
rxCache = configuration.configRxCache(application, builder);
}
if (rxCache != null) {
return rxCache;
}
return builder.persistence(cacheDirectory, new GsonSpeaker(gson));
}
use of javax.inject.Singleton in project philm by chrisbanes.
the class NetworkProvider method provideTraktClient.
@Provides
@Singleton
public Trakt provideTraktClient(@CacheDirectory File cacheLocation) {
Trakt trakt = new PhilmTrakt(cacheLocation);
trakt.setApiKey(Constants.TRAKT_API_KEY);
trakt.setIsDebug(Constants.DEBUG_NETWORK);
return trakt;
}
use of javax.inject.Singleton in project android-oss by kickstarter.
the class ApplicationModule method provideHttpLoggingInterceptor.
@Provides
@Singleton
@NonNull
static HttpLoggingInterceptor provideHttpLoggingInterceptor() {
final HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
return interceptor;
}
Aggregations