Skip to content

Commit 459ebb1

Browse files
committed
1.0.8
1 parent 4a281e3 commit 459ebb1

File tree

4 files changed

+176
-18
lines changed

4 files changed

+176
-18
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
/.idea/
44
/gradle.properties
55
/gradlew
6-
/build.gradle
76
/gradlew.bat
87
gradle/
98
.gradle/

README.md

+171-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
###MVCHelper主要用于下拉刷新加载,失败,加载,空数据,成功的界面切换。
2+
MVCHelper +(IDataSource或ITask)+ IDataAdapter + 下拉刷新控件 + 布局切换(ILoadViewFactory,ILoadView,ILoadMoreView)
23

3-
###TaskHelper主要用于执行多个任务,通过回调ICallback更新UI
4+
###TaskHelper主要用于没有布局切换和刷新控件的MVC架构,可以执行多个任务通过回调ICallback更新UI
5+
TaskHelper+(ITask或IDataSource)+ ICallBack
46

5-
Download Library [JAR](https://github.com/LuckyJayce/MVCHelper/releases/download/1.0.7/LuckyJayce_MVCHelper_1.0.7.zip)
67
Download sample [Apk](https://github.com/LuckyJayce/MVCHelper/blob/master/raw/MVCHelper_Demo.apk?raw=true)
78

89
###历史版本和更新信息
@@ -12,43 +13,43 @@ https://github.com/LuckyJayce/MVCHelper/releases
1213
## 1.必须导入: ##
1314

1415
//MVCHelper核心类库
15-
compile 'com.shizhefei:MVCHelper-Library:1.0.7'
16+
compile 'com.shizhefei:MVCHelper-Library:1.0.8'
1617
//里面有使用recyclerview,所以需要导入recyclerview
1718
compile 'com.android.support:recyclerview-v7:24.0.0'
1819

1920
## 2.可选: ##
2021
<1> 使用 https://github.com/chrisbanes/Android-PullToRefresh 的刷新控件导入
2122

2223
//里面包含一个MVCPullrefshHelper 是适配这个控件的 MVCHelper
23-
compile 'com.shizhefei:MVCHelper-Pullrefresh:1.0.7'
24+
compile 'com.shizhefei:MVCHelper-Pullrefresh:1.0.8'
2425
//由于没有找到gradle排至,我自己把它上传到jcenter上
2526
compile 'com.shizhefei:pulltorefresh:1.0.1'
2627

2728
<2> 使用 https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh 的刷新控件导入
2829

2930
//里面包含一个MVCUltraHelper 是适配这个控件的 MVCHelper
30-
compile 'com.shizhefei:MVCHelper-UltraRefresh:1.0.7'
31+
compile 'com.shizhefei:MVCHelper-UltraRefresh:1.0.8'
3132
//这里6月29号目前最新的,要实时关注新版本去秋大的网站上去看
3233
compile 'in.srain.cube:ultra-ptr:1.0.11'
3334

3435
<3> 使用android v4的SwipeRefreshLayout的作为刷新控件导入
3536

3637
//里面包含一个MVCSwipeRefreshHelper 是适配这个控件的 MVCHelper
37-
compile 'com.shizhefei:MVCHelper-SwipeRefresh:1.0.7'
38+
compile 'com.shizhefei:MVCHelper-SwipeRefresh:1.0.8'
3839
//v4包应该都有导入吧,v7包里面包含v4包
3940
compile 'com.android.support:support-v4:24.0.0'
4041

4142
<4> 测试用例,可以方便的查看MVCHelper,Task的运行情况和返回数据,还提供了修改接口字段,用于接口测试很方便哦
4243

4344
//MVCHelper的测试用例,继承ABSTestCaseFragment实现List<TestCaseData> getTestCaseDatas()方法
44-
compile 'com.shizhefei:MVCHelper-TestCase:1.0.7'
45+
compile 'com.shizhefei:MVCHelper-TestCase:1.0.8'
4546
//里面用到了gson
4647
compile 'com.google.code.gson:gson:2.2.4'
4748

4849
<5> MVCHelper-OkHttp 对OKHttp的简单封装
4950

5051
//MVCHelper的 OKHttp的简单封装
51-
compile 'com.shizhefei:MVCHelper-OkHttp:1.0.7'
52+
compile 'com.shizhefei:MVCHelper-OkHttp:1.0.8'
5253
//里面用到了okhttp3
5354
compile 'com.squareup.okhttp3:okhttp:3.4.0'
5455
compile 'com.squareup.okio:okio:1.9.0'
@@ -63,9 +64,11 @@ https://github.com/LuckyJayce/MVCHelper/releases
6364
MVCHelper. 实现下拉刷新,滚动底部自动加载更多,分页加载,自动切换显示网络失败布局,暂无数据布局,,真正的MVC架构.
6465

6566
## 1.Model (IDataSource<DATA>)数据源,加载数据
66-
**同步请求实现IDataSource,异步请求(okhttp,volley)实现IAsyncDataSource**
67+
**同步请求实现IDataSource,异步请求(okhttp,volley,rxjava+retrofit)实现IAsyncDataSource**
68+
69+
**<1>同步请求(直接返回结果)**
6770

68-
//数据源
71+
//数据源
6972

7073
public interface IDataSource<DATA> {
7174
// 获取刷新的数据
@@ -77,6 +80,7 @@ MVCHelper. 实现下拉刷新,滚动底部自动加载更多,分页加载,
7780
// 是否还可以继续加载更多
7881
public boolean hasMore();
7982
}
83+
8084
例如:分页加载书籍列表数据
8185

8286
public class BooksDataSource implements IDataSource<List<Book>> {
@@ -109,9 +113,164 @@ MVCHelper. 实现下拉刷新,滚动底部自动加载更多,分页加载,
109113

110114
}
111115

112-
详细写法请看
116+
**<2>异步请求(就是请求等待回调函数返回结果)**
117+
118+
/**
119+
* 异步数据源(比如Volley,OkHttp等异步请求使用)
120+
* @param <DATA>
121+
*/
122+
public interface IAsyncDataSource<DATA> {
123+
/**
124+
* 获取刷新的数据
125+
*
126+
* @param sender 用于请求结束时发送数据给MVCHelper,MVCHelper再通知IDataAdapter调用notifyDataChenge方法
127+
* @return 用于提供外部取消请求的处理.比如执行refresh还没请求结束又执行refresh,就会通过上次的RequestHandle取消上次的请求.MVCHelper的destroy也会用这个取消请求
128+
* @throws Exception
129+
*/
130+
RequestHandle refresh(ResponseSender<DATA> sender) throws Exception;
131+
132+
/**
133+
* 获取加载更多的数据
134+
*
135+
* @param sender 用于请求结束时发送数据给MVCHelper,MVCHelper再通知IDataAdapter调用notifyDataChenge方法
136+
* @return 用于提供外部取消请求的处理.比如执行refresh还没请求结束又执行refresh,就会通过上次的RequestHandle取消上次的请求.MVCHelper的destroy也会用这个取消请求
137+
* @throws Exception
138+
*/
139+
RequestHandle loadMore(ResponseSender<DATA> sender) throws Exception;
140+
141+
/**
142+
* 是否还可以继续加载更多
143+
*
144+
* @return
145+
*/
146+
boolean hasMore();
147+
148+
}
149+
150+
例如:OkHttp请求
151+
152+
public class BooksOkHttpNormal_DataSource implements IAsyncDataSource<List<Book>> {
153+
private int mPage;
154+
private int mMaxPage = 5;
155+
156+
public BooksOkHttpNormal_DataSource() {
157+
super();
158+
}
159+
160+
@Override
161+
public RequestHandle refresh(ResponseSender<List<Book>> sender) throws Exception {
162+
return loadBooks(sender, 1);
163+
}
164+
165+
@Override
166+
public RequestHandle loadMore(ResponseSender<List<Book>> sender) throws Exception {
167+
return loadBooks(sender, mPage + 1);
168+
}
169+
170+
@Override
171+
public boolean hasMore() {
172+
return mPage < mMaxPage;
173+
}
174+
175+
private RequestHandle loadBooks(final ResponseSender<List<Book>> sender, final int page) throws Exception {
176+
Request request = new Request.Builder().url("https://www.baidu.com").get().build();
177+
Call call = OkHttpUtils.client.newCall(request);
178+
call.enqueue(new Callback() {
179+
180+
@Override
181+
public void onFailure(Call call, IOException e) {
182+
//send 要放在最后一句(请求结束)
183+
sender.sendError(e);
184+
}
185+
186+
@Override
187+
public void onResponse(Call call, Response response) throws IOException {
188+
final List<Book> books = new ArrayList<Book>();
189+
for (int i = 0; i < 15; i++) {
190+
books.add(new Book("page" + page + " Java编程思想 " + i, 108.00d));
191+
}
192+
mPage = page;
193+
194+
//send 要放在最后一句(请求结束)
195+
sender.sendData(books);
196+
}
197+
});
198+
return new OKHttpRequestHandle(call);
199+
}
200+
}
201+
202+
public class OKHttpRequestHandle implements RequestHandle {
203+
204+
private final Call call;
205+
206+
public OKHttpRequestHandle(Call call) {
207+
super();
208+
this.call = call;
209+
}
210+
211+
@Override
212+
public void cancle() {
213+
call.cancel();
214+
}
215+
216+
@Override
217+
public boolean isRunning() {
218+
return false;
219+
}
220+
}
221+
222+
例如:使用 MVCHelper-OkHttp
223+
224+
public class BooksOkHttp_AsyncDataSource implements IAsyncDataSource<List<Book>> {
225+
private int mPage;
226+
private int mMaxPage = 5;
227+
228+
@Override
229+
public RequestHandle refresh(ResponseSender<List<Book>> sender) throws Exception {
230+
return loadBooks(sender, 1);
231+
}
232+
233+
@Override
234+
public RequestHandle loadMore(ResponseSender<List<Book>> sender) throws Exception {
235+
return loadBooks(sender, mPage + 1);
236+
}
237+
238+
@Override
239+
public boolean hasMore() {
240+
return mPage < mMaxPage;
241+
}
242+
243+
private RequestHandle loadBooks(final ResponseSender<List<Book>> sender, final int page) throws Exception {
244+
GetMethod method = new GetMethod("https://www.baidu.com");
245+
method.addHeader("a", "aaaaa");
246+
method.addParam("api_key", "75ee6c644cad38dc8e53d3598c8e6b6c");
247+
//method 里面已经封装了sender.sendData 和 sendError的方法,只要关心ResponseParser解析Response返回数据就好
248+
method.executeAsync(sender, new ResponseParser<List<Book>>() {
249+
@Override
250+
public List<Book> parse(Response response) throws Exception {
251+
List<Book> books = new ArrayList<Book>();
252+
for (int i = 0; i < 15; i++) {
253+
books.add(new Book("page" + page + " Java编程思想 " + i, 108.00d));
254+
}
255+
mPage = page;
256+
return books;
257+
}
258+
});
259+
return method;
260+
}
261+
}
262+
263+
264+
**详细写法请看
113265
https://github.com/LuckyJayce/MVCHelper/tree/master/app/src/main/java/com/shizhefei/test/models/datasource
114-
里面有volley,okhttp,rxjava+retrofit等使用方法
266+
里面有
267+
268+
**例子:[volley](https://github.com/LuckyJayce/MVCHelper/tree/master/app/src/main/java/com/shizhefei/test/models/datasource/volley)**
269+
270+
**例子:[okhttp](https://github.com/LuckyJayce/MVCHelper/tree/master/app/src/main/java/com/shizhefei/test/models/datasource/okhttp)**
271+
272+
**例子:[rxjava+retrofit](https://github.com/LuckyJayce/MVCHelper/tree/master/app/src/main/java/com/shizhefei/test/models/datasource/rxjava_retrofit)**
273+
115274
## 2.View(IDataAdapter<DATA>) 视图,显示数据
116275
**这里不是指Android的view,而是显示数据的概念和显示逻辑**
117276

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ allprojects {
1919
}
2020

2121
ext {
22-
VERSION_NAME = '1.0.7'
23-
VERSION_CODE = 8
22+
VERSION_NAME = '1.0.8'
23+
VERSION_CODE = 9
2424
}
2525

2626

mvchelper_library/src/main/java/com/shizhefei/mvc/IAsyncDataSource.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public interface IAsyncDataSource<DATA> {
1212
* @return 用于提供外部取消请求的处理.比如执行refresh还没请求结束又执行refresh,就会通过上次的RequestHandle取消上次的请求.MVCHelper的destroy也会用这个取消请求
1313
* @throws Exception
1414
*/
15-
public RequestHandle refresh(ResponseSender<DATA> sender) throws Exception;
15+
RequestHandle refresh(ResponseSender<DATA> sender) throws Exception;
1616

1717
/**
1818
* 获取加载更多的数据
@@ -21,13 +21,13 @@ public interface IAsyncDataSource<DATA> {
2121
* @return 用于提供外部取消请求的处理.比如执行refresh还没请求结束又执行refresh,就会通过上次的RequestHandle取消上次的请求.MVCHelper的destroy也会用这个取消请求
2222
* @throws Exception
2323
*/
24-
public RequestHandle loadMore(ResponseSender<DATA> sender) throws Exception;
24+
RequestHandle loadMore(ResponseSender<DATA> sender) throws Exception;
2525

2626
/**
2727
* 是否还可以继续加载更多
2828
*
2929
* @return
3030
*/
31-
public boolean hasMore();
31+
boolean hasMore();
3232

3333
}

0 commit comments

Comments
 (0)