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) {