|
@@ -38,8 +38,8 @@ open class BRRepository : BRepository() {
|
|
* */
|
|
* */
|
|
|
|
|
|
private suspend fun <T : IResp<*>> reqList(
|
|
private suspend fun <T : IResp<*>> reqList(
|
|
- pageLoading: Boolean = true,
|
|
|
|
- func: suspend () -> T
|
|
|
|
|
|
+ pageLoading: Boolean = true,
|
|
|
|
+ func: suspend () -> T
|
|
): T {
|
|
): T {
|
|
|
|
|
|
try {
|
|
try {
|
|
@@ -58,21 +58,26 @@ open class BRRepository : BRepository() {
|
|
view().refreshing(false)
|
|
view().refreshing(false)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- bView.toLogin()
|
|
|
|
- // bView.processCodeOffline()
|
|
|
|
|
|
+ if(resp.isLogin()==-1) {
|
|
|
|
+ bView.toLogin()
|
|
|
|
+ }
|
|
|
|
+ // bView.processCodeOffline()
|
|
} else {
|
|
} else {
|
|
|
|
|
|
if (page <= 1) {
|
|
if (page <= 1) {
|
|
- if (resp.empty()) {
|
|
|
|
|
|
+ if (resp.empty()) { //如果没有数据
|
|
|
|
|
|
view().loadService?.showCallback(EmptyCallback::class.java)
|
|
view().loadService?.showCallback(EmptyCallback::class.java)
|
|
|
|
|
|
- } else {
|
|
|
|
- if (resp is PageResp<*>) {
|
|
|
|
|
|
+// if (pageLoading) {//列表还未有数据
|
|
|
|
+//
|
|
|
|
+// view().loadService?.showCallback(EmptyCallback::class.java)
|
|
|
|
+// }
|
|
|
|
|
|
|
|
|
|
|
|
+ } else {
|
|
|
|
+ if (resp is PageResp<*>) {
|
|
view().adapter().setList(resp.data()?.records as Collection<Nothing>)
|
|
view().adapter().setList(resp.data()?.records as Collection<Nothing>)
|
|
-
|
|
|
|
} else {
|
|
} else {
|
|
view().adapter().setList(resp.data() as Collection<Nothing>)
|
|
view().adapter().setList(resp.data() as Collection<Nothing>)
|
|
}
|
|
}
|
|
@@ -110,7 +115,7 @@ open class BRRepository : BRepository() {
|
|
} catch (e: Exception) {
|
|
} catch (e: Exception) {
|
|
e.printStackTrace()
|
|
e.printStackTrace()
|
|
|
|
|
|
- Log.e("shy", "e=: " + e)
|
|
|
|
|
|
+ Log.e("shy", "e=: "+e )
|
|
when {
|
|
when {
|
|
pageLoading -> {
|
|
pageLoading -> {
|
|
bView.loadService?.showCallback(TimeoutCallback::class.java)
|
|
bView.loadService?.showCallback(TimeoutCallback::class.java)
|
|
@@ -131,8 +136,8 @@ open class BRRepository : BRepository() {
|
|
|
|
|
|
|
|
|
|
return Resp<Any>(
|
|
return Resp<Any>(
|
|
- NetCode.CODE_EXCEPTION,
|
|
|
|
- message = ExceptionUtils.getExceptionName(e)
|
|
|
|
|
|
+ NetCode.CODE_EXCEPTION,
|
|
|
|
+ message = ExceptionUtils.getExceptionName(e)
|
|
) as T
|
|
) as T
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -150,8 +155,8 @@ open class BRRepository : BRepository() {
|
|
|
|
|
|
|
|
|
|
fun rxReqFirstPage(
|
|
fun rxReqFirstPage(
|
|
- api: Observable<IResp<Collection<Any>>>,
|
|
|
|
- pagable: Boolean
|
|
|
|
|
|
+ api: Observable<IResp<Collection<Any>>>,
|
|
|
|
+ pagable: Boolean
|
|
): Observable<IResp<Collection<Any>>> {
|
|
): Observable<IResp<Collection<Any>>> {
|
|
this.api = api;
|
|
this.api = api;
|
|
page = 1
|
|
page = 1
|
|
@@ -170,50 +175,50 @@ open class BRRepository : BRepository() {
|
|
|
|
|
|
@SuppressLint("CheckResult")
|
|
@SuppressLint("CheckResult")
|
|
fun rxReqList(
|
|
fun rxReqList(
|
|
- observable: Observable<IResp<Collection<Any>>>,
|
|
|
|
- pageLoading: Boolean
|
|
|
|
|
|
+ observable: Observable<IResp<Collection<Any>>>,
|
|
|
|
+ pageLoading: Boolean
|
|
): Observable<IResp<Collection<Any>>> {
|
|
): Observable<IResp<Collection<Any>>> {
|
|
return Observable.create { emitter: ObservableEmitter<IResp<Collection<Any>>> ->
|
|
return Observable.create { emitter: ObservableEmitter<IResp<Collection<Any>>> ->
|
|
rxReq(observable, pageLoading, false)
|
|
rxReq(observable, pageLoading, false)
|
|
- .doOnError { throwable: Throwable ->
|
|
|
|
- throwable.printStackTrace()
|
|
|
|
- if (page >= 1) {
|
|
|
|
- view().adapter().loadMoreModule.loadMoreFail()
|
|
|
|
- page -= 1
|
|
|
|
- }
|
|
|
|
- emitter.onError(throwable)
|
|
|
|
|
|
+ .doOnError { throwable: Throwable ->
|
|
|
|
+ throwable.printStackTrace()
|
|
|
|
+ if (page >= 1) {
|
|
|
|
+ view().adapter().loadMoreModule.loadMoreFail()
|
|
|
|
+ page -= 1
|
|
}
|
|
}
|
|
- .subscribe({ res: IResp<Collection<Any>> ->
|
|
|
|
- view().onListReceive(res)
|
|
|
|
- if (page <= 1) {
|
|
|
|
- if (res.empty()) { //如果没有数据
|
|
|
|
- view().refreshing(false)
|
|
|
|
- view().loadService!!.showCallback(EmptyCallback::class.java)
|
|
|
|
- } else {
|
|
|
|
- view().refreshing(false)
|
|
|
|
- //Object data = res.data();
|
|
|
|
|
|
+ emitter.onError(throwable)
|
|
|
|
+ }
|
|
|
|
+ .subscribe({ res: IResp<Collection<Any>> ->
|
|
|
|
+ view().onListReceive(res)
|
|
|
|
+ if (page <= 1) {
|
|
|
|
+ if (res.empty()) { //如果没有数据
|
|
|
|
+ view().refreshing(false)
|
|
|
|
+ view().loadService!!.showCallback(EmptyCallback::class.java)
|
|
|
|
+ } else {
|
|
|
|
+ view().refreshing(false)
|
|
|
|
+ //Object data = res.data();
|
|
// if (data instanceof IResultList) {
|
|
// if (data instanceof IResultList) {
|
|
// adapter.setList(((IResultList) data).list());
|
|
// adapter.setList(((IResultList) data).list());
|
|
// }
|
|
// }
|
|
- view().adapter().setList(res.data() as Collection<Nothing>)
|
|
|
|
- view().loadService!!.showSuccess()
|
|
|
|
- }
|
|
|
|
- view().getTotal(res.total())
|
|
|
|
- } else {
|
|
|
|
|
|
+ view().adapter().setList(res.data() as Collection<Nothing>)
|
|
|
|
+ view().loadService!!.showSuccess()
|
|
|
|
+ }
|
|
|
|
+ view().getTotal(res.total())
|
|
|
|
+ } else {
|
|
// Object data = res.data();
|
|
// Object data = res.data();
|
|
// if (data instanceof IResultList) {
|
|
// if (data instanceof IResultList) {
|
|
// view().getAdapter().addData((((IResultList) data).list()));
|
|
// view().getAdapter().addData((((IResultList) data).list()));
|
|
// }
|
|
// }
|
|
- view().adapter().addData(res.data() as Collection<Nothing>)
|
|
|
|
- }
|
|
|
|
- if (res.more(page)) {
|
|
|
|
- view().adapter().loadMoreModule.loadMoreComplete()
|
|
|
|
- } else {
|
|
|
|
- //数据全部加载完毕
|
|
|
|
- view().adapter().loadMoreModule.loadMoreEnd()
|
|
|
|
- }
|
|
|
|
- emitter.onNext(res)
|
|
|
|
- }, { throwable: Throwable? -> }) { emitter.onComplete() }
|
|
|
|
|
|
+ view().adapter().addData(res.data() as Collection<Nothing>)
|
|
|
|
+ }
|
|
|
|
+ if (res.more(page)) {
|
|
|
|
+ view().adapter().loadMoreModule.loadMoreComplete()
|
|
|
|
+ } else {
|
|
|
|
+ //数据全部加载完毕
|
|
|
|
+ view().adapter().loadMoreModule.loadMoreEnd()
|
|
|
|
+ }
|
|
|
|
+ emitter.onNext(res)
|
|
|
|
+ }, { throwable: Throwable? -> }) { emitter.onComplete() }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -221,4 +226,8 @@ open class BRRepository : BRepository() {
|
|
page += 1
|
|
page += 1
|
|
return page
|
|
return page
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|