retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory Java Examples
The following examples show how to use
retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DailyFragment.java From Cashew with Apache License 2.0 | 7 votes |
private void getHistoryDate() { mProgressDialog.show(); String baseUrl = "http://gank.io/api/"; Retrofit retrofit = new Retrofit.Builder() .baseUrl(baseUrl) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build(); ApiService apiService = retrofit.create(ApiService.class); apiService.getHistoryDate() .map(new BaseResFunc<List<String>>()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(mObserver); }
Example #2
Source File: RetrofitCircuitBreakerTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Before public void setUp() { this.circuitBreaker = CircuitBreaker.of("test", circuitBreakerConfig); final long TIMEOUT = 150; // ms this.client = new OkHttpClient.Builder() .connectTimeout(TIMEOUT, TimeUnit.MILLISECONDS) .readTimeout(TIMEOUT, TimeUnit.MILLISECONDS) .writeTimeout(TIMEOUT, TimeUnit.MILLISECONDS) .build(); this.service = new Retrofit.Builder() .addCallAdapterFactory(CircuitBreakerCallAdapter.of(circuitBreaker)) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addConverterFactory(ScalarsConverterFactory.create()) .baseUrl(wireMockRule.baseUrl()) .client(client) .build() .create(RetrofitService.class); }
Example #3
Source File: AppModule.java From EosCommander with MIT License | 6 votes |
@Provides @Singleton NodeosApi providesEosService(Gson gson, OkHttpClient okHttpClient, PreferencesHelper preferencesHelper) { RefValue<Integer> portRef = new RefValue<>(0); RefValue<String> schemeRef = new RefValue<>(); String addr = preferencesHelper.getNodeosConnInfo( portRef, schemeRef ); String url = StringUtils.isEmpty( addr ) ? ENDPOINT : ( schemeRef.data + "://"+addr+":"+portRef.data); Retrofit retrofit = new Retrofit.Builder() .baseUrl( url ) .addConverterFactory( GsonConverterFactory.create( gson)) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) // retrofit 용 rxjava2 adapter .client( okHttpClient ) .build(); return retrofit.create( NodeosApi.class); }
Example #4
Source File: PaasClient.java From java-unified-sdk with Apache License 2.0 | 6 votes |
static void initializeGlobalClient() { if (null == apiService) { AppRouter appRouter = AppRouter.getInstance(); appRouter.getEndpoint(AVOSCloud.getApplicationId(), AVOSService.API).subscribe( new Consumer<String>() { @Override public void accept(String apiHost) throws Exception { OkHttpClient okHttpClient = getGlobalOkHttpClient(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(apiHost) .addConverterFactory(FastJsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .client(okHttpClient) .build(); apiService = retrofit.create(APIService.class); storageClient = new StorageClient(apiService, AppConfiguration.isAsynchronized(), AppConfiguration.getDefaultScheduler()); } }); } }
Example #5
Source File: GirlFragment.java From Cashew with Apache License 2.0 | 6 votes |
@Override public void onRefresh() { String baseUrl = "http://gank.io/api/"; Retrofit retrofit = new Retrofit.Builder() .baseUrl(baseUrl) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build(); ApiService apiService = retrofit.create(ApiService.class); apiService.getClassifyData("福利", 1) .map(new BaseResFunc<List<Gank>>()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(mObserver); }
Example #6
Source File: NotificationService.java From Mysplash with GNU Lesser General Public License v3.0 | 6 votes |
public NotificationService(OkHttpClient client, GsonConverterFactory gsonConverterFactory, RxJava2CallAdapterFactory rxJava2CallAdapterFactory, CompositeDisposable disposable) { api = new Retrofit.Builder() .baseUrl(UrlCollection.UNSPLASH_URL) .client( client.newBuilder() .addInterceptor(new NotificationInterceptor()) .build() ).addConverterFactory(gsonConverterFactory) .addCallAdapterFactory(rxJava2CallAdapterFactory) .build() .create((NotificationApi.class)); compositeDisposable = disposable; }
Example #7
Source File: ApiModule.java From AndroidBlueprints with Apache License 2.0 | 6 votes |
@Provides @Singleton MockRetrofit provideRetrofit(GsonConverterFactory gson, OkHttpClient okHttpClient) { NetworkBehavior behavior = NetworkBehavior.create(); behavior.setDelay(1, TimeUnit.SECONDS); behavior.setVariancePercent(40); behavior.setErrorPercent(2); Retrofit retrofit = new Retrofit.Builder() .baseUrl(BuildConfig.API_URL) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addCallAdapterFactory(LiveDataCallAdapterFactory.create()) .client(okHttpClient) .build(); return new MockRetrofit.Builder(retrofit) .networkBehavior(behavior) .build(); }
Example #8
Source File: RetrofitClient.java From MvpRoute with Apache License 2.0 | 6 votes |
/** * init Retrofit * * @param config */ private RetrofitClient(RetrofitConfig config) { errorResponse = config.getiResponseErrorMsg(); loadingView = config.getLoadingView(); iRefreshToken = config.getiRefreshToken(); if (config.getGsonClass() == null) { throw new NullPointerException("gsonClazz is null"); } if (iRefreshToken != null) proxyHandler = new ProxyHandler(iRefreshToken); OkHttpClient.Builder builder = config.getBuilder() == null ? new OkHttpClient.Builder() : config.getBuilder(); // builder.addInterceptor(progressInterceptor()); client = new Retrofit.Builder() .client(builder.build()) .baseUrl(config.getBaseUrl()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create(config.getGsonClass())) .build(); }
Example #9
Source File: AppCoinsAddressProxyBuilder.java From asf-sdk with GNU General Public License v3.0 | 6 votes |
private RemoteRepository.Api provideApi(int chainId) { String baseHost; switch (chainId) { case 3: baseHost = BuildConfig.ROPSTEN_NETWORK_BACKEND_BASE_HOST; break; default: baseHost = BuildConfig.MAIN_NETWORK_BACKEND_BASE_HOST; break; } return new Retrofit.Builder().baseUrl(baseHost) .client(new OkHttpClient.Builder().build()) .addConverterFactory(JacksonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build() .create(RemoteRepository.Api.class); }
Example #10
Source File: DownloadManager.java From AndroidQuick with MIT License | 6 votes |
public DownloadManager(String url, DownloadProgressListener listener) { DownloadProgressInterceptor interceptor = new DownloadProgressInterceptor(listener); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor) .retryOnConnectionFailure(true) .connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS) .build(); retrofit = new Retrofit.Builder() .baseUrl(url) .client(client) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build(); }
Example #11
Source File: GhostApiUtils.java From quill with MIT License | 6 votes |
public static Retrofit getRetrofit(@NonNull String blogUrl, @NonNull OkHttpClient httpClient) { String baseUrl = NetworkUtils.makeAbsoluteUrl(blogUrl, "ghost/api/v0.1/"); Gson gson = new GsonBuilder() .registerTypeAdapter(Date.class, new DateDeserializer()) .registerTypeAdapter(ConfigurationList.class, new ConfigurationListDeserializer()) .registerTypeAdapterFactory(new PostTypeAdapterFactory()) .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .setExclusionStrategies(new RealmExclusionStrategy(), new AnnotationExclusionStrategy()) .create(); return new Retrofit.Builder() .baseUrl(baseUrl) .client(httpClient) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) // for HTML output (e.g., to get the client secret) .addConverterFactory(StringConverterFactory.create()) // for raw JSONObject output (e.g., for the /configuration/about call) .addConverterFactory(JSONObjectConverterFactory.create()) // for domain objects .addConverterFactory(GsonConverterFactory.create(gson)) .build(); }
Example #12
Source File: SwapiModule.java From okuki with Apache License 2.0 | 6 votes |
@Inject public SwapiModule(OkHttpClient okHttpClient, Moshi moshi) { final Retrofit swapiRetrofit = new Retrofit.Builder().baseUrl(Swapi.BASE_URL) .client(okHttpClient) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addConverterFactory(MoshiConverterFactory.create(moshi)) .build(); bind(Swapi.class).toInstance(swapiRetrofit.create(Swapi.class)); final Retrofit searchRetrofit = new Retrofit.Builder().baseUrl(CustomSearch.BASE_URL) .client(okHttpClient) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addConverterFactory(MoshiConverterFactory.create(moshi)) .build(); bind(CustomSearch.class).toInstance(searchRetrofit.create(CustomSearch.class)); bind(SwapiListDataManager.class).singletonInScope(); }
Example #13
Source File: ClassifyListFragment.java From Cashew with Apache License 2.0 | 6 votes |
@Override public void onRefresh() { String baseUrl = "http://gank.io/api/"; Retrofit retrofit = new Retrofit.Builder() .baseUrl(baseUrl) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build(); ApiService apiService = retrofit.create(ApiService.class); apiService.getClassifyData(mType, 1) .map(new BaseResFunc<List<Gank>>()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(mObserver); }
Example #14
Source File: FollowService.java From Mysplash with GNU Lesser General Public License v3.0 | 6 votes |
public FollowService(OkHttpClient client, GsonConverterFactory gsonConverterFactory, RxJava2CallAdapterFactory rxJava2CallAdapterFactory, CompositeDisposable disposable) { api = new Retrofit.Builder() .baseUrl(UrlCollection.UNSPLASH_URL) .client( client.newBuilder() .addInterceptor(new AuthInterceptor()) .addInterceptor(new NapiInterceptor()) .build() ).addConverterFactory(gsonConverterFactory) .addCallAdapterFactory(rxJava2CallAdapterFactory) .build() .create((FollowApi.class)); compositeDisposable = disposable; }
Example #15
Source File: RemotePresenterImpl.java From DanDanPlayForAndroid with MIT License | 6 votes |
private RetrofitService getRetrofitService(String ip, int port, String authorization){ String newUrl = "http://" + ip + ":" + port + "/"; if (newUrl.equals(baseUrl) && retrofitService != null){ return retrofitService; } baseUrl = newUrl; retrofitService = null; retrofitService = new Retrofit.Builder() .baseUrl(baseUrl) .addConverterFactory(GsonConverterFactory.create(GsonFactory.buildGson())) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .client(getOkHttpClient(authorization)) .build() .create(RetrofitService.class); return retrofitService; }
Example #16
Source File: AllocineApi.java From Android-Allocine-Api with Apache License 2.0 | 5 votes |
public AllocineApi(OkHttpClient okHttpClient) { allocineService = new Retrofit.Builder() .baseUrl(AllocineService.URL) .client(okHttpClient) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build() .create(AllocineService.class); }
Example #17
Source File: UpWalletTickerService.java From Upchain-wallet with GNU Affero General Public License v3.0 | 5 votes |
private void buildApiClient(String baseUrl) { apiClient = new Retrofit.Builder() .baseUrl(baseUrl + "/") .client(httpClient) .addConverterFactory(GsonConverterFactory.create(gson)) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build() .create(ApiClient.class); }
Example #18
Source File: BaseModelImpl.java From MyBookshelf with GNU General Public License v3.0 | 5 votes |
public Retrofit getRetrofitString(String url) { return new Retrofit.Builder().baseUrl(url) //增加返回值为字符串的支持(以实体类返回) .addConverterFactory(EncodeConverter.create()) //增加返回值为Observable<T>的支持 .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .client(getClient()) .build(); }
Example #19
Source File: AboutActivityModule.java From Ency with Apache License 2.0 | 5 votes |
@BingURL @Provides @ActivityScope Retrofit provideBingRetrofit(Retrofit.Builder builder, OkHttpClient client) { return builder .baseUrl(BingApi.HOST) .client(client) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build(); }
Example #20
Source File: NetworkModule.java From JReadHub with GNU General Public License v3.0 | 5 votes |
private Retrofit createRetrofit(Retrofit.Builder builder, OkHttpClient okHttpClient, String url) { return builder .baseUrl(url) .client(okHttpClient) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) .build(); }
Example #21
Source File: RetrofitHelper.java From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 | 5 votes |
public static RetrofitService getDefault() { return new Retrofit.Builder() .baseUrl(URL_NGA_BASE_CC) .addConverterFactory(JsonStringConvertFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build() .create(RetrofitService.class); }
Example #22
Source File: GirlFragment.java From Cashew with Apache License 2.0 | 5 votes |
public void loadMore(int currentPage) { String baseUrl = "http://gank.io/api/"; Retrofit retrofit = new Retrofit.Builder() .baseUrl(baseUrl) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build(); ApiService apiService = retrofit.create(ApiService.class); apiService.getClassifyData("福利", currentPage) .map(new BaseResFunc<List<Gank>>()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(mLoadMoreObserver); }
Example #23
Source File: BaseNet.java From AFBaseLibrary with Apache License 2.0 | 5 votes |
/** * 默认使用rxjava call adapter,和{@link BaseNetService}结合使用,可避免rx引起的内存泄漏问题 */ protected CallAdapter.Factory getDefaultCallAdapterFactory() { if (rxJavaCallAdapterFactory == null) { rxJavaCallAdapterFactory = RxJava2CallAdapterFactory.create(); } return rxJavaCallAdapterFactory; }
Example #24
Source File: RetrofitFactory.java From Yuan-SxMusic with Apache License 2.0 | 5 votes |
private synchronized static Retrofit getRetrofit() { if (sRetrofit == null) { sRetrofit = new Retrofit.Builder() .baseUrl(Api.FIDDLER_BASE_QQ_URL) // 对应服务端的host .client(getOkHttpClient()) .addConverterFactory(GsonConverterFactory.create(new GsonBuilder().setLenient().create())) // 这里还结合了Gson .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) // 把Retrofit请求转化成RxJava的Observable .build(); } return sRetrofit; }
Example #25
Source File: MainActivityModule.java From Ency with Apache License 2.0 | 5 votes |
@WeatherURL @Provides @ActivityScope Retrofit provideWeatherRetrofit(Retrofit.Builder builder, OkHttpClient client) { return builder .baseUrl(WeatherApi.HOST) .client(client) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build(); }
Example #26
Source File: XApi.java From XDroid-Databinding with MIT License | 5 votes |
public Retrofit getRetrofit(String baseUrl, OkHttpClient okHttpClient) { if (baseUrl == null || baseUrl.trim().isEmpty()) { throw new IllegalStateException("baseUrl can not be null"); } Retrofit.Builder builder = new Retrofit.Builder() .baseUrl(baseUrl) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) // 添加Rx适配器 .addConverterFactory(StringConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) // 添加gson转换器 .client(okHttpClient); Retrofit retrofit = builder.build(); return retrofit; }
Example #27
Source File: MainActivity.java From journaldev with MIT License | 5 votes |
private void setupRetrofitAndOkHttp() { HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(); httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); File httpCacheDirectory = new File(getCacheDir(), "offlineCache"); //10 MB Cache cache = new Cache(httpCacheDirectory, 10 * 1024 * 1024); OkHttpClient httpClient = new OkHttpClient.Builder() .cache(cache) .addInterceptor(httpLoggingInterceptor) .addNetworkInterceptor(provideCacheInterceptor()) .addInterceptor(provideOfflineCacheInterceptor()) .build(); Retrofit retrofit = new Retrofit.Builder() .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create(new Gson())) .client(httpClient) .baseUrl(BASE_URL) .build(); apiService = retrofit.create(APIService.class); }
Example #28
Source File: MainActivity.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
private void createGithubAPI() { Gson gson = new GsonBuilder() .setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ") .registerTypeAdapter(GithubRepo.class, new GithubRepoDeserializer()) .create(); OkHttpClient okHttpClient = new OkHttpClient.Builder() .addInterceptor(new Interceptor() { @Override public okhttp3.Response intercept(Chain chain) throws IOException { Request originalRequest = chain.request(); Request.Builder builder = originalRequest.newBuilder().header("Authorization", Credentials.basic(username, password)); Request newRequest = builder.build(); return chain.proceed(newRequest); } }).build(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(GithubAPI.ENDPOINT) .client(okHttpClient) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create(gson)) .build(); githubAPI = retrofit.create(GithubAPI.class); }
Example #29
Source File: ServiceGenerator.java From XposedSmsCode with GNU General Public License v3.0 | 5 votes |
public <T> T createService(String baseUrl, Class<T> serviceClass) { Retrofit retrofit = mRetrofitMap.get(baseUrl); if (retrofit == null) { retrofit = new Retrofit.Builder() .baseUrl(baseUrl) .client(mOkHttpClient) .addConverterFactory(ScalarsConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build(); mRetrofitMap.put(baseUrl, retrofit); } return retrofit.create(serviceClass); }
Example #30
Source File: MainActivity.java From journaldev with MIT License | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); recyclerView = findViewById(R.id.recyclerView); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerViewAdapter = new RecyclerViewAdapter(); recyclerView.setAdapter(recyclerViewAdapter); HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build(); Gson gson = new GsonBuilder() .setLenient() .create(); retrofit = new Retrofit.Builder() .baseUrl(BASE_URL) .client(client) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create(gson)) .build(); callEndpoints(); }