Skip to content

Commit

Permalink
完善demo
Browse files Browse the repository at this point in the history
  • Loading branch information
lygttpod committed Mar 24, 2019
1 parent 9e61367 commit 1d9a95d
Show file tree
Hide file tree
Showing 14 changed files with 447 additions and 912 deletions.
75 changes: 34 additions & 41 deletions app/src/main/java/com/allen/rxhttputils/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.allen.library.config.OkHttpConfig;
import com.allen.library.cookie.store.SPCookieStore;
import com.allen.library.interfaces.BuildHeadersListener;
import com.allen.library.manage.RxUrlManager;
import com.allen.rxhttputils.url.AppUrlConfig;

import java.net.URLEncoder;
import java.util.HashMap;
Expand All @@ -27,32 +29,49 @@ public class App extends Application {
@Override
public void onCreate() {
super.onCreate();

// initRxHttpUtils();
initCustomRxHttpUtils();

initRxHttpUtils();
}


/**
* 快速上手,默认配置
* 全局请求的统一配置(以下配置根据自身情况选择性的配置即可)
*/
private void initRxHttpUtils() {

//一个项目多url的配置方法
RxUrlManager.getInstance().setMultipleUrl(AppUrlConfig.getAllUrl());

RxHttpUtils
.getInstance()
.init(this)
.config()
//自定义factory的用法
//.setCallAdapterFactory(RxJava2CallAdapterFactory.create())
//.setConverterFactory(ScalarsConverterFactory.create(),GsonConverterFactory.create(GsonAdapter.buildGson()))
//配置全局baseUrl
.setBaseUrl("https://api.douban.com/");
}
.setBaseUrl("https://www.wanandroid.com/")
//开启全局配置
.setOkClient(createOkHttp());

// TODO: 2018/5/31 如果以上OkHttpClient的配置满足不了你,传入自己的 OkHttpClient 自行设置
// OkHttpClient.Builder builder = new OkHttpClient.Builder();
//
// builder
// .addInterceptor(log_interceptor)
// .readTimeout(10, TimeUnit.SECONDS)
// .writeTimeout(10, TimeUnit.SECONDS)
// .connectTimeout(10, TimeUnit.SECONDS);
//
// RxHttpUtils
// .getInstance()
// .init(this)
// .config()
// .setBaseUrl(BuildConfig.BASE_URL)
// .setOkClient(builder.build());

/**
* 全局请求的统一配置(以下配置根据自身情况选择性的配置即可)
*/
private void initCustomRxHttpUtils() {
}

// 获取证书
private OkHttpClient createOkHttp() {
// 获取证书
// InputStream cerInputStream = null;
// InputStream bksInputStream = null;
// try {
Expand Down Expand Up @@ -102,36 +121,10 @@ public Map<String, String> buildHeaders() {
//全局超时配置
.setConnectTimeout(10)
//全局是否打开请求log日志
.setDebug(true)
.setDebug(BuildConfig.DEBUG)
.build();

RxHttpUtils
.getInstance()
.init(this)
.config()
//自定义factory的用法
//.setCallAdapterFactory(RxJava2CallAdapterFactory.create())
//.setConverterFactory(ScalarsConverterFactory.create(),GsonConverterFactory.create(GsonAdapter.buildGson()))
//配置全局baseUrl
.setBaseUrl("https://api.douban.com/")
//开启全局配置
.setOkClient(okHttpClient);

// TODO: 2018/5/31 如果以上OkHttpClient的配置满足不了你,传入自己的 OkHttpClient 自行设置
// OkHttpClient.Builder builder = new OkHttpClient.Builder();
//
// builder
// .addInterceptor(log_interceptor)
// .readTimeout(10, TimeUnit.SECONDS)
// .writeTimeout(10, TimeUnit.SECONDS)
// .connectTimeout(10, TimeUnit.SECONDS);
//
// RxHttpUtils
// .getInstance()
// .init(this)
// .config()
// .setBaseUrl(BuildConfig.BASE_URL)
// .setOkClient(builder.build());
return okHttpClient;
}


Expand Down
Loading

0 comments on commit 1d9a95d

Please sign in to comment.