Skip to content

Commit 9ac535d

Browse files
author
Vens Chen
committed
update readme
1 parent c6b2382 commit 9ac535d

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
该框架使用retrofit2.0+rxAndroid进行封装,该框架主要特性:
44

55
> * 统一管理网络请求接口
6+
> * 灵活的线程切换
67
> * 支持请求结果的自定义数据结构
78
> * 统一的异常拦截处理,对特殊异常也可以单独处理
89
> * 支持文件带进度下载
9-
> * 支持自定义网络拦截器(log输出,头部参数处理等)
10+
> * 支持自定义拦截器(log输出,头部参数处理等)
1011
> * 提供请求等待的加载动画入口
1112
1213

@@ -120,29 +121,30 @@ public class HttpInterceptor implements Interceptor {
120121

121122
### 初始化
122123
```
123-
RetrofitManager.getInstence()
124-
.baseUrl("your baseurl")
124+
RetrofitManager.getInstence()
125+
.baseUrl("your baseUrl")
125126
.addInterceptor(new HttpInterceptor())
127+
.serviceClass(ApiService.class)
126128
.create();
127129
```
128130

129131
### 业务请求
130132
具体的业务请求类继承HttpPresenter,传入一些配置参数:
131133
```
132134
public class DocPresenter extends HttpPresenter {
133-
private ApiService mApi;
135+
private ApiService mApiService;
134136
public DocPresenter(ILoadingView iLoadingView)
135137
{
136138
super(iLoadingView);
137-
mApi = RetrofitManager.getInstence().getRetrofitService(ApiService.class);
139+
mApiService = (ApiService)RetrofitManager.getInstence().getRetrofitService();
138140
}
139141
140142
/**
141143
* 网络请求的具体实现
142144
*/
143145
public void getDoc()
144146
{
145-
Observable observable = mApi.getDoc(1,4);//调用接口
147+
Observable observable = mApiService.getDoc(1,4);//调用接口
146148
subscribeHttp(observable, new IHttpResultListener<String>() {
147149
@Override
148150
public void onSuccess(String s)
@@ -216,7 +218,7 @@ DocPresenter docPresenter = new DocPresenter(new ILoadingView() {
216218
{
217219
218220
}
219-
}, "your baseUrl");
221+
});
220222
presenter.setFileDir(FileUtil.ROOT_PATH);
221223
presenter.setDestFileName(FileUtil.NAME);
222224
presenter.download("http://upload.cbg.cn/2016/0726/1469533389366.jpg");

app/src/main/java/com/threetree/thttp/MainActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ public void success()
9494
mIv.setImageBitmap(BitmapFactory.decodeFile(FileUtil.getFilePath()));
9595
mDownLoadPresenter.destroy();
9696
}
97-
}, "http://upload.cbg.cn/2016/0726/1469533389366.jpg");
97+
});
9898
}
9999
mDownLoadPresenter.setFileDir(FileUtil.ROOT_PATH);
100100
mDownLoadPresenter.setDestFileName(FileUtil.NAME);
101-
mDownLoadPresenter.download();
101+
mDownLoadPresenter.download("http://upload.cbg.cn/2016/0726/1469533389366.jpg");
102102
}
103103
}

tthttp/src/main/java/com/threetree/tthttp/presenter/DownLoadPresenter.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public class DownLoadPresenter extends HttpPresenter {
4040
private RetrofitService mRetrofitService;
4141
private PresenterHandler mHandler = new PresenterHandler(this);
4242

43-
private String mBaseUrl;
4443

4544
public static class PresenterHandler extends Handler {
4645
private WeakReference<DownLoadPresenter> mInstance;
@@ -67,17 +66,10 @@ public void handleMessage(Message msg)
6766
}
6867
}
6968

70-
public DownLoadPresenter(IProgressView iProgressView, String url)
69+
public DownLoadPresenter(IProgressView iProgressView)
7170
{
7271
super(iProgressView);
7372
this.iProgressView = iProgressView;
74-
mBaseUrl = url;
75-
76-
//我们下载一般使用全路径,而retrofit 必须要传baseurl
77-
//而且要按格式,否则报错,所以这里处理一下
78-
HttpUrl httpUrl = HttpUrl.parse(url);
79-
String newUrl = httpUrl.scheme() + "://" + httpUrl.host();
80-
mRetrofitService = getRetrofit(newUrl).create(RetrofitService.class);
8173
}
8274

8375
private Retrofit getRetrofit(String baseUrl)
@@ -135,17 +127,24 @@ public void destroy()
135127
/**
136128
* 下载
137129
*/
138-
public void download()
130+
public void download(String url)
139131
{
140-
if(TextUtils.isEmpty(mBaseUrl))
132+
if(TextUtils.isEmpty(url))
141133
throw new NullPointerException("url must not be null!");
142134
if(TextUtils.isEmpty(destFileDir))
143135
throw new NullPointerException("FileDir must not be null!");
144136
if(TextUtils.isEmpty(destFileName))
145137
throw new NullPointerException("FileName must not be null!");
146138
if(iProgressView.isActive())
147139
iProgressView.start();
148-
Observable observable = mRetrofitService.downloadFile(mBaseUrl);
140+
141+
//我们下载一般使用全路径,而retrofit 必须要传baseurl
142+
//而且要按格式,否则报错,所以这里处理一下
143+
HttpUrl httpUrl = HttpUrl.parse(url);
144+
String newUrl = httpUrl.scheme() + "://" + httpUrl.host();
145+
mRetrofitService = getRetrofit(newUrl).create(RetrofitService.class);
146+
147+
Observable observable = mRetrofitService.downloadFile(url);
149148
subscribeHttp(observable, new IHttpResultListener<ResponseBody>() {
150149
@Override
151150
public void onSuccess(ResponseBody responseBody)

0 commit comments

Comments
 (0)