From 88380d2ee7a6857c3d9dcae65eacc73f1da3e55d Mon Sep 17 00:00:00 2001 From: liqi Date: Thu, 16 Nov 2017 11:22:13 +0800 Subject: [PATCH 01/11] Support rxjava2 Support rxjava2 --- .../OnSubscribeTimerPeriodically.java | 158 -------------- .../build.gradle | 8 +- .../src/main/AndroidManifest.xml | 0 .../com/liqi/nohttputils/RxNoHttpUtils.java | 0 .../download/DownloadUrlEntity.java | 0 .../nohttputils/download/NohttpDownload.java | 0 .../download/NohttpDownloadConfig.java | 0 .../download/NohttpDownloadUtils.java | 0 .../download/NohttpDownloadWhatAlgorithm.java | 0 .../service/NohttpDownloadService.java | 0 .../interfa/DialogGetListener.java | 0 .../interfa/OnIsRequestListener.java | 0 .../interfa/OnRequestRxNoHttpListener.java | 0 .../liqi/nohttputils/nohttp/BinaryAllObj.java | 0 .../nohttputils/nohttp/BinaryFactory.java | 0 .../liqi/nohttputils/nohttp/NoHttpInit.java | 0 .../nohttputils/nohttp/RequestBeanObj.java | 0 .../com/liqi/nohttputils/nohttp/RxNoHttp.java | 63 ++++-- .../nohttp/RxPollNoHttpConfig.java | 16 +- .../nohttputils/nohttp/RxRequestConfig.java | 0 .../nohttp/RxRequestEntityBase.java | 0 .../nohttp/RxRequestInputStreamEntity.java | 0 .../nohttp/RxRequestJsonListEntity.java | 0 .../nohttp/RxRequestJsonObjectEntity.java | 0 .../nohttputils/nohttp/RxRequestOperate.java | 0 .../nohttp/RxRequestStringEntity.java | 0 .../nohttp/RxThreadInterchange.java | 60 +++-- .../nohttputils/nohttp/RxUtilsConfig.java | 0 .../nohttputils/nohttp/SSLContextUtil.java | 0 .../nohttp/gsonutils/JsonUtil.java | 0 .../OnToInputStreamEntityMethodListener.java | 0 .../OnToJsonListEntityMethodListener.java | 0 .../OnToJsonObjectEntityMethodListener.java | 0 .../OnToStringEntityMethodListener.java | 0 .../nohttp/rx_poll/RxPollUtils.java | 13 +- .../rx_poll/extend/ObservableExpand.java | 40 +--- .../OnRxInformationCancelListener.java | 0 .../interfa/OnRxInformationListListener.java | 0 .../OnRxPollConfigBuilderListener.java | 4 +- .../rx_poll/model/RxInformationModel.java | 0 .../rx_poll/model/RxInformationPoolModel.java | 31 ++- .../operators/OnObserverEventListener.java | 0 .../OnSubscribeTimerPeriodically.java | 206 ++++++++++++++++++ .../rx_poll/pond/RxInformationPool.java | 0 .../nohttp/rx_threadpool/RxMessageSource.java | 0 .../interfa/OnRxMessageGetListener.java | 0 .../interfa/OnRxMessageSetListener.java | 0 .../model/BaseRxRequestModel.java | 14 +- .../rx_threadpool/model/RxRequestModel.java | 0 .../thread/RxThreadDispatch.java | 0 .../utils/RxThreadPoolUtisl.java | 0 .../src/main/res/values/strings.xml | 0 sample/build.gradle | 2 +- .../java/com/liqi/nohttprxutils/PollDemo.java | 38 ++-- settings.gradle | 2 +- 55 files changed, 363 insertions(+), 292 deletions(-) delete mode 100644 nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/operators/OnSubscribeTimerPeriodically.java rename {nohttputils-r1 => nohttputils-r2}/build.gradle (82%) rename {nohttputils-r1 => nohttputils-r2}/src/main/AndroidManifest.xml (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/RxNoHttpUtils.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/download/DownloadUrlEntity.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/download/NohttpDownload.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/download/NohttpDownloadConfig.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/download/NohttpDownloadUtils.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/download/NohttpDownloadWhatAlgorithm.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/download/service/NohttpDownloadService.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/interfa/DialogGetListener.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/interfa/OnIsRequestListener.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/interfa/OnRequestRxNoHttpListener.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/BinaryAllObj.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/BinaryFactory.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/NoHttpInit.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/RequestBeanObj.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/RxNoHttp.java (84%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/RxPollNoHttpConfig.java (88%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/RxRequestConfig.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/RxRequestEntityBase.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/RxRequestInputStreamEntity.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/RxRequestJsonListEntity.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/RxRequestJsonObjectEntity.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/RxRequestOperate.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/RxRequestStringEntity.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/RxThreadInterchange.java (93%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/RxUtilsConfig.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/SSLContextUtil.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/gsonutils/JsonUtil.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/interfa/OnToInputStreamEntityMethodListener.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/interfa/OnToJsonListEntityMethodListener.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/interfa/OnToJsonObjectEntityMethodListener.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/interfa/OnToStringEntityMethodListener.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/RxPollUtils.java (89%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/extend/ObservableExpand.java (63%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/interfa/OnRxInformationCancelListener.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/interfa/OnRxInformationListListener.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/interfa/OnRxPollConfigBuilderListener.java (77%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/model/RxInformationModel.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/model/RxInformationPoolModel.java (91%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/operators/OnObserverEventListener.java (100%) create mode 100644 nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/operators/OnSubscribeTimerPeriodically.java rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/pond/RxInformationPool.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/RxMessageSource.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/interfa/OnRxMessageGetListener.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/interfa/OnRxMessageSetListener.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/model/BaseRxRequestModel.java (80%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/model/RxRequestModel.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/thread/RxThreadDispatch.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/utils/RxThreadPoolUtisl.java (100%) rename {nohttputils-r1 => nohttputils-r2}/src/main/res/values/strings.xml (100%) diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/operators/OnSubscribeTimerPeriodically.java b/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/operators/OnSubscribeTimerPeriodically.java deleted file mode 100644 index db123aa..0000000 --- a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/operators/OnSubscribeTimerPeriodically.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.liqi.nohttputils.nohttp.rx_poll.operators; - -import java.util.concurrent.TimeUnit; - -import rx.Observable; -import rx.Scheduler; -import rx.Subscriber; -import rx.exceptions.Exceptions; -import rx.functions.Action0; -import rx.schedulers.Schedulers; - -/** - * 订阅间隔计时器对象 - * Created by LiQi on 2017/9/6. - */ - -public final class OnSubscribeTimerPeriodically implements Observable.OnSubscribe { - /** - * 初始化加载延迟 - */ - final long initialDelay; - /** - * 轮询间隔时间 - */ - final long period; - /** - * 时间单位 - */ - final TimeUnit unit; - /** - * 订阅者线程线路 - */ - final Scheduler scheduler; - /** - * 可观察者事件监听器 - */ - private OnObserverEventListener eventListener; - /** - * 可观察者线程线路-事件处理默认在子线程 - */ - private Scheduler eventScheduler = Schedulers.io(); - /** - * 传输给被观察者接受的对象 - */ - private V transferValue; - - public OnSubscribeTimerPeriodically(long initialDelay, long period, TimeUnit unit, Scheduler scheduler) { - this.initialDelay = initialDelay; - this.period = period; - this.unit = unit; - this.scheduler = scheduler; - } - - /** - * 赋值传输给被观察者接受的对象 - * - * @param transferValue 被观察者接受的对象 - */ - public void setTransferValue(V transferValue) { - this.transferValue = transferValue; - } - - /** - * 设置事件执行线程线路 - * - * @param eventScheduler 线程线路 - */ - public void setEventScheduler(Scheduler eventScheduler) { - if (null != eventScheduler) { - this.eventScheduler = eventScheduler; - } - } - - /** - * 设置可观察者事件监听器 - * - * @param eventListener 可观察者事件监听器 - */ - public void setOnObserverEventListener(OnObserverEventListener eventListener) { - this.eventListener = eventListener; - } - - @Override - public void call(final Subscriber subscriber) { - //子线程调度器执行 - final Scheduler.Worker worker = Schedulers.io().createWorker(); - subscriber.add(worker); - //开启子线程调度器定时器执行 - worker.schedulePeriodically(new Action0() { - @Override - public void call() { - try { - synchronized (OnSubscribeTimerPeriodically.this) { - //被观察事件处理的调度器 - final Scheduler.Worker workerEvent = eventScheduler.createWorker(); - workerEvent.schedule(new Action0() { - @Override - public void call() { - if (null != eventListener) { - try { - final T observerEvent = eventListener.onObserverEvent(transferValue); - - //观察者事件处理的调度器 - final Scheduler.Worker workerDispose = scheduler.createWorker(); - workerDispose.schedule(new Action0() { - @Override - public void call() { - try { - subscriber.onNext(observerEvent); - awake(); - } catch (Throwable e) { - try { - worker.unsubscribe(); - workerEvent.unsubscribe(); - workerDispose.unsubscribe(); - awake(); - } finally { - Exceptions.throwOrReport(e, subscriber); - } - } - } - }); - } catch (Throwable e) { - try { - worker.unsubscribe(); - workerEvent.unsubscribe(); - awake(); - } finally { - Exceptions.throwOrReport(e, subscriber); - } - } - } - } - }); - //当前线程休眠,等待"被观察者"事件逻辑处理完毕 - OnSubscribeTimerPeriodically.this.wait(); - } - } catch (Throwable e) { - try { - worker.unsubscribe(); - } finally { - Exceptions.throwOrReport(e, subscriber); - } - } - } - - }, initialDelay, period, unit); - } - - /** - * 观察者已经根据被观察者的动作做出相应处理后唤醒调度器定时器继续往下走 - */ - private void awake() { - synchronized (OnSubscribeTimerPeriodically.this) { - OnSubscribeTimerPeriodically.this.notify(); - } - } -} diff --git a/nohttputils-r1/build.gradle b/nohttputils-r2/build.gradle similarity index 82% rename from nohttputils-r1/build.gradle rename to nohttputils-r2/build.gradle index 2438b4b..f18ed10 100644 --- a/nohttputils-r1/build.gradle +++ b/nohttputils-r2/build.gradle @@ -8,8 +8,8 @@ android { defaultConfig { minSdkVersion 11 targetSdkVersion 23 - versionCode 1 - versionName "1" + versionCode 2 + versionName "2" } buildTypes { release { @@ -24,7 +24,7 @@ dependencies { testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.4.0' compile 'com.yanzhenjie.nohttp:okhttp:1.1.4' - compile 'io.reactivex:rxandroid:1.2.1' - compile 'io.reactivex:rxjava:1.1.9' + compile 'io.reactivex.rxjava2:rxandroid:2.0.1' + compile 'io.reactivex.rxjava2:rxjava:2.1.5' compile 'com.google.code.gson:gson:2.8.0' } diff --git a/nohttputils-r1/src/main/AndroidManifest.xml b/nohttputils-r2/src/main/AndroidManifest.xml similarity index 100% rename from nohttputils-r1/src/main/AndroidManifest.xml rename to nohttputils-r2/src/main/AndroidManifest.xml diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/RxNoHttpUtils.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/RxNoHttpUtils.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/RxNoHttpUtils.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/RxNoHttpUtils.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/download/DownloadUrlEntity.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/DownloadUrlEntity.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/download/DownloadUrlEntity.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/download/DownloadUrlEntity.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/download/NohttpDownload.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/NohttpDownload.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/download/NohttpDownload.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/download/NohttpDownload.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/download/NohttpDownloadConfig.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/NohttpDownloadConfig.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/download/NohttpDownloadConfig.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/download/NohttpDownloadConfig.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/download/NohttpDownloadUtils.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/NohttpDownloadUtils.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/download/NohttpDownloadUtils.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/download/NohttpDownloadUtils.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/download/NohttpDownloadWhatAlgorithm.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/NohttpDownloadWhatAlgorithm.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/download/NohttpDownloadWhatAlgorithm.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/download/NohttpDownloadWhatAlgorithm.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/download/service/NohttpDownloadService.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/service/NohttpDownloadService.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/download/service/NohttpDownloadService.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/download/service/NohttpDownloadService.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/interfa/DialogGetListener.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/interfa/DialogGetListener.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/interfa/DialogGetListener.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/interfa/DialogGetListener.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/interfa/OnIsRequestListener.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/interfa/OnIsRequestListener.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/interfa/OnIsRequestListener.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/interfa/OnIsRequestListener.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/interfa/OnRequestRxNoHttpListener.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/interfa/OnRequestRxNoHttpListener.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/interfa/OnRequestRxNoHttpListener.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/interfa/OnRequestRxNoHttpListener.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/BinaryAllObj.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/BinaryAllObj.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/BinaryAllObj.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/BinaryAllObj.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/BinaryFactory.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/BinaryFactory.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/BinaryFactory.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/BinaryFactory.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/NoHttpInit.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/NoHttpInit.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/NoHttpInit.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/NoHttpInit.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RequestBeanObj.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RequestBeanObj.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RequestBeanObj.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RequestBeanObj.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxNoHttp.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxNoHttp.java similarity index 84% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxNoHttp.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxNoHttp.java index ec2b4b3..cef01e1 100644 --- a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxNoHttp.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxNoHttp.java @@ -21,10 +21,14 @@ import java.net.ConnectException; import java.net.ProtocolException; -import rx.Observable; -import rx.Subscriber; -import rx.android.schedulers.AndroidSchedulers; -import rx.schedulers.Schedulers; +import io.reactivex.Observable; +import io.reactivex.ObservableEmitter; +import io.reactivex.ObservableOnSubscribe; +import io.reactivex.Observer; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.annotations.NonNull; +import io.reactivex.disposables.Disposable; +import io.reactivex.schedulers.Schedulers; /** @@ -58,9 +62,9 @@ void request(final ProtocolRequest request, DialogGetListener mDialogG } } - Observable.create(new Observable.OnSubscribe>() { + Observable.create(new ObservableOnSubscribe>() { @Override - public void call(Subscriber> subscriberOut) { + public void subscribe(@NonNull ObservableEmitter> subscriberOut) throws Exception { // 最关键的就是用NoHttp的同步请求请求到response了,其它的都是rxjava做的,跟nohttp无关的。 Response response = NoHttp.startRequestSync(request); if (response.isSucceed() || response.isFromCache()) { @@ -68,18 +72,39 @@ public void call(Subscriber> subscriberOut) { } else { subscriberOut.onError(response.getException()); } - } }).subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Subscriber>() { + .subscribe(new Observer>() { + private Disposable mDisposable; + + @Override + public void onSubscribe(@NonNull Disposable d) { + mDisposable = d; + } + @Override - public void onCompleted() { + public void onNext(@NonNull Response tResponse) { + mDisposable.dispose(); + // 关闭dialog. + if (null != dialog && dialog.isShowing()) { + try { + dialog.dismiss(); + } catch (Exception e1) { + Logger.e("Dialog-关闭异常:由于Dialog已经关闭或者依赖的Context不存在"); + } + } + + if (null != responseInterfa) { + responseInterfa.onNext(tResponse.get()); + } } @Override - public void onError(Throwable e) { + public void onError(@NonNull Throwable e) { + mDisposable.dispose(); + // 关闭dialog. if (null != dialog && dialog.isShowing()) { try { @@ -115,8 +140,8 @@ public void onError(Throwable e) { } if (TextUtils.isEmpty(anUnknownErrorHint)) { show(dialog, R.string.error_unknow); - }else{ - show(dialog,anUnknownErrorHint); + } else { + show(dialog, anUnknownErrorHint); } } @@ -127,19 +152,8 @@ public void onError(Throwable e) { } @Override - public void onNext(Response tResponse) { - // 关闭dialog. - if (null != dialog && dialog.isShowing()) { - try { - dialog.dismiss(); - } catch (Exception e1) { - Logger.e("Dialog-关闭异常:由于Dialog已经关闭或者依赖的Context不存在"); - } - } + public void onComplete() { - if (null != responseInterfa) { - responseInterfa.onNext(tResponse.get()); - } } }); } @@ -155,6 +169,7 @@ private void show(Dialog dialog, int stringId) { Toast.makeText(context, context.getResources().getString(stringId), Toast.LENGTH_SHORT).show(); } } + /** * 土司提示 * diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxPollNoHttpConfig.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxPollNoHttpConfig.java similarity index 88% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxPollNoHttpConfig.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxPollNoHttpConfig.java index 6c25565..9cf92fe 100644 --- a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxPollNoHttpConfig.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxPollNoHttpConfig.java @@ -9,8 +9,8 @@ import com.liqi.nohttputils.nohttp.rx_poll.operators.OnObserverEventListener; import com.yanzhenjie.nohttp.rest.RestRequest; -import rx.functions.Action1; -import rx.functions.Func1; +import io.reactivex.functions.Consumer; +import io.reactivex.functions.Predicate; /** * NoHttp轮询配置类 @@ -29,7 +29,7 @@ public class RxPollNoHttpConfig { /** * 设置数据拦截监听对象 */ - private Func1, Boolean> mBooleanFunc1; + private Predicate> mBooleanFunc1; /** * 被观察者产生的行为事件监听器 */ @@ -37,7 +37,7 @@ public class RxPollNoHttpConfig { /** * 观察者根据被观察产生的行为做出相应处理监听器 */ - private Action1> mRxInformationModelAction1; + private Consumer> mRxInformationModelAction1; /** * 网络请求参数对象 */ @@ -54,7 +54,7 @@ public long getPeriod() { return mPeriod; } - public Func1, Boolean> getBooleanFunc1() { + public Predicate> getBooleanFunc1() { return mBooleanFunc1; } @@ -62,7 +62,7 @@ public RxRequestOperate getRxRequestOperate() { return mRxRequestOperate; } - public Action1> getRxInformationModelAction1() { + public Consumer> getRxInformationModelAction1() { return mRxInformationModelAction1; } @@ -123,7 +123,7 @@ public ConfigBuilder setPeriod(long period) { * @param booleanFunc1 设置数据拦截监听对象 * @return 构建轮询配置类 */ - public ConfigBuilder setBooleanFunc1(Func1, Boolean> booleanFunc1) { + public ConfigBuilder setBooleanFunc1(Predicate> booleanFunc1) { mRxPollNoHttpConfig.mBooleanFunc1 = booleanFunc1; return this; } @@ -134,7 +134,7 @@ public ConfigBuilder setBooleanFunc1(Func1, Boolean> bo * @param rxInformationModelAction1 观察者根据被观察产生的行为做出相应处理监听器 * @return 构建轮询配置类 */ - public ConfigBuilder setRxInformationModelAction1(Action1> rxInformationModelAction1) { + public ConfigBuilder setRxInformationModelAction1(Consumer> rxInformationModelAction1) { mRxPollNoHttpConfig.mRxInformationModelAction1 = rxInformationModelAction1; return this; } diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxRequestConfig.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestConfig.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxRequestConfig.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestConfig.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxRequestEntityBase.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestEntityBase.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxRequestEntityBase.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestEntityBase.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxRequestInputStreamEntity.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestInputStreamEntity.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxRequestInputStreamEntity.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestInputStreamEntity.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxRequestJsonListEntity.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestJsonListEntity.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxRequestJsonListEntity.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestJsonListEntity.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxRequestJsonObjectEntity.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestJsonObjectEntity.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxRequestJsonObjectEntity.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestJsonObjectEntity.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxRequestOperate.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestOperate.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxRequestOperate.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestOperate.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxRequestStringEntity.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestStringEntity.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxRequestStringEntity.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestStringEntity.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxThreadInterchange.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxThreadInterchange.java similarity index 93% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxThreadInterchange.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxThreadInterchange.java index 68b2d30..ffe5f17 100644 --- a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxThreadInterchange.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxThreadInterchange.java @@ -26,10 +26,12 @@ import java.net.ConnectException; import java.net.ProtocolException; -import rx.Observable; -import rx.Subscriber; -import rx.android.schedulers.AndroidSchedulers; -import rx.schedulers.Schedulers; +import io.reactivex.Observable; +import io.reactivex.Observer; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.Disposable; +import io.reactivex.schedulers.Schedulers; + /** * 把数据源中的数据转换成rxJava线程的中转站对象 @@ -142,13 +144,40 @@ private void runRequest(final RxRequestModel baseRxRequestModel) { Observable.create(baseRxRequestModel) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Subscriber() { + .subscribe(new Observer() { + private Disposable mDisposable; + + @Override + public void onSubscribe(@NonNull Disposable d) { + mDisposable = d; + } + @Override - public void onCompleted() { + public void onNext(@NonNull T t) { + mDisposable.dispose(); + + Dialog dialog = getDialog(baseRxRequestModel); + if (null != dialog && dialog.isShowing()) { + try { + dialog.dismiss(); + } catch (Exception e) { + Logger.e("Dialog-关闭异常:由于Dialog已经关闭或者依赖的Context不存在"); + } + } + + OnIsRequestListener onIsRequestListener = baseRxRequestModel.getOnIsRequestListener(); + if (null != onIsRequestListener) { + onIsRequestListener.onNext(t); + } + + baseRxRequestModel.clearAll(); + messageListDalete(); } @Override - public void onError(Throwable e) { + public void onError(@NonNull Throwable e) { + mDisposable.dispose(); + Dialog dialog = getDialog(baseRxRequestModel); if (null != dialog && dialog.isShowing()) { try { @@ -204,23 +233,8 @@ public void onError(Throwable e) { } @Override - public void onNext(T t) { - Dialog dialog = getDialog(baseRxRequestModel); - if (null != dialog && dialog.isShowing()) { - try { - dialog.dismiss(); - } catch (Exception e) { - Logger.e("Dialog-关闭异常:由于Dialog已经关闭或者依赖的Context不存在"); - } - } + public void onComplete() { - OnIsRequestListener onIsRequestListener = baseRxRequestModel.getOnIsRequestListener(); - if (null != onIsRequestListener) { - onIsRequestListener.onNext(t); - } - - baseRxRequestModel.clearAll(); - messageListDalete(); } }); } diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxUtilsConfig.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxUtilsConfig.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/RxUtilsConfig.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxUtilsConfig.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/SSLContextUtil.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/SSLContextUtil.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/SSLContextUtil.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/SSLContextUtil.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/gsonutils/JsonUtil.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/gsonutils/JsonUtil.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/gsonutils/JsonUtil.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/gsonutils/JsonUtil.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/interfa/OnToInputStreamEntityMethodListener.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/interfa/OnToInputStreamEntityMethodListener.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/interfa/OnToInputStreamEntityMethodListener.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/interfa/OnToInputStreamEntityMethodListener.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/interfa/OnToJsonListEntityMethodListener.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/interfa/OnToJsonListEntityMethodListener.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/interfa/OnToJsonListEntityMethodListener.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/interfa/OnToJsonListEntityMethodListener.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/interfa/OnToJsonObjectEntityMethodListener.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/interfa/OnToJsonObjectEntityMethodListener.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/interfa/OnToJsonObjectEntityMethodListener.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/interfa/OnToJsonObjectEntityMethodListener.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/interfa/OnToStringEntityMethodListener.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/interfa/OnToStringEntityMethodListener.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/interfa/OnToStringEntityMethodListener.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/interfa/OnToStringEntityMethodListener.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/RxPollUtils.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/RxPollUtils.java similarity index 89% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/RxPollUtils.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/RxPollUtils.java index 0650df8..8f7585b 100644 --- a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/RxPollUtils.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/RxPollUtils.java @@ -15,10 +15,11 @@ import java.util.concurrent.TimeUnit; -import rx.android.schedulers.AndroidSchedulers; -import rx.functions.Action1; -import rx.functions.Func1; -import rx.schedulers.Schedulers; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.functions.Consumer; +import io.reactivex.functions.Predicate; +import io.reactivex.schedulers.Schedulers; + /** * RxJava轮询控制类 @@ -63,13 +64,13 @@ public void requestRxNoHttp() { informationPoolModel.setSign(sign); } //赋值拦截器 - Func1, Boolean> booleanFunc1 = mRxPollNoHttpConfig.getBooleanFunc1(); + Predicate> booleanFunc1 = mRxPollNoHttpConfig.getBooleanFunc1(); if (null != booleanFunc1) { informationPoolModel.setBooleanFunc1(booleanFunc1); } //设置观察者相应处理事件 - Action1> rxInformationModelAction1 = mRxPollNoHttpConfig.getRxInformationModelAction1(); + Consumer> rxInformationModelAction1 = mRxPollNoHttpConfig.getRxInformationModelAction1(); if (null != rxInformationModelAction1) { informationPoolModel.setRxInformationModelAction1(rxInformationModelAction1); } diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/extend/ObservableExpand.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/extend/ObservableExpand.java similarity index 63% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/extend/ObservableExpand.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/extend/ObservableExpand.java index 9dc89b7..ad38223 100644 --- a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/extend/ObservableExpand.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/extend/ObservableExpand.java @@ -1,39 +1,23 @@ package com.liqi.nohttputils.nohttp.rx_poll.extend; -import android.support.annotation.NonNull; - import com.liqi.nohttputils.nohttp.rx_poll.operators.OnObserverEventListener; import com.liqi.nohttputils.nohttp.rx_poll.operators.OnSubscribeTimerPeriodically; import java.util.concurrent.TimeUnit; -import rx.Observable; -import rx.Scheduler; -import rx.plugins.RxJavaHooks; -import rx.schedulers.Schedulers; +import io.reactivex.Observable; +import io.reactivex.Scheduler; +import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.schedulers.Schedulers; + /** * 继承rxjava-Observable扩展类 * Created by LiQi on 2017/9/6. */ -public class ObservableExpand extends Observable { - - final OnSubscribeTimerPeriodically onSubscribeTimerPeriodically; - - /** - * Creates an Observable with a Function to execute when it is subscribed to. - *

- * Note: Use {@link #create(OnSubscribe)} to create an Observable, instead of this constructor, - * unless you specifically have a need for inheritance. - * - * @param f {@link OnSubscribe} to be executed when {@link #subscribe(Subscriber)} is called - */ - protected ObservableExpand(OnSubscribe f, OnSubscribeTimerPeriodically onSubscribe1) { - super(f); - onSubscribeTimerPeriodically = onSubscribe1; - } +public class ObservableExpand { /** @@ -53,7 +37,7 @@ public static Builder intervalPolling(long initialDelay, long perio /** * 订阅间隔计时Builder - * @param + * * @param */ public static class Builder { @@ -85,16 +69,16 @@ public Builder(long initialDelay, long period, TimeUnit unit, OnObserverEventLis * 设置可观察者监听器线程线路 * * @param eventScheduler 线程线路 - * @param transferValue 传输给被观察者对象 + * @param transferValue 待处理或者待传输的对象 * @return */ - public ObservableExpand subscribeOn(Scheduler eventScheduler, @NonNull V transferValue) { + public Observable subscribeOn(Scheduler eventScheduler, V transferValue) { - OnSubscribeTimerPeriodically timerPeriodically = new OnSubscribeTimerPeriodically<>(initialDelay, period, unit, Schedulers.computation()); + OnSubscribeTimerPeriodically timerPeriodically = new OnSubscribeTimerPeriodically<>(Math.max(0L, initialDelay), Math.max(0L, period), unit, Schedulers.computation()); timerPeriodically.setOnObserverEventListener(observerEventListener); timerPeriodically.setTransferValue(transferValue); timerPeriodically.setEventScheduler(eventScheduler); - return new ObservableExpand<>(RxJavaHooks.onCreate(timerPeriodically), timerPeriodically); + return RxJavaPlugins.onAssembly(timerPeriodically); } } -} +} \ No newline at end of file diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/interfa/OnRxInformationCancelListener.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/interfa/OnRxInformationCancelListener.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/interfa/OnRxInformationCancelListener.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/interfa/OnRxInformationCancelListener.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/interfa/OnRxInformationListListener.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/interfa/OnRxInformationListListener.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/interfa/OnRxInformationListListener.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/interfa/OnRxInformationListListener.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/interfa/OnRxPollConfigBuilderListener.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/interfa/OnRxPollConfigBuilderListener.java similarity index 77% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/interfa/OnRxPollConfigBuilderListener.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/interfa/OnRxPollConfigBuilderListener.java index a8e89f6..1a45af5 100644 --- a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/interfa/OnRxPollConfigBuilderListener.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/interfa/OnRxPollConfigBuilderListener.java @@ -3,7 +3,7 @@ import com.liqi.nohttputils.nohttp.RxPollNoHttpConfig; import com.liqi.nohttputils.nohttp.rx_poll.model.RxInformationModel; -import rx.functions.Func1; +import io.reactivex.functions.Predicate; /** * RX轮询构建轮询配置类业务操作方法接口 @@ -17,5 +17,5 @@ public interface OnRxPollConfigBuilderListener { * @param booleanFunc1 设置数据拦截监听对象 * @return 构建轮询配置类 */ - RxPollNoHttpConfig.ConfigBuilder setBooleanFunc1(Func1, Boolean> booleanFunc1); + RxPollNoHttpConfig.ConfigBuilder setBooleanFunc1(Predicate> booleanFunc1); } diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/model/RxInformationModel.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/model/RxInformationModel.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/model/RxInformationModel.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/model/RxInformationModel.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/model/RxInformationPoolModel.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/model/RxInformationPoolModel.java similarity index 91% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/model/RxInformationPoolModel.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/model/RxInformationPoolModel.java index a695ee3..bd83816 100644 --- a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/model/RxInformationPoolModel.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/model/RxInformationPoolModel.java @@ -24,10 +24,9 @@ import java.net.ConnectException; import java.net.ProtocolException; -import rx.android.schedulers.AndroidSchedulers; -import rx.functions.Action0; -import rx.functions.Action1; -import rx.functions.Func1; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.functions.Consumer; +import io.reactivex.functions.Predicate; /** * rxJava轮询操作数据源对象 @@ -42,9 +41,9 @@ public class RxInformationPoolModel { private RxInformationModel mRxInformationModel; - private Func1, Boolean> mBooleanFunc1; + private Predicate> mBooleanFunc1; private OnObserverEventListener, RxInformationModel> mOnObserverEventListener; - private Action1> mRxInformationModelAction1; + private Consumer> mRxInformationModelAction1; public RxInformationPoolModel(@NonNull OnIsRequestListener onIsRequestListener, DialogGetListener dialogGetListener, String anUnknownErrorHint) { mOnIsRequestListener = onIsRequestListener; @@ -62,9 +61,9 @@ public RxInformationPoolModel(@NonNull OnIsRequestListener onIsRequestListene */ private void initRxInformationModelAction1(final String anUnknownErrorHint) { - mRxInformationModelAction1 = new Action1>() { + mRxInformationModelAction1 = new Consumer>() { @Override - public void call(RxInformationModel tRxInformationModel) { + public void accept(RxInformationModel tRxInformationModel) throws Exception { Logger.e(mRestRequest.url() + ":轮询运行完毕"); Dialog dialog = null == mDialogGetListener ? null : mDialogGetListener.getDialog(); @@ -130,9 +129,9 @@ public void call(RxInformationModel tRxInformationModel) { * 内部实现是否取消轮询-拦截器 */ private void initBooleanFunc1() { - mBooleanFunc1 = new Func1, Boolean>() { + mBooleanFunc1 = new Predicate>() { @Override - public Boolean call(RxInformationModel tRxInformationModel) { + public boolean test(RxInformationModel tRxInformationModel) throws Exception { //拦截传输过来的对象为null之时,创建一个对象关闭临时关闭轮询对象 if (null == tRxInformationModel) { tRxInformationModel = new RxInformationModel<>(); @@ -155,9 +154,9 @@ public RxInformationModel onObserverEvent(RestRequest restRequest) { initTransitionModel(); if (null != mDialogGetListener) { //对话框放到主线程去运行 - AndroidSchedulers.mainThread().createWorker().schedule(new Action0() { + AndroidSchedulers.mainThread().createWorker().schedule(new Runnable() { @Override - public void call() { + public void run() { Dialog dialog = mDialogGetListener.getDialog(); if (null != dialog) { dialog.show(); @@ -192,7 +191,7 @@ public void call() { * * @return 数据拦截监听对象 */ - public Func1, Boolean> getBooleanFunc1() { + public Predicate> getBooleanFunc1() { return mBooleanFunc1; } @@ -201,7 +200,7 @@ public Func1, Boolean> getBooleanFunc1() { * * @param booleanFunc1 数据拦截监听对象 */ - public void setBooleanFunc1(Func1, Boolean> booleanFunc1) { + public void setBooleanFunc1(Predicate> booleanFunc1) { if (null != booleanFunc1) { mBooleanFunc1 = booleanFunc1; } @@ -230,7 +229,7 @@ public void setOnObserverEventListener(OnObserverEventListener, R * * @return 可观察者事件产生对应行动监听器 */ - public Action1> getRxInformationModelAction1() { + public Consumer> getRxInformationModelAction1() { return mRxInformationModelAction1; } @@ -239,7 +238,7 @@ public Action1> getRxInformationModelAction1() { * * @param rxInformationModelAction1 可观察者事件产生对应行动监听器 */ - public void setRxInformationModelAction1(Action1> rxInformationModelAction1) { + public void setRxInformationModelAction1(Consumer> rxInformationModelAction1) { mRxInformationModelAction1 = rxInformationModelAction1; } diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/operators/OnObserverEventListener.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/operators/OnObserverEventListener.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/operators/OnObserverEventListener.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/operators/OnObserverEventListener.java diff --git a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/operators/OnSubscribeTimerPeriodically.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/operators/OnSubscribeTimerPeriodically.java new file mode 100644 index 0000000..b0228ff --- /dev/null +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/operators/OnSubscribeTimerPeriodically.java @@ -0,0 +1,206 @@ +package com.liqi.nohttputils.nohttp.rx_poll.operators; + +import com.yanzhenjie.nohttp.Logger; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import io.reactivex.Observable; +import io.reactivex.Observer; +import io.reactivex.Scheduler; +import io.reactivex.disposables.Disposable; +import io.reactivex.internal.disposables.DisposableHelper; +import io.reactivex.schedulers.Schedulers; + + +/** + * 订阅者间隔计时器(轮询)对象 + * Created by LiQi on 2017/9/6. + */ + +public final class OnSubscribeTimerPeriodically extends Observable { + /** + * 初始化加载延迟 + */ + final long initialDelay; + /** + * 轮询间隔时间 + */ + final long period; + /** + * 时间单位 + */ + final TimeUnit unit; + /** + * 订阅者线程线路 + */ + final Scheduler scheduler; + /** + * 可观察者事件监听器 + */ + private OnObserverEventListener eventListener; + /** + * 可观察者线程线路-事件处理默认在子线程 + */ + private Scheduler eventScheduler = Schedulers.io(); + /** + * 传输给被观察者接受的对象 + */ + private V transferValue; + private Disposable disposable; + + public OnSubscribeTimerPeriodically(long initialDelay, long period, TimeUnit unit, Scheduler scheduler) { + this.initialDelay = initialDelay; + this.period = period; + this.unit = unit; + this.scheduler = scheduler; + } + + private static void toThrowableString(Throwable e) { + Logger.e("Expand-轮询异常捕获:" + e.toString()); + StackTraceElement[] stackTrace = e.getStackTrace(); + if (null != stackTrace) { + for (StackTraceElement traceElement : stackTrace) { + Logger.e("Expand-轮询异常捕获:" + traceElement.toString()); + } + } + } + + /** + * 赋值传输给被观察者接受的对象 + * + * @param transferValue 被观察者接受的对象 + */ + public void setTransferValue(V transferValue) { + this.transferValue = transferValue; + } + + /** + * 设置事件执行线程线路 + * + * @param eventScheduler 线程线路 + */ + public void setEventScheduler(Scheduler eventScheduler) { + if (null != eventScheduler) { + this.eventScheduler = eventScheduler; + } + } + + /** + * 设置可观察者事件监听器 + * + * @param eventListener 可观察者事件监听器 + */ + public void setOnObserverEventListener(OnObserverEventListener eventListener) { + this.eventListener = eventListener; + } + + /** + * 观察者已经根据被观察者的动作做出相应处理后唤醒调度器定时器继续往下走 + */ + private void awake() { + synchronized (OnSubscribeTimerPeriodically.this) { + OnSubscribeTimerPeriodically.this.notify(); + } + } + + @Override + protected void subscribeActual(Observer observer) { + + final Observer observerNew = observer; + + //子线程调度器执行 + final Scheduler.Worker worker = Schedulers.io().createWorker(); + + IntervalObserver is = new IntervalObserver() { + + @Override + void runStart() throws Exception { + synchronized (OnSubscribeTimerPeriodically.this) { + //被观察事件处理的调度器 + final Scheduler.Worker workerEvent = eventScheduler.createWorker(); + workerEvent.schedule(new Runnable() { + @Override + public void run() { + if (null != eventListener) { + try { + final T observerEvent = eventListener.onObserverEvent(transferValue); + + //观察者事件处理的调度器 + final Scheduler.Worker workerDispose = scheduler.createWorker(); + workerDispose.schedule(new Runnable() { + @Override + public void run() { + try { + observerNew.onNext(observerEvent); + end(); + } catch (Throwable e) { + disposable.dispose(); + disposable = null; + eventScheduler = null; + eventListener = null; + end(); + toThrowableString(e); + } + } + }); + } catch (Throwable e) { + disposable.dispose(); + disposable = null; + eventScheduler = null; + eventListener = null; + end(); + toThrowableString(e); + } + } + } + }); + //当前线程休眠,等待"被观察者"事件逻辑处理完毕 + OnSubscribeTimerPeriodically.this.wait(); + } + } + }; + observerNew.onSubscribe(is); + disposable = worker.schedulePeriodically(is, initialDelay, period, unit); + } + + private void end() { + awake(); + System.gc(); + } + + private static abstract class IntervalObserver + extends AtomicReference + implements Disposable, Runnable { + + + private static final long serialVersionUID = 346773832286157679L; + + private IntervalObserver() { + } + + @Override + public void dispose() { + DisposableHelper.dispose(this); + } + + @Override + public boolean isDisposed() { + return get() == DisposableHelper.DISPOSED; + } + + @Override + public void run() { + if (get() != DisposableHelper.DISPOSED) { + try { + runStart(); + } catch (Exception e) { + toThrowableString(e); + } + } + } + + + abstract void runStart() throws Exception; + } +} diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/pond/RxInformationPool.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/pond/RxInformationPool.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/pond/RxInformationPool.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/pond/RxInformationPool.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/RxMessageSource.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/RxMessageSource.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/RxMessageSource.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/RxMessageSource.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/interfa/OnRxMessageGetListener.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/interfa/OnRxMessageGetListener.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/interfa/OnRxMessageGetListener.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/interfa/OnRxMessageGetListener.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/interfa/OnRxMessageSetListener.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/interfa/OnRxMessageSetListener.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/interfa/OnRxMessageSetListener.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/interfa/OnRxMessageSetListener.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/model/BaseRxRequestModel.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/model/BaseRxRequestModel.java similarity index 80% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/model/BaseRxRequestModel.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/model/BaseRxRequestModel.java index 0be1cd3..d696c4d 100644 --- a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/model/BaseRxRequestModel.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/model/BaseRxRequestModel.java @@ -1,14 +1,16 @@ package com.liqi.nohttputils.nohttp.rx_threadpool.model; -import rx.Observable; -import rx.Subscriber; +import io.reactivex.ObservableEmitter; +import io.reactivex.ObservableOnSubscribe; +import io.reactivex.annotations.NonNull; -/**所有要处理的数据基类 +/** + * 所有要处理的数据基类 * Created by LiQi on 2017/3/20. */ -public abstract class BaseRxRequestModel implements Observable.OnSubscribe { +public abstract class BaseRxRequestModel implements ObservableOnSubscribe { //是否需要打断线程标识 private boolean isRunOff; //是否已经有线程处理了 @@ -18,6 +20,7 @@ public abstract class BaseRxRequestModel implements Observable.OnSubscribe /** * 设置错误信息 + * * @param throwable 错误对象 */ protected void setThrowable(Throwable throwable) { @@ -42,8 +45,7 @@ public void setRunOff(boolean runOff) { } @Override - public void call(Subscriber subscriber) { - + public void subscribe(@NonNull ObservableEmitter subscriber) throws Exception { T t = run(); if (!isRunOff()) subscriber.onNext(t); diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/model/RxRequestModel.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/model/RxRequestModel.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/model/RxRequestModel.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/model/RxRequestModel.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/thread/RxThreadDispatch.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/thread/RxThreadDispatch.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/thread/RxThreadDispatch.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/thread/RxThreadDispatch.java diff --git a/nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/utils/RxThreadPoolUtisl.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/utils/RxThreadPoolUtisl.java similarity index 100% rename from nohttputils-r1/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/utils/RxThreadPoolUtisl.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/utils/RxThreadPoolUtisl.java diff --git a/nohttputils-r1/src/main/res/values/strings.xml b/nohttputils-r2/src/main/res/values/strings.xml similarity index 100% rename from nohttputils-r1/src/main/res/values/strings.xml rename to nohttputils-r2/src/main/res/values/strings.xml diff --git a/sample/build.gradle b/sample/build.gradle index 39e7bd3..223afea 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -23,5 +23,5 @@ dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.4.0' - compile project(':nohttputils-r1') + compile project(':nohttputils-r2') } diff --git a/sample/src/main/java/com/liqi/nohttprxutils/PollDemo.java b/sample/src/main/java/com/liqi/nohttprxutils/PollDemo.java index 698ce6a..cda3852 100644 --- a/sample/src/main/java/com/liqi/nohttprxutils/PollDemo.java +++ b/sample/src/main/java/com/liqi/nohttprxutils/PollDemo.java @@ -12,8 +12,8 @@ import com.liqi.nohttputils.nohttp.rx_poll.operators.OnObserverEventListener; import com.yanzhenjie.nohttp.rest.RestRequest; -import rx.functions.Action1; -import rx.functions.Func1; +import io.reactivex.functions.Consumer; +import io.reactivex.functions.Predicate; /** * 轮询请求演示界面 @@ -212,23 +212,36 @@ public RxInformationModel onObserverEvent(RestRequest transferVa } }) - .setBooleanFunc1(new Func1,Boolean>() { + .setBooleanFunc1(new Predicate>() { +// @Override +// public Boolean call(RxInformationModel stringRxInformationModel) { +// Log.e("外部实现轮询拦截","外部实现轮询拦截>>>拦截状态:"+stringRxInformationModel.isStop()); +// return stringRxInformationModel.isStop(); +// } + @Override - public Boolean call(RxInformationModel stringRxInformationModel) { + public boolean test(RxInformationModel stringRxInformationModel) throws Exception { Log.e("外部实现轮询拦截","外部实现轮询拦截>>>拦截状态:"+stringRxInformationModel.isStop()); return stringRxInformationModel.isStop(); } + }) + .setRxInformationModelAction1(new Consumer>() { // @Override -// public boolean test(@NonNull RxInformationModel stringRxInformationModel) throws Exception { -// Log.e("外部实现轮询拦截","外部实现轮询拦截>>>拦截状态:"+stringRxInformationModel.isStop()); -// return stringRxInformationModel.isStop(); +// public void call(RxInformationModel stringRxInformationModel) { +// String data = stringRxInformationModel.getData(); +// Log.e("外部实现轮询完毕","外部实现轮询运行完毕>>>运行结果:"+data); +// if (!isDiy) { +// isDiy = true; +// content.setText("轮询名称:自定义轮询\n外部实现调用轮询结果:" + data); +// } else { +// String trim = content.getText().toString().trim(); +// content.setText(trim + "\n\n轮询名称:自定义轮询\n外部实现调用轮询结果:" + data); +// } // } - }) - .setRxInformationModelAction1(new Action1>() { @Override - public void call(RxInformationModel stringRxInformationModel) { + public void accept(RxInformationModel stringRxInformationModel) throws Exception { String data = stringRxInformationModel.getData(); Log.e("外部实现轮询完毕","外部实现轮询运行完毕>>>运行结果:"+data); if (!isDiy) { @@ -239,11 +252,6 @@ public void call(RxInformationModel stringRxInformationModel) { content.setText(trim + "\n\n轮询名称:自定义轮询\n外部实现调用轮询结果:" + data); } } - -// @Override -// public void accept(RxInformationModel stringRxInformationModel) throws Exception { -// -// } }) .switchPoll() .requestRxNoHttp(); diff --git a/settings.gradle b/settings.gradle index fdae6a5..ab2e898 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':sample', ':nohttputils-r1' +include ':sample', ':nohttputils-r2' From 0ed9ea558e7777b5b381356b89774597bb5bf505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A5=87?= <543945827@qq.com> Date: Thu, 16 Nov 2017 11:29:48 +0800 Subject: [PATCH 02/11] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4fb4be6..58f87f1 100644 --- a/README.md +++ b/README.md @@ -67,12 +67,12 @@ repositories { **2:The project directory build.gradle relies on the NoHttpRxUtils framework**
* RxJava-1 project depends on ```gradle -compile 'com.github.liqinew:nohttprxutils:v.1.3.4' +compile 'com.github.liqinew:nohttprxutils:v.1.3.5' ``` * RxJava-2 project depends on ```gradle -compile 'com.github.liqinew:nohttprxutils:v.1.3.4' +compile 'com.github.liqinew:nohttprxutils:v.2.0.1' ``` NoHttpRxUtils use method ----- From 630a6aea4a44a3df7f6442b0aeeb4ee043990c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A5=87?= <543945827@qq.com> Date: Thu, 16 Nov 2017 11:30:25 +0800 Subject: [PATCH 03/11] Update README_CHINESE.md --- README_CHINESE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README_CHINESE.md b/README_CHINESE.md index de1f82b..8308dff 100644 --- a/README_CHINESE.md +++ b/README_CHINESE.md @@ -66,12 +66,12 @@ repositories { **2:项目目录build.gradle中依赖NoHttpRxUtils框架**
* 使用RxJava-1的项目请依赖 ```gradle -compile 'com.github.liqinew:nohttprxutils:v.1.3.4' +compile 'com.github.liqinew:nohttprxutils:v.1.3.5' ``` * 使用RxJava-2的项目请依赖 ```gradle -compile 'com.github.liqinew:nohttprxutils:v.1.3.4' +compile 'com.github.liqinew:nohttprxutils:v.2.0.1' ``` NoHttpRxUtils使用简介 From 7dd31622e503fa65d11d2f5452aecc411075faa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A5=87?= <543945827@qq.com> Date: Sun, 27 May 2018 18:40:20 +0800 Subject: [PATCH 04/11] Update build.gradle --- nohttputils-r2/build.gradle | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/nohttputils-r2/build.gradle b/nohttputils-r2/build.gradle index 786bbed..28bd396 100644 --- a/nohttputils-r2/build.gradle +++ b/nohttputils-r2/build.gradle @@ -7,15 +7,9 @@ android { defaultConfig { minSdkVersion 11 -<<<<<<< HEAD:nohttputils-r2/build.gradle - targetSdkVersion 23 + targetSdkVersion 22 versionCode 2 versionName "2" -======= - targetSdkVersion 22 - versionCode 1 - versionName "1" ->>>>>>> refs/remotes/origin/master:nohttputils-r1/build.gradle } buildTypes { release { From 447a5407350f49c46179ccafc82dbd5ff306a99c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A5=87?= <543945827@qq.com> Date: Sun, 27 May 2018 18:45:19 +0800 Subject: [PATCH 05/11] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 30c816d..edfb133 100644 --- a/README.md +++ b/README.md @@ -67,12 +67,12 @@ repositories { **2:The project directory build.gradle relies on the NoHttpRxUtils framework**
* RxJava-1 project depends on ```gradle -compile 'com.github.liqinew:nohttprxutils:v.1.3.5' +compile 'com.github.liqinew:nohttprxutils:v.1.3.6' ``` * RxJava-2 project depends on ```gradle -compile 'com.github.liqinew:nohttprxutils:v.2.0.1' +compile 'com.github.liqinew:nohttprxutils:v.2.0.2' ``` NoHttpRxUtils use method ----- From 940320e988f8e558a2e1532e479e9b3b7cdb99ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A5=87?= <543945827@qq.com> Date: Sun, 27 May 2018 18:46:13 +0800 Subject: [PATCH 06/11] Update README_CHINESE.md --- README_CHINESE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README_CHINESE.md b/README_CHINESE.md index a63e813..c895d80 100644 --- a/README_CHINESE.md +++ b/README_CHINESE.md @@ -66,12 +66,12 @@ repositories { **2:项目目录build.gradle中依赖NoHttpRxUtils框架**
* 使用RxJava-1的项目请依赖 ```gradle -compile 'com.github.liqinew:nohttprxutils:v.1.3.5' +compile 'com.github.liqinew:nohttprxutils:v.1.3.6' ``` * 使用RxJava-2的项目请依赖 ```gradle -compile 'com.github.liqinew:nohttprxutils:v.2.0.1' +compile 'com.github.liqinew:nohttprxutils:v.2.0.2' ``` NoHttpRxUtils使用简介 From 0b5828ec5946095a0addc83d7c31367c73f6befb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A5=87?= <543945827@qq.com> Date: Sun, 27 May 2018 19:34:22 +0800 Subject: [PATCH 07/11] Update README_CHINESE.md --- README_CHINESE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_CHINESE.md b/README_CHINESE.md index c895d80..b0e47ba 100644 --- a/README_CHINESE.md +++ b/README_CHINESE.md @@ -71,7 +71,7 @@ compile 'com.github.liqinew:nohttprxutils:v.1.3.6' * 使用RxJava-2的项目请依赖 ```gradle -compile 'com.github.liqinew:nohttprxutils:v.2.0.2' +compile 'com.github.liqinew:nohttprxutils:v.2.0.1' ``` NoHttpRxUtils使用简介 From f2b7d82aaa76d7b2372691a0171e59a40e6e5256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A5=87?= <543945827@qq.com> Date: Sun, 27 May 2018 19:35:19 +0800 Subject: [PATCH 08/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index edfb133..56d5ce2 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ compile 'com.github.liqinew:nohttprxutils:v.1.3.6' * RxJava-2 project depends on ```gradle -compile 'com.github.liqinew:nohttprxutils:v.2.0.2' +compile 'com.github.liqinew:nohttprxutils:v.2.0.1' ``` NoHttpRxUtils use method ----- From 239b1501db66e083d0718499bab748607d34c36e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A5=87?= <543945827@qq.com> Date: Fri, 2 Nov 2018 18:27:22 +0800 Subject: [PATCH 09/11] update v.2.0.6 update v.2.0.6 --- README.md | 9 +++- README_CHINESE.md | 10 +++- nohttputils-r2/build.gradle | 2 +- .../download/DownloadUrlEntity.java | 5 +- .../nohttputils/download/NohttpDownload.java | 15 ++++++ .../download/NohttpDownloadUtils.java | 12 +++++ .../service/NohttpDownloadService.java | 22 ++++++++- ...Listener.java => OnDialogGetListener.java} | 2 +- .../liqi/nohttputils/nohttp/NoHttpInit.java | 14 +++--- .../nohttputils/nohttp/RequestBeanObj.java | 4 +- .../com/liqi/nohttputils/nohttp/RxNoHttp.java | 10 ++-- .../nohttp/RxPollNoHttpConfig.java | 8 ++-- .../nohttputils/nohttp/RxRequestConfig.java | 18 ++++---- .../nohttputils/nohttp/RxRequestOperate.java | 23 +++++----- .../nohttp/RxThreadInterchange.java | 6 +-- .../nohttputils/nohttp/RxUtilsConfig.java | 14 +++--- .../nohttputils/nohttp/SSLContextUtil.java | 41 +++-------------- .../nohttp/rx_poll/RxPollUtils.java | 8 ++-- .../rx_poll/model/RxInformationPoolModel.java | 46 +++++++++---------- .../rx_threadpool/model/RxRequestModel.java | 40 ++++++++-------- .../FileUploadingDemoActivity.java | 11 +++-- .../nohttprxutils/GetPostDemoActivity.java | 16 +++---- .../liqi/nohttprxutils/HttpsDemoActivity.java | 4 +- .../ImageDownloadDemoActivity.java | 4 +- .../java/com/liqi/nohttprxutils/PollDemo.java | 38 ++++++--------- .../RequestQueueDemoActivity.java | 4 +- .../com/liqi/nohttprxutils/StaticHttpUrl.java | 33 ++++++------- .../liqi/nohttprxutils/base/BaseActivity.java | 4 +- .../download/DownloadFileActivity.java | 12 +++-- 29 files changed, 228 insertions(+), 207 deletions(-) rename nohttputils-r2/src/main/java/com/liqi/nohttputils/interfa/{DialogGetListener.java => OnDialogGetListener.java} (83%) diff --git a/README.md b/README.md index 56d5ce2..71b32f4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ [中文版文档](https://github.com/LiqiNew/NoHttpRxUtils/blob/master/README_CHINESE.md)

[![](https://jitpack.io/v/liqinew/nohttprxutils.svg)](https://jitpack.io/#liqinew/nohttprxutils) [![](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-%E6%9D%8E%E5%A5%87-orange.svg)](https://github.com/LiqiNew) +
**---- v.2.0.6 New in version ----** +* **Compatible to NoHttp-v.1.1.11** +* **Repair BUG**Fix bug that download file is not available because the file name was not passed in at the time of download +* **NohttpDownloadUtils** File download tool object added (getDownloadRequestsUrl() Get the path method corresponding to the download request What value) + ### Because NoHttpRxUtils through the RxJava face NoHttp network framework for a series of bundle.First of all against RxJava and NoHttp network framework to do a brief introduction # What is the RxJava framework? RxJava is a responsive programming design frame.
@@ -67,12 +72,12 @@ repositories { **2:The project directory build.gradle relies on the NoHttpRxUtils framework**
* RxJava-1 project depends on ```gradle -compile 'com.github.liqinew:nohttprxutils:v.1.3.6' +compile 'com.github.liqinew:nohttprxutils:v.2.0.5' ``` * RxJava-2 project depends on ```gradle -compile 'com.github.liqinew:nohttprxutils:v.2.0.1' +compile 'com.github.liqinew:nohttprxutils:v.2.0.6' ``` NoHttpRxUtils use method ----- diff --git a/README_CHINESE.md b/README_CHINESE.md index b0e47ba..954a18e 100644 --- a/README_CHINESE.md +++ b/README_CHINESE.md @@ -1,5 +1,11 @@ [![](https://jitpack.io/v/liqinew/nohttprxutils.svg)](https://jitpack.io/#liqinew/nohttprxutils) [![](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-%E6%9D%8E%E5%A5%87-orange.svg)](https://github.com/LiqiNew) +
**---- v.2.0.6版本新增功能 ----** +* **兼容到NoHttp-v.1.1.11** +* **修复BUG**修复因为下载时未传入文件名称而导致下载文件不可用的BUG +* **NohttpDownloadUtils** 文件下载工具对象新增(getDownloadRequestsUrl()获取下载请求What值对应的路径方法) + + ### 由于NoHttpRxUtils是通过RxJava对NoHttp网络框架操作进行一系列封装。
首先对RxJava和NoHttp网络框架做一个简介 # RxJava框架是什么? RxJava是响应式程序设计的一种实现。
@@ -66,12 +72,12 @@ repositories { **2:项目目录build.gradle中依赖NoHttpRxUtils框架**
* 使用RxJava-1的项目请依赖 ```gradle -compile 'com.github.liqinew:nohttprxutils:v.1.3.6' +compile 'com.github.liqinew:nohttprxutils:v.2.0.5' ``` * 使用RxJava-2的项目请依赖 ```gradle -compile 'com.github.liqinew:nohttprxutils:v.2.0.1' +compile 'com.github.liqinew:nohttprxutils:v.2.0.6' ``` NoHttpRxUtils使用简介 diff --git a/nohttputils-r2/build.gradle b/nohttputils-r2/build.gradle index 28bd396..108d1f5 100644 --- a/nohttputils-r2/build.gradle +++ b/nohttputils-r2/build.gradle @@ -23,7 +23,7 @@ dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.4.0' - compile 'com.yanzhenjie.nohttp:okhttp:1.1.4' + compile 'com.yanzhenjie.nohttp:okhttp:1.1.11' compile 'io.reactivex.rxjava2:rxandroid:2.0.1' compile 'io.reactivex.rxjava2:rxjava:2.1.5' compile 'com.google.code.gson:gson:2.8.0' diff --git a/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/DownloadUrlEntity.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/DownloadUrlEntity.java index e467384..0873f16 100644 --- a/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/DownloadUrlEntity.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/DownloadUrlEntity.java @@ -39,9 +39,8 @@ public void setFileName(String fileName) { */ private String urlGetName() { String[] split = mDownloadUrL.split("/"); - if (null != split && split.length > 0) { - String name = split[split.length - 1]; - return name + ".nohttpDownload"; + if (split.length > 0) { + return split[split.length - 1]; } else { Logger.e("下载地址按“/”切割错误,无法获取存储文件名"); return "ErrorDownloading"; diff --git a/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/NohttpDownload.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/NohttpDownload.java index 735f980..1a047fd 100644 --- a/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/NohttpDownload.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/NohttpDownload.java @@ -154,7 +154,22 @@ int getWhat(String downloadUrl) { what = mBindService.getWhat(downloadUrl); return what; } + /** + * 获取下载请求What值对应的路径 + *

+ * 如果有重复的值,那么获取数据源最后一位路径值。 + *

+ * + * @param what What值 + * @return 下载请求What值对应的路径值 + */ + String getDownloadRequestsUrl(int what) { + String downloadRequestsUrl = ""; + if (null != mBindService) + downloadRequestsUrl = mBindService.getDownloadRequestsUrl(what); + return downloadRequestsUrl; + } /** * 把指定的What从容器里面移除 * diff --git a/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/NohttpDownloadUtils.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/NohttpDownloadUtils.java index be9d3e0..f033c5e 100644 --- a/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/NohttpDownloadUtils.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/NohttpDownloadUtils.java @@ -66,6 +66,18 @@ public static void clearAll() { public static int getDownloadRequestsWhat(String downloadUrl) { return NohttpDownload.getNohttpDownload().getWhat(downloadUrl); } + /** + * 获取下载请求What值对应的路径 + *

+ * 如果有重复的值,那么获取数据源最后一位路径值。 + *

+ * + * @param what What值 + * @return 下载请求What值对应的路径值 + */ + public static String getDownloadRequestsUrl(int what) { + return NohttpDownload.getNohttpDownload().getDownloadRequestsUrl(what); + } /** * 移除下载地址对应的What diff --git a/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/service/NohttpDownloadService.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/service/NohttpDownloadService.java index f030dff..64eae60 100644 --- a/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/service/NohttpDownloadService.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/download/service/NohttpDownloadService.java @@ -238,7 +238,27 @@ public int getWhat(String downloadUrl) { } return -1; } - + /** + * 获取下载请求What值对应的路径 + *

+ * 如果有重复的值,那么获取数据源最后一位路径值。 + *

+ * @param what What值 + * @return 下载请求What值对应的路径值 + */ + public String getDownloadRequestsUrl(int what) { + String downloadRequestsUrl = ""; + if (null != mWhats && !mWhats.isEmpty()) { + if (mWhats.containsValue(what)) + for (Map.Entry entry : mWhats.entrySet()) { + Integer value = entry.getValue(); + if (value == what) { + downloadRequestsUrl = entry.getKey(); + } + } + } + return downloadRequestsUrl; + } /** * 把指定的What从容器里面移除 * diff --git a/nohttputils-r2/src/main/java/com/liqi/nohttputils/interfa/DialogGetListener.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/interfa/OnDialogGetListener.java similarity index 83% rename from nohttputils-r2/src/main/java/com/liqi/nohttputils/interfa/DialogGetListener.java rename to nohttputils-r2/src/main/java/com/liqi/nohttputils/interfa/OnDialogGetListener.java index 1389b96..d23f02d 100644 --- a/nohttputils-r2/src/main/java/com/liqi/nohttputils/interfa/DialogGetListener.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/interfa/OnDialogGetListener.java @@ -6,7 +6,7 @@ * 获取dialog * Created by LiQi on 2016/12/8. */ -public interface DialogGetListener { +public interface OnDialogGetListener { /** * 获取dialog * @return diff --git a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/NoHttpInit.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/NoHttpInit.java index 62baaa3..32fec88 100644 --- a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/NoHttpInit.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/NoHttpInit.java @@ -2,7 +2,7 @@ import android.content.Context; -import com.liqi.nohttputils.interfa.DialogGetListener; +import com.liqi.nohttputils.interfa.OnDialogGetListener; import com.yanzhenjie.nohttp.InitializationConfig; import com.yanzhenjie.nohttp.Logger; import com.yanzhenjie.nohttp.NetworkExecutor; @@ -33,7 +33,7 @@ public class NoHttpInit { /** * 加载框获取接口 */ - private DialogGetListener mDialogGetListener; + private OnDialogGetListener mOnDialogGetListener; private NoHttpInit() { @@ -43,8 +43,8 @@ static NoHttpInit getNoHttpInit() { return mNoHttpInit = null == mNoHttpInit ? new NoHttpInit() : mNoHttpInit; } - public DialogGetListener getDialogGetListener() { - return mDialogGetListener; + public OnDialogGetListener getOnDialogGetListener() { + return mOnDialogGetListener; } /** @@ -100,9 +100,9 @@ void init(RxUtilsConfig rxUtilsConfig) { SSLSocketFactory socketFactory; //是否有证书 if (null != inputStreamSSL) { - socketFactory = SSLContextUtil.getSSLContext(inputStreamSSL).getSocketFactory(); + socketFactory = SSLUtils.fixSSLLowerThanLollipop(SSLContextUtil.getSSLContext(inputStreamSSL).getSocketFactory()); } else { - socketFactory =SSLContextUtil.getDefaultSLLContext().getSocketFactory(); + socketFactory =SSLContextUtil.getDefaultSLLContext(); } builder.sslSocketFactory(socketFactory); //主机名验证 @@ -118,7 +118,7 @@ void init(RxUtilsConfig rxUtilsConfig) { NoHttp.initialize(builder.build()); Logger.setDebug(rxUtilsConfig.isDebug());// 开启NoHttp的调试模式, 配置后可看到请求过程、日志和错误信息。 Logger.setTag(rxUtilsConfig.getDebugName());// 设置NoHttp打印Log的tag。 - mDialogGetListener = rxUtilsConfig.getDialogGetListener(); + mOnDialogGetListener = rxUtilsConfig.getOnDialogGetListener(); } } } diff --git a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RequestBeanObj.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RequestBeanObj.java index b1395b3..7c38809 100644 --- a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RequestBeanObj.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RequestBeanObj.java @@ -23,7 +23,7 @@ import com.yanzhenjie.nohttp.Headers; import com.yanzhenjie.nohttp.Logger; import com.yanzhenjie.nohttp.RequestMethod; -import com.yanzhenjie.nohttp.rest.RestRequest; +import com.yanzhenjie.nohttp.rest.Request; import com.yanzhenjie.nohttp.rest.StringRequest; import org.json.JSONArray; @@ -37,7 +37,7 @@ * @param 请求成功后的数据转换对象 * Created by Liqi on 2016/10/15. */ -class RequestBeanObj extends RestRequest { +class RequestBeanObj extends Request { /** * Decoding lock so that we don't decode more than one image at a time (to avoid OOM's). diff --git a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxNoHttp.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxNoHttp.java index cef01e1..c8b3a8d 100644 --- a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxNoHttp.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxNoHttp.java @@ -6,7 +6,7 @@ import android.widget.Toast; import com.liqi.nohttputils.R; -import com.liqi.nohttputils.interfa.DialogGetListener; +import com.liqi.nohttputils.interfa.OnDialogGetListener; import com.liqi.nohttputils.interfa.OnIsRequestListener; import com.yanzhenjie.nohttp.Logger; import com.yanzhenjie.nohttp.NoHttp; @@ -15,7 +15,7 @@ import com.yanzhenjie.nohttp.error.TimeoutError; import com.yanzhenjie.nohttp.error.URLError; import com.yanzhenjie.nohttp.error.UnKnownHostError; -import com.yanzhenjie.nohttp.rest.ProtocolRequest; +import com.yanzhenjie.nohttp.rest.Request; import com.yanzhenjie.nohttp.rest.Response; import java.net.ConnectException; @@ -49,11 +49,11 @@ synchronized static RxNoHttp getRxNoHttp() { /** * 通过nohttp去请求 * - * @param mDialogGetListener dialog获取接口 + * @param mOnDialogGetListener dialog获取接口 * @param responseInterfa 请求成功或者失败回调对象 */ - void request(final ProtocolRequest request, DialogGetListener mDialogGetListener, final OnIsRequestListener responseInterfa, final String anUnknownErrorHint) { - final Dialog dialog = null == mDialogGetListener ? null : mDialogGetListener.getDialog(); + void request(final Request request, OnDialogGetListener mOnDialogGetListener, final OnIsRequestListener responseInterfa, final String anUnknownErrorHint) { + final Dialog dialog = null == mOnDialogGetListener ? null : mOnDialogGetListener.getDialog(); if (null != dialog && !dialog.isShowing()) { try { dialog.show(); diff --git a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxPollNoHttpConfig.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxPollNoHttpConfig.java index 9cf92fe..0c71715 100644 --- a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxPollNoHttpConfig.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxPollNoHttpConfig.java @@ -7,7 +7,7 @@ import com.liqi.nohttputils.nohttp.rx_poll.interfa.OnRxPollConfigBuilderListener; import com.liqi.nohttputils.nohttp.rx_poll.model.RxInformationModel; import com.liqi.nohttputils.nohttp.rx_poll.operators.OnObserverEventListener; -import com.yanzhenjie.nohttp.rest.RestRequest; +import com.yanzhenjie.nohttp.rest.Request; import io.reactivex.functions.Consumer; import io.reactivex.functions.Predicate; @@ -33,7 +33,7 @@ public class RxPollNoHttpConfig { /** * 被观察者产生的行为事件监听器 */ - private OnObserverEventListener, RxInformationModel> mOnObserverEventListener; + private OnObserverEventListener, RxInformationModel> mOnObserverEventListener; /** * 观察者根据被观察产生的行为做出相应处理监听器 */ @@ -66,7 +66,7 @@ public Consumer> getRxInformationModelAction1() { return mRxInformationModelAction1; } - public OnObserverEventListener, RxInformationModel> getOnObserverEventListener() { + public OnObserverEventListener, RxInformationModel> getOnObserverEventListener() { return mOnObserverEventListener; } @@ -145,7 +145,7 @@ public ConfigBuilder setRxInformationModelAction1(Consumer setOnObserverEventListener(OnObserverEventListener, RxInformationModel> onObserverEventListener) { + public OnRxPollConfigBuilderListener setOnObserverEventListener(OnObserverEventListener, RxInformationModel> onObserverEventListener) { mRxPollNoHttpConfig.mOnObserverEventListener = onObserverEventListener; return this; } diff --git a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestConfig.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestConfig.java index 6240cb6..1656a74 100644 --- a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestConfig.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestConfig.java @@ -4,7 +4,7 @@ import android.support.annotation.NonNull; import android.widget.ImageView; -import com.liqi.nohttputils.interfa.DialogGetListener; +import com.liqi.nohttputils.interfa.OnDialogGetListener; import com.liqi.nohttputils.interfa.OnIsRequestListener; import com.liqi.nohttputils.interfa.OnRequestRxNoHttpListener; import com.liqi.nohttputils.nohttp.interfa.OnToInputStreamEntityMethodListener; @@ -33,7 +33,7 @@ public class RxRequestConfig { private int mMaxHeight = -1; private Bitmap.Config mDecodeConfig; private ImageView.ScaleType mScaleType; - private DialogGetListener mDialogGetListener; + private OnDialogGetListener mOnDialogGetListener; private OnIsRequestListener mOnIsRequestListener; private Class mClazz; private Object mSign; @@ -131,8 +131,8 @@ public boolean isQueue() { return isQueue; } - public DialogGetListener getDialogGetListener() { - return mDialogGetListener = null == mDialogGetListener ? NoHttpInit.getNoHttpInit().getDialogGetListener() : mDialogGetListener; + public OnDialogGetListener getOnDialogGetListener() { + return mOnDialogGetListener = null == mOnDialogGetListener ? NoHttpInit.getNoHttpInit().getOnDialogGetListener() : mOnDialogGetListener; } public OnIsRequestListener getOnIsRequestListener() { @@ -179,7 +179,7 @@ public static class ConfigBuilder { /** * 加载框获取接口 */ - private DialogGetListener mDialogGetListener; + private OnDialogGetListener mOnDialogGetListener; /** * 请求标识 */ @@ -406,11 +406,11 @@ public ConfigBuilder setBitmapConfigType(Bitmap.Config config, ImageView.ScaleTy /** * 设置请求加载框 * - * @param dialogGetListener 加载框获取接口 + * @param onDialogGetListener 加载框获取接口 * @return */ - public ConfigBuilder setDialogGetListener(DialogGetListener dialogGetListener) { - mDialogGetListener = dialogGetListener; + public ConfigBuilder setOnDialogGetListener(OnDialogGetListener onDialogGetListener) { + mOnDialogGetListener = onDialogGetListener; return this; } @@ -621,7 +621,7 @@ private RxRequestConfig getRxRequestConfig(@NonNull Class clazz, OnIsR requestConfig.mMaxHeight = mMaxHeight; requestConfig.mDecodeConfig = mDecodeConfig; requestConfig.mScaleType = mScaleType; - requestConfig.mDialogGetListener = mDialogGetListener; + requestConfig.mOnDialogGetListener = mOnDialogGetListener; requestConfig.mSign = mSign; requestConfig.isQueue = isQueue; requestConfig.mConnectTimeout = mConnectTimeout; diff --git a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestOperate.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestOperate.java index 4aa3dac..188d338 100644 --- a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestOperate.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxRequestOperate.java @@ -10,7 +10,8 @@ import com.yanzhenjie.nohttp.Binary; import com.yanzhenjie.nohttp.Headers; import com.yanzhenjie.nohttp.Logger; -import com.yanzhenjie.nohttp.rest.RestRequest; +import com.yanzhenjie.nohttp.rest.Request; +import com.yanzhenjie.nohttp.ssl.SSLUtils; import java.io.File; import java.io.InputStream; @@ -59,8 +60,8 @@ private RxRequestOperate() { */ public void requestRxNoHttp() { if (mRxRequestConfig.isQueue()) { - RxRequestModel requestModel = new RxRequestModel<>(getRestRequest(), mRxRequestConfig.getOnIsRequestListener()); - requestModel.setDialogGetListener(mRxRequestConfig.getDialogGetListener()); + RxRequestModel requestModel = new RxRequestModel<>(getRequest(), mRxRequestConfig.getOnIsRequestListener()); + requestModel.setOnDialogGetListener(mRxRequestConfig.getOnDialogGetListener()); requestModel.setAnUnknownErrorHint(mRxRequestConfig.getAnUnknownErrorHint()); Object sign = mRxRequestConfig.getSign(); if (sign != null) { @@ -69,7 +70,7 @@ public void requestRxNoHttp() { RxThreadInterchange.getRxThreadInterchange().start(RxMessageSource.getRxMessageSource().add(requestModel)); } else { RxNoHttp.getRxNoHttp().request(addParameter(getTJavaBeanRequest(mRxRequestConfig.getShiftDataClazz())), - mRxRequestConfig.getDialogGetListener(), + mRxRequestConfig.getOnDialogGetListener(), mRxRequestConfig.getOnIsRequestListener(), mRxRequestConfig.getAnUnknownErrorHint()); } @@ -89,7 +90,7 @@ public RxRequestConfig getRxRequestConfig() { * * @return 请求参数对象 */ - public RestRequest getRestRequest() { + public Request getRequest() { return addParameter(getTJavaBeanRequest(mRxRequestConfig.getShiftDataClazz())); } @@ -99,7 +100,7 @@ public RestRequest getRestRequest() { * @param entityRequest 请求网络参数对象 * @return */ - private RestRequest addParameter(RestRequest entityRequest) { + private Request addParameter(Request entityRequest) { if (null != entityRequest) { Map parameterMap = mRxRequestConfig.getParameterMap(); //参数设置 @@ -213,7 +214,7 @@ private RestRequest addParameter(RestRequest entityRequest) { * @param entityRequest 参数对象 * @param mapHttps https参数集合 */ - private void mapValueHttps(RestRequest entityRequest, Map mapHttps) { + private void mapValueHttps(Request entityRequest, Map mapHttps) { for (Map.Entry entryHttps : mapHttps.entrySet()) { String keyHttps = entryHttps.getKey(); Object valueHttps = entryHttps.getValue(); @@ -222,7 +223,7 @@ private void mapValueHttps(RestRequest entityRequest, Map map if (null != valueHttps) { if (valueHttps instanceof InputStream) { InputStream inputStream = (InputStream) valueHttps; - entityRequest.setSSLSocketFactory(SSLContextUtil.getSSLContext(inputStream).getSocketFactory()); + entityRequest.setSSLSocketFactory(SSLUtils.fixSSLLowerThanLollipop(SSLContextUtil.getSSLContext(inputStream).getSocketFactory())); break; } else { Logger.e("Https集合需要证书值需要InputStream类型"); @@ -233,7 +234,7 @@ private void mapValueHttps(RestRequest entityRequest, Map map } //不需要证书 if (HTTPS_CERTIFICATE_NO.equals(keyHttps)) { - entityRequest.setSSLSocketFactory(SSLContextUtil.getDefaultSLLContext().getSocketFactory()); + entityRequest.setSSLSocketFactory(SSLContextUtil.getDefaultSLLContext()); entityRequest.setHostnameVerifier(SSLContextUtil.HOSTNAME_VERIFIER); break; } @@ -246,8 +247,8 @@ private void mapValueHttps(RestRequest entityRequest, Map map * @param clazz 请求网络返回对象 * @return */ - private RestRequest getTJavaBeanRequest(Class clazz) { - RestRequest ntityRequest; + private Request getTJavaBeanRequest(Class clazz) { + Request ntityRequest; if (clazz != Bitmap.class) { ntityRequest = new RequestBeanObj<>(mRxRequestConfig.getUrl(), mRxRequestConfig.getRequestMethod(), clazz); } else { diff --git a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxThreadInterchange.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxThreadInterchange.java index ffe5f17..8cfbdee 100644 --- a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxThreadInterchange.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxThreadInterchange.java @@ -9,7 +9,7 @@ import android.widget.Toast; import com.liqi.nohttputils.R; -import com.liqi.nohttputils.interfa.DialogGetListener; +import com.liqi.nohttputils.interfa.OnDialogGetListener; import com.liqi.nohttputils.interfa.OnIsRequestListener; import com.liqi.nohttputils.nohttp.rx_threadpool.interfa.OnRxMessageGetListener; import com.liqi.nohttputils.nohttp.rx_threadpool.model.BaseRxRequestModel; @@ -304,7 +304,7 @@ private void show(Dialog dialog, String hint) { * @return */ private Dialog getDialog(RxRequestModel baseRxRequestModel) { - DialogGetListener dialogGetListener = baseRxRequestModel.getDialogGetListener(); - return null == dialogGetListener ? null : dialogGetListener.getDialog(); + OnDialogGetListener onDialogGetListener = baseRxRequestModel.getOnDialogGetListener(); + return null == onDialogGetListener ? null : onDialogGetListener.getDialog(); } } diff --git a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxUtilsConfig.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxUtilsConfig.java index faacd94..0785b54 100644 --- a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxUtilsConfig.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/RxUtilsConfig.java @@ -3,7 +3,7 @@ import android.content.Context; import com.liqi.nohttputils.R; -import com.liqi.nohttputils.interfa.DialogGetListener; +import com.liqi.nohttputils.interfa.OnDialogGetListener; import com.yanzhenjie.nohttp.InitializationConfig; import com.yanzhenjie.nohttp.cookie.DBCookieStore; @@ -54,7 +54,7 @@ public class RxUtilsConfig { * 网络请求全局加载框获取接口 * (全项目请求默认加载框) */ - private DialogGetListener mDialogGetListener; + private OnDialogGetListener mOnDialogGetListener; /** * 下载线程池并发数量 */ @@ -102,8 +102,8 @@ String getAnUnknownErrorHint() { return mAnUnknownErrorHint; } - DialogGetListener getDialogGetListener() { - return mDialogGetListener; + OnDialogGetListener getOnDialogGetListener() { + return mOnDialogGetListener; } boolean isDebug() { @@ -305,11 +305,11 @@ public ConfigBuilder setThreadPoolSize(int threadPoolSize) { /** * 网络请求全局加载框获取接口 * - * @param dialogGetListener + * @param onDialogGetListener * @return */ - public ConfigBuilder setDialogGetListener(DialogGetListener dialogGetListener) { - mRxUtilsConfig.mDialogGetListener = dialogGetListener; + public ConfigBuilder setDialogGetListener(OnDialogGetListener onDialogGetListener) { + mRxUtilsConfig.mOnDialogGetListener = onDialogGetListener; return this; } diff --git a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/SSLContextUtil.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/SSLContextUtil.java index d1e7e72..b0751a2 100644 --- a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/SSLContextUtil.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/SSLContextUtil.java @@ -17,21 +17,19 @@ import android.annotation.SuppressLint; +import com.yanzhenjie.nohttp.ssl.SSLUtils; + import java.io.InputStream; import java.security.KeyStore; import java.security.SecureRandom; import java.security.cert.Certificate; -import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; -import javax.net.ssl.TrustManager; +import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManagerFactory; -import javax.net.ssl.X509TrustManager; /** * Https协议证书工具类 @@ -40,27 +38,7 @@ */ public class SSLContextUtil { - static final HostnameVerifier HOSTNAME_VERIFIER = new HostnameVerifier() { - public boolean verify(String hostname, SSLSession session) { - return true; - } - }; - private static TrustManager trustManagers = new X509TrustManager() { - - @Override - public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { - } - - @Override - public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { - - } - - @Override - public X509Certificate[] getAcceptedIssuers() { - return new X509Certificate[0]; - } - }; + static final HostnameVerifier HOSTNAME_VERIFIER = SSLUtils.defaultHostnameVerifier(); /** * 拿到https证书, SSLContext (NoHttp已经修补了系统的SecureRandom的bug)。 @@ -95,15 +73,8 @@ static SSLContext getSSLContext(InputStream inputStream) { /** * 如果不需要https证书.(NoHttp已经修补了系统的SecureRandom的bug)。 */ - static SSLContext getDefaultSLLContext() { - SSLContext sslContext = null; - try { - sslContext = SSLContext.getInstance("TLS"); - sslContext.init(null, new TrustManager[]{trustManagers}, new SecureRandom()); - } catch (Exception e) { - e.printStackTrace(); - } - return sslContext; + static SSLSocketFactory getDefaultSLLContext() { + return SSLUtils.defaultSSLSocketFactory(); } } diff --git a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/RxPollUtils.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/RxPollUtils.java index 8f7585b..6c7284a 100644 --- a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/RxPollUtils.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/RxPollUtils.java @@ -11,7 +11,7 @@ import com.liqi.nohttputils.nohttp.rx_poll.model.RxInformationPoolModel; import com.liqi.nohttputils.nohttp.rx_poll.operators.OnObserverEventListener; import com.liqi.nohttputils.nohttp.rx_poll.pond.RxInformationPool; -import com.yanzhenjie.nohttp.rest.RestRequest; +import com.yanzhenjie.nohttp.rest.Request; import java.util.concurrent.TimeUnit; @@ -57,7 +57,7 @@ public void requestRxNoHttp() { RxInformationPoolModel informationPoolModel = new RxInformationPoolModel<>( rxRequestConfig.getOnIsRequestListener(), - rxRequestConfig.getDialogGetListener(), + rxRequestConfig.getOnDialogGetListener(), rxRequestConfig.getAnUnknownErrorHint()); Object sign = rxRequestConfig.getSign(); if (null != sign) { @@ -76,7 +76,7 @@ public void requestRxNoHttp() { } //赋值被观察者处理事件 - OnObserverEventListener, RxInformationModel> onObserverEventListener = mRxPollNoHttpConfig.getOnObserverEventListener(); + OnObserverEventListener, RxInformationModel> onObserverEventListener = mRxPollNoHttpConfig.getOnObserverEventListener(); if (null != onObserverEventListener) { informationPoolModel.setOnObserverEventListener(onObserverEventListener); } @@ -90,7 +90,7 @@ public void requestRxNoHttp() { mRxPollNoHttpConfig.getPeriod(), TimeUnit.MILLISECONDS, informationPoolModel.getOnObserverEventListener()) - .subscribeOn(Schedulers.io(), rxRequestOperate.getRestRequest()) + .subscribeOn(Schedulers.io(), rxRequestOperate.getRequest()) .takeUntil(informationPoolModel.getBooleanFunc1()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(informationPoolModel.getRxInformationModelAction1()); diff --git a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/model/RxInformationPoolModel.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/model/RxInformationPoolModel.java index bd83816..9ab2845 100644 --- a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/model/RxInformationPoolModel.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_poll/model/RxInformationPoolModel.java @@ -8,7 +8,7 @@ import android.widget.Toast; import com.liqi.nohttputils.R; -import com.liqi.nohttputils.interfa.DialogGetListener; +import com.liqi.nohttputils.interfa.OnDialogGetListener; import com.liqi.nohttputils.interfa.OnIsRequestListener; import com.liqi.nohttputils.nohttp.rx_poll.operators.OnObserverEventListener; import com.yanzhenjie.nohttp.Logger; @@ -19,7 +19,7 @@ import com.yanzhenjie.nohttp.error.URLError; import com.yanzhenjie.nohttp.error.UnKnownHostError; import com.yanzhenjie.nohttp.rest.Response; -import com.yanzhenjie.nohttp.rest.RestRequest; +import com.yanzhenjie.nohttp.rest.Request; import java.net.ConnectException; import java.net.ProtocolException; @@ -35,19 +35,19 @@ public class RxInformationPoolModel { private Object mSign; - private DialogGetListener mDialogGetListener; - private RestRequest mRestRequest; + private OnDialogGetListener mOnDialogGetListener; + private Request mRequest; private OnIsRequestListener mOnIsRequestListener; private RxInformationModel mRxInformationModel; private Predicate> mBooleanFunc1; - private OnObserverEventListener, RxInformationModel> mOnObserverEventListener; + private OnObserverEventListener, RxInformationModel> mOnObserverEventListener; private Consumer> mRxInformationModelAction1; - public RxInformationPoolModel(@NonNull OnIsRequestListener onIsRequestListener, DialogGetListener dialogGetListener, String anUnknownErrorHint) { + public RxInformationPoolModel(@NonNull OnIsRequestListener onIsRequestListener, OnDialogGetListener onDialogGetListener, String anUnknownErrorHint) { mOnIsRequestListener = onIsRequestListener; - mDialogGetListener = dialogGetListener; + mOnDialogGetListener = onDialogGetListener; mRxInformationModel = new RxInformationModel<>(); initOnObserverEventListener(); initBooleanFunc1(); @@ -64,9 +64,9 @@ private void initRxInformationModelAction1(final String anUnknownErrorHint) { mRxInformationModelAction1 = new Consumer>() { @Override public void accept(RxInformationModel tRxInformationModel) throws Exception { - Logger.e(mRestRequest.url() + ":轮询运行完毕"); + Logger.e(mRequest.url() + ":轮询运行完毕"); - Dialog dialog = null == mDialogGetListener ? null : mDialogGetListener.getDialog(); + Dialog dialog = null == mOnDialogGetListener ? null : mOnDialogGetListener.getDialog(); if (null != dialog && dialog.isShowing()) { dialog.dismiss(); } @@ -119,7 +119,7 @@ public void accept(RxInformationModel tRxInformationModel) throws Exception { } } } else { - Logger.e(mRestRequest.url() + ":取消轮询请求线程"); + Logger.e(mRequest.url() + ":取消轮询请求线程"); } } }; @@ -137,7 +137,7 @@ public boolean test(RxInformationModel tRxInformationModel) throws Exception tRxInformationModel = new RxInformationModel<>(); tRxInformationModel.setStop(true); } - Logger.e(mRestRequest.url() + ":轮询运行拦截>>拦截状态:" + tRxInformationModel.isStop()); + Logger.e(mRequest.url() + ":轮询运行拦截>>拦截状态:" + tRxInformationModel.isStop()); return tRxInformationModel.isStop(); } }; @@ -147,26 +147,26 @@ public boolean test(RxInformationModel tRxInformationModel) throws Exception * 内部实现轮询操作处理 */ private void initOnObserverEventListener() { - mOnObserverEventListener = new OnObserverEventListener, RxInformationModel>() { + mOnObserverEventListener = new OnObserverEventListener, RxInformationModel>() { @Override - public RxInformationModel onObserverEvent(RestRequest restRequest) { - mRestRequest = restRequest; + public RxInformationModel onObserverEvent(Request Request) { + mRequest = Request; initTransitionModel(); - if (null != mDialogGetListener) { + if (null != mOnDialogGetListener) { //对话框放到主线程去运行 AndroidSchedulers.mainThread().createWorker().schedule(new Runnable() { @Override public void run() { - Dialog dialog = mDialogGetListener.getDialog(); + Dialog dialog = mOnDialogGetListener.getDialog(); if (null != dialog) { dialog.show(); } } }); } - if (null != mRestRequest) { - Logger.e(mRestRequest.url() + ":轮询运行开始"); - Response response = NoHttp.startRequestSync(mRestRequest); + if (null != mRequest) { + Logger.e(mRequest.url() + ":轮询运行开始"); + Response response = NoHttp.startRequestSync(mRequest); //正确 if (response.isSucceed() || response.isFromCache()) { mRxInformationModel.setData(response.get()); @@ -211,7 +211,7 @@ public void setBooleanFunc1(Predicate> booleanFunc1) { * * @return 可观察者事件对象 */ - public OnObserverEventListener, RxInformationModel> getOnObserverEventListener() { + public OnObserverEventListener, RxInformationModel> getOnObserverEventListener() { return mOnObserverEventListener; } @@ -220,7 +220,7 @@ public OnObserverEventListener, RxInformationModel> getOnObser * * @param onObserverEventListener 可观察者事件对象 */ - public void setOnObserverEventListener(OnObserverEventListener, RxInformationModel> onObserverEventListener) { + public void setOnObserverEventListener(OnObserverEventListener, RxInformationModel> onObserverEventListener) { mOnObserverEventListener = onObserverEventListener; } @@ -266,8 +266,8 @@ public void setSign(Object sign) { * 取消请求 */ public void cancel() { - if (null != mRestRequest) { - mRestRequest.cancel(); + if (null != mRequest) { + mRequest.cancel(); } setRxPollStopState(true); } diff --git a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/model/RxRequestModel.java b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/model/RxRequestModel.java index 50bf50c..ccaa145 100644 --- a/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/model/RxRequestModel.java +++ b/nohttputils-r2/src/main/java/com/liqi/nohttputils/nohttp/rx_threadpool/model/RxRequestModel.java @@ -2,12 +2,12 @@ import android.support.annotation.NonNull; -import com.liqi.nohttputils.interfa.DialogGetListener; +import com.liqi.nohttputils.interfa.OnDialogGetListener; import com.liqi.nohttputils.interfa.OnIsRequestListener; import com.yanzhenjie.nohttp.Logger; import com.yanzhenjie.nohttp.NoHttp; import com.yanzhenjie.nohttp.rest.Response; -import com.yanzhenjie.nohttp.rest.RestRequest; +import com.yanzhenjie.nohttp.rest.Request; /** @@ -16,8 +16,8 @@ */ public class RxRequestModel extends BaseRxRequestModel { - private DialogGetListener mDialogGetListener; - private RestRequest mRestRequest; + private OnDialogGetListener mOnDialogGetListener; + private Request mRequest; private OnIsRequestListener mOnIsRequestListener; private Object mSign; //未知错误提示语 @@ -27,8 +27,8 @@ private RxRequestModel() { } - public RxRequestModel(@NonNull RestRequest restRequest, @NonNull OnIsRequestListener onIsRequestListener) { - mRestRequest = restRequest; + public RxRequestModel(@NonNull Request Request, @NonNull OnIsRequestListener onIsRequestListener) { + mRequest = Request; mOnIsRequestListener = onIsRequestListener; } @@ -44,7 +44,7 @@ public void setAnUnknownErrorHint(String anUnknownErrorHint) { * 释放当前对象内存 */ public void clear() { - mDialogGetListener = null; + mOnDialogGetListener = null; mOnIsRequestListener = null; mSign = null; } @@ -54,7 +54,7 @@ public void clear() { */ public void clearAll() { clear(); - mRestRequest = null; + mRequest = null; } /** @@ -64,7 +64,7 @@ public void clearAll() { * @return */ public boolean isCancel(@NonNull Object sign) { - if (null != mRestRequest) { + if (null != mRequest) { if (mSign == sign) { return true; } @@ -77,18 +77,18 @@ public void setSign(@NonNull Object sign) { } public void cancel() { - if (null != mRestRequest) { - mRestRequest.cancel(); + if (null != mRequest) { + mRequest.cancel(); setRunOff(true); } } - public DialogGetListener getDialogGetListener() { - return mDialogGetListener; + public OnDialogGetListener getOnDialogGetListener() { + return mOnDialogGetListener; } - public RxRequestModel setDialogGetListener(DialogGetListener dialogGetListener) { - mDialogGetListener = dialogGetListener; + public RxRequestModel setOnDialogGetListener(OnDialogGetListener onDialogGetListener) { + mOnDialogGetListener = onDialogGetListener; return this; } @@ -98,14 +98,14 @@ public OnIsRequestListener getOnIsRequestListener() { @Override protected T run() { - if (null != mRestRequest) { - Logger.e(mRestRequest.url() + "线程运行>>>"); - Response response = NoHttp.startRequestSync(mRestRequest); + if (null != mRequest) { + Logger.e(mRequest.url() + "线程运行>>>"); + Response response = NoHttp.startRequestSync(mRequest); if (response.isSucceed() || response.isFromCache()) { if (!isRunOff()) { return response.get(); } else { - setThrowable(new Exception(mRestRequest.url() + " -->撤销请求")); + setThrowable(new Exception(mRequest.url() + " -->撤销请求")); } } else { setThrowable(response.getException()); @@ -113,6 +113,6 @@ protected T run() { } else { setThrowable(new NullPointerException()); } - return (T) mRestRequest.url(); + return (T) mRequest.url(); } } diff --git a/sample/src/main/java/com/liqi/nohttprxutils/FileUploadingDemoActivity.java b/sample/src/main/java/com/liqi/nohttprxutils/FileUploadingDemoActivity.java index c4c4ddc..6eb3c70 100644 --- a/sample/src/main/java/com/liqi/nohttprxutils/FileUploadingDemoActivity.java +++ b/sample/src/main/java/com/liqi/nohttprxutils/FileUploadingDemoActivity.java @@ -10,8 +10,8 @@ import com.liqi.nohttprxutils.base.BaseActivity; import com.liqi.nohttprxutils.utils.FileUtil; -import com.liqi.nohttputils.nohttp.BinaryFactory; import com.liqi.nohttputils.RxNoHttpUtils; +import com.liqi.nohttputils.nohttp.BinaryFactory; import com.yanzhenjie.nohttp.BasicBinary; import com.yanzhenjie.nohttp.Binary; import com.yanzhenjie.nohttp.OnUploadListener; @@ -106,10 +106,11 @@ public void onClick(View v) { //开始请求 RxNoHttpUtils.rxNohttpRequest() .post() - .url(StaticHttpUrl.UPLOAD_URL) - .addParameter("user","LiQi") - .addParameter("image1",getBinaries()) - .setDialogGetListener(this) + .url(StaticHttpUrl.UPLOAD_FORM) + .addParameter("name","nohttp") + .addParameter("age", 18) + .addParameter("file1",getBinaries().get(0)) + .setOnDialogGetListener(this) .builder(String.class,this) .requestRxNoHttp(); } else { diff --git a/sample/src/main/java/com/liqi/nohttprxutils/GetPostDemoActivity.java b/sample/src/main/java/com/liqi/nohttprxutils/GetPostDemoActivity.java index e6b97cd..da8f460 100644 --- a/sample/src/main/java/com/liqi/nohttprxutils/GetPostDemoActivity.java +++ b/sample/src/main/java/com/liqi/nohttprxutils/GetPostDemoActivity.java @@ -38,8 +38,10 @@ public void onClick(View v) { //开始请求 RxNoHttpUtils.rxNohttpRequest() .get() - .url(StaticHttpUrl.getGetUrl("LiQi1", "LiQi1.pass", 20, "1")) - .setDialogGetListener(this) + .url(StaticHttpUrl.LOGIN) + .addParameter("pageNum",1) + .addParameter("pageSize",10) + .setOnDialogGetListener(this) .setQueue(false) //单个请求设置读取时间(单位秒,默认以全局读取超时时间。) // .setReadTimeout(40) @@ -86,12 +88,10 @@ public void onClick(View v) { //开始请求 RxNoHttpUtils.rxNohttpRequest() .post() - .url(StaticHttpUrl.POST_URL) - .addParameter("userName", "LiQi") - .addParameter("userPass", "LiQi.pass") - .addParameter("userAge", 20) - .addParameter("userSex", "1") - .setDialogGetListener(this) + .url(StaticHttpUrl.LOGIN) + .addParameter("pageNum",1) + .addParameter("pageSize",10) + .setOnDialogGetListener(this) .setSign(this) .setAnUnknownErrorHint("POST未知错误提示") .builder(String.class, this) diff --git a/sample/src/main/java/com/liqi/nohttprxutils/HttpsDemoActivity.java b/sample/src/main/java/com/liqi/nohttprxutils/HttpsDemoActivity.java index 79ef13b..8c9094a 100644 --- a/sample/src/main/java/com/liqi/nohttprxutils/HttpsDemoActivity.java +++ b/sample/src/main/java/com/liqi/nohttprxutils/HttpsDemoActivity.java @@ -40,7 +40,7 @@ public void onClick(View v) { .post() .url(StaticHttpUrl.HTTPS_URL) .addHttpsIsCertificate(inputStream) - .setDialogGetListener(this) + .setOnDialogGetListener(this) .builder(String.class,this) .requestRxNoHttp(); } catch (IOException e) { @@ -54,7 +54,7 @@ public void onClick(View v) { .post() .url(StaticHttpUrl.HTTPS_URL) .addHttpsIsCertificate() - .setDialogGetListener(this) + .setOnDialogGetListener(this) .builder(String.class,this) .requestRxNoHttp(); break; diff --git a/sample/src/main/java/com/liqi/nohttprxutils/ImageDownloadDemoActivity.java b/sample/src/main/java/com/liqi/nohttprxutils/ImageDownloadDemoActivity.java index 8e726cc..d36144e 100644 --- a/sample/src/main/java/com/liqi/nohttprxutils/ImageDownloadDemoActivity.java +++ b/sample/src/main/java/com/liqi/nohttprxutils/ImageDownloadDemoActivity.java @@ -36,8 +36,8 @@ public void onClick(View v) { //开始请求 RxNoHttpUtils.rxNohttpRequest() .get() - .url(StaticHttpUrl.IMAGE_URL) - .setDialogGetListener(this) + .url(StaticHttpUrl.IMAGE_GET) + .setOnDialogGetListener(this) .setSign(this) .builder(Bitmap.class, this) .requestRxNoHttp(); diff --git a/sample/src/main/java/com/liqi/nohttprxutils/PollDemo.java b/sample/src/main/java/com/liqi/nohttprxutils/PollDemo.java index cda3852..9eed931 100644 --- a/sample/src/main/java/com/liqi/nohttprxutils/PollDemo.java +++ b/sample/src/main/java/com/liqi/nohttprxutils/PollDemo.java @@ -10,7 +10,7 @@ import com.liqi.nohttputils.interfa.OnIsRequestListener; import com.liqi.nohttputils.nohttp.rx_poll.model.RxInformationModel; import com.liqi.nohttputils.nohttp.rx_poll.operators.OnObserverEventListener; -import com.yanzhenjie.nohttp.rest.RestRequest; +import com.yanzhenjie.nohttp.rest.Request; import io.reactivex.functions.Consumer; import io.reactivex.functions.Predicate; @@ -61,11 +61,9 @@ public void onClick(View v) { //开始轮询请求 --->>线程1111 RxNoHttpUtils.rxNohttpRequest() .post() - .url(StaticHttpUrl.POST_URL) - .addParameter("userName", "LiQi") - .addParameter("userPass", "LiQi.pass") - .addParameter("userAge", 20) - .addParameter("userSex", "1") + .url(StaticHttpUrl.LOGIN) + .addParameter("pageNum",1) + .addParameter("pageSize",10) // .setDialogGetListener(this) .setSign(mSign[0]) //构建轮询请求 @@ -95,11 +93,9 @@ public void onError(Throwable e) { //开始轮询请求 --->>线程2222 RxNoHttpUtils.rxNohttpRequest() .post() - .url(StaticHttpUrl.POST_URL) - .addParameter("userName", "LiQi") - .addParameter("userPass", "LiQi.pass") - .addParameter("userAge", 20) - .addParameter("userSex", "1") + .url(StaticHttpUrl.LOGIN) + .addParameter("pageNum",1) + .addParameter("pageSize",10) // .setDialogGetListener(this) .setSign(mSign[1]) //构建轮询请求 @@ -130,11 +126,9 @@ public void onError(Throwable e) { //开始轮询请求 --->>线程3333 RxNoHttpUtils.rxNohttpRequest() .post() - .url(StaticHttpUrl.POST_URL) - .addParameter("userName", "LiQi") - .addParameter("userPass", "LiQi.pass") - .addParameter("userAge", 20) - .addParameter("userSex", "1") + .url(StaticHttpUrl.LOGIN) + .addParameter("pageNum",1) + .addParameter("pageSize",10) //.setDialogGetListener(this) .setSign(mSign[2]) //构建轮询请求 @@ -173,11 +167,9 @@ public void onError(Throwable e) { //开始自定义轮询 RxNoHttpUtils.rxNohttpRequest() .post() - .url(StaticHttpUrl.POST_URL) - .addParameter("userName", "LiQi") - .addParameter("userPass", "LiQi.pass") - .addParameter("userAge", 20) - .addParameter("userSex", "1") + .url(StaticHttpUrl.LOGIN) + .addParameter("pageNum",1) + .addParameter("pageSize",10) .setAnUnknownErrorHint("Poll自定义请求未知错误提示") //.setDialogGetListener(this) .setSign(this) @@ -202,9 +194,9 @@ public void onError(Throwable e) { .setInitialDelay(3 * 1000) .setPeriod(5 * 1000) - .setOnObserverEventListener(new OnObserverEventListener, RxInformationModel>() { + .setOnObserverEventListener(new OnObserverEventListener, RxInformationModel>() { @Override - public RxInformationModel onObserverEvent(RestRequest transferValue) { + public RxInformationModel onObserverEvent(Request transferValue) { Log.e("外部实现轮询运行","外部实现轮询运行开始>>>"); RxInformationModel informationModel=new RxInformationModel<>(); informationModel.setData("<<<外部现实轮询>>>"); diff --git a/sample/src/main/java/com/liqi/nohttprxutils/RequestQueueDemoActivity.java b/sample/src/main/java/com/liqi/nohttprxutils/RequestQueueDemoActivity.java index 5fc4457..3851487 100644 --- a/sample/src/main/java/com/liqi/nohttprxutils/RequestQueueDemoActivity.java +++ b/sample/src/main/java/com/liqi/nohttprxutils/RequestQueueDemoActivity.java @@ -44,7 +44,9 @@ public void onClick(View v) { //发送多个请求 RxNoHttpUtils.rxNohttpRequest() .get() - .url(StaticHttpUrl.getGetUrl("LiQi" + i + "" + i + "" + i, "LiQi.pass", 20, "1")) + .url(StaticHttpUrl.LOGIN) + .addParameter("pageNum",1) + .addParameter("pageSize",10) .setSign(mSign[i]) .builder(String.class, this) .requestRxNoHttp(); diff --git a/sample/src/main/java/com/liqi/nohttprxutils/StaticHttpUrl.java b/sample/src/main/java/com/liqi/nohttprxutils/StaticHttpUrl.java index 90ef17b..1781e6b 100644 --- a/sample/src/main/java/com/liqi/nohttprxutils/StaticHttpUrl.java +++ b/sample/src/main/java/com/liqi/nohttprxutils/StaticHttpUrl.java @@ -5,27 +5,20 @@ * Created by LiQi on 2016/12/30. */ public class StaticHttpUrl { - private static final String HTTP_URL = "http://api.nohttp.net/"; - private static final String GET_URL = HTTP_URL + "method?"; - public static final String POST_URL = HTTP_URL + "method"; - public static final String IMAGE_URL = HTTP_URL + "image"; - public static final String UPLOAD_URL= HTTP_URL + "upload"; + private static final String HTTP_URL = "http://kalle.nohttp.net/"; + /** + * Login. + */ + public static final String LOGIN = HTTP_URL + "/login"; + + public static final String IMAGE_GET ="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1541153455963&di=8830bd21c6f786f0b425e6c9d41e709f&imgtype=0&src=http%3A%2F%2Fimg3.redocn.com%2Ftupian%2F20150106%2Faixinxiangkuang_3797284.jpg"; + + /** + * Form. + */ + public static final String UPLOAD_FORM = HTTP_URL + "upload/form"; + public static final String HTTPS_URL="https://kyfw.12306.cn/otn"; //图片文件存储本地路径 public static final String FILE_PATH="/LiQi_nohttp_utils"; - /** - * 获取get请求拼接的URL地址 - * - * @param userName - * @param userPass - * @param userAge - * @param userSex - * @return - */ - public static String getGetUrl(String userName, String userPass, int userAge, String userSex) { - String getHttpUrl = GET_URL + "userName=" - + userName + "&userPass=" - + userPass + "&userAge=" + userAge + "&userSex=" + userSex; - return getHttpUrl; - } } diff --git a/sample/src/main/java/com/liqi/nohttprxutils/base/BaseActivity.java b/sample/src/main/java/com/liqi/nohttprxutils/base/BaseActivity.java index c56b8a0..5899201 100644 --- a/sample/src/main/java/com/liqi/nohttprxutils/base/BaseActivity.java +++ b/sample/src/main/java/com/liqi/nohttprxutils/base/BaseActivity.java @@ -7,7 +7,7 @@ import android.view.View; import android.view.Window; -import com.liqi.nohttputils.interfa.DialogGetListener; +import com.liqi.nohttputils.interfa.OnDialogGetListener; import com.liqi.nohttputils.interfa.OnIsRequestListener; @@ -16,7 +16,7 @@ * 个人QQ:543945827 * Created by LiQi on 2016/12/30. */ -public abstract class BaseActivity extends AppCompatActivity implements DialogGetListener, OnIsRequestListener { +public abstract class BaseActivity extends AppCompatActivity implements OnDialogGetListener, OnIsRequestListener { protected ProgressDialog mDialog; @Override diff --git a/sample/src/main/java/com/liqi/nohttprxutils/download/DownloadFileActivity.java b/sample/src/main/java/com/liqi/nohttprxutils/download/DownloadFileActivity.java index feba813..96cc511 100644 --- a/sample/src/main/java/com/liqi/nohttprxutils/download/DownloadFileActivity.java +++ b/sample/src/main/java/com/liqi/nohttprxutils/download/DownloadFileActivity.java @@ -13,6 +13,7 @@ import com.liqi.nohttprxutils.utils.FileUtil; import com.liqi.nohttputils.download.NohttpDownloadUtils; import com.yanzhenjie.nohttp.Headers; +import com.yanzhenjie.nohttp.Logger; import com.yanzhenjie.nohttp.download.DownloadListener; import com.yanzhenjie.nohttp.error.NetworkError; import com.yanzhenjie.nohttp.error.ServerError; @@ -38,9 +39,9 @@ public class DownloadFileActivity extends AppCompatActivity implements View.OnCl //存储文件夹路径 private final String FILEPATH = FileUtil.getRootPath().getAbsolutePath() + StaticHttpUrl.FILE_PATH + "/DownloadFile"; //文件下载路径 - private String DOWNLOAD_FILE01 = "http://api.nohttp.net/download/1.apk", - DOWNLOAD_FILE02 = "http://api.nohttp.net/download/2.apk", - DOWNLOAD_FILE03 = "http://api.nohttp.net/download/3.apk"; + private String DOWNLOAD_FILE01 = "http://wap.dl.pinyin.sogou.com/wapdl/android/apk/SogouInput_android_v8.18_sweb.apk", + DOWNLOAD_FILE02 = "http://wap.dl.pinyin.sogou.com/wapdl/android/apk/SogouInput_android_v8.18_sweb.apk", + DOWNLOAD_FILE03 = "http://wap.dl.pinyin.sogou.com/wapdl/android/apk/SogouInput_android_v8.10_sweb.apk"; private ProgressBar mDownloadSingleProgress; private TextView mDownloadSingleHint; private Button mDownloadSingleButton; @@ -83,7 +84,7 @@ public void onClick(View v) { //把要下载的请求添加到下载服务队列中,并开始下载 if (mSingleInit == -1) { NohttpDownloadUtils.getNohttpDownloadBuild() - .addDownloadParameter(DOWNLOAD_FILE01, "Liqi_single_test.apk") + .addDownloadParameter(DOWNLOAD_FILE01, "") .setRange(true) .setDownloadListener(this) .setDeleteOld(false) @@ -226,6 +227,9 @@ private void downloadHint(int what, String hint, boolean tag) { mDownloadMultiButton.setEnabled(false); } } + Logger.e("What值:" + NohttpDownloadUtils.getDownloadRequestsWhat(DOWNLOAD_FILE01)); + Logger.e("路径值:" + NohttpDownloadUtils.getDownloadRequestsUrl(NohttpDownloadUtils.getDownloadRequestsWhat(DOWNLOAD_FILE01))); + Logger.e("\n回调路径值:" + NohttpDownloadUtils.getDownloadRequestsUrl(what)); } private void setProgress(int what, int progress, long speed) { From 7f5874508f1d4403a12839061663c6dab4bd8b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A5=87?= <543945827@qq.com> Date: Fri, 2 Nov 2018 18:57:58 +0800 Subject: [PATCH 10/11] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 71b32f4..5bd5173 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [中文版文档](https://github.com/LiqiNew/NoHttpRxUtils/blob/master/README_CHINESE.md)

[![](https://jitpack.io/v/liqinew/nohttprxutils.svg)](https://jitpack.io/#liqinew/nohttprxutils) [![](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-%E6%9D%8E%E5%A5%87-orange.svg)](https://github.com/LiqiNew) -
**---- v.2.0.6 New in version ----** +
**---- v.2.0.7 New in version ----** * **Compatible to NoHttp-v.1.1.11** * **Repair BUG**Fix bug that download file is not available because the file name was not passed in at the time of download * **NohttpDownloadUtils** File download tool object added (getDownloadRequestsUrl() Get the path method corresponding to the download request What value) @@ -77,7 +77,7 @@ compile 'com.github.liqinew:nohttprxutils:v.2.0.5' * RxJava-2 project depends on ```gradle -compile 'com.github.liqinew:nohttprxutils:v.2.0.6' +compile 'com.github.liqinew:nohttprxutils:v.2.0.7' ``` NoHttpRxUtils use method ----- From 39ce7569681398b123cf35998e14e3c78c57aed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A5=87?= <543945827@qq.com> Date: Fri, 2 Nov 2018 18:58:49 +0800 Subject: [PATCH 11/11] Update README_CHINESE.md --- README_CHINESE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README_CHINESE.md b/README_CHINESE.md index 954a18e..f7cbf2f 100644 --- a/README_CHINESE.md +++ b/README_CHINESE.md @@ -1,6 +1,6 @@ [![](https://jitpack.io/v/liqinew/nohttprxutils.svg)](https://jitpack.io/#liqinew/nohttprxutils) [![](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-%E6%9D%8E%E5%A5%87-orange.svg)](https://github.com/LiqiNew) -
**---- v.2.0.6版本新增功能 ----** +
**---- v.2.0.7版本新增功能 ----** * **兼容到NoHttp-v.1.1.11** * **修复BUG**修复因为下载时未传入文件名称而导致下载文件不可用的BUG * **NohttpDownloadUtils** 文件下载工具对象新增(getDownloadRequestsUrl()获取下载请求What值对应的路径方法) @@ -77,7 +77,7 @@ compile 'com.github.liqinew:nohttprxutils:v.2.0.5' * 使用RxJava-2的项目请依赖 ```gradle -compile 'com.github.liqinew:nohttprxutils:v.2.0.6' +compile 'com.github.liqinew:nohttprxutils:v.2.0.7' ``` NoHttpRxUtils使用简介