Skip to content

Commit

Permalink
Support rxjava-1 and rxjava2
Browse files Browse the repository at this point in the history
Support rxjava-1 and rxjava2
  • Loading branch information
liqi committed Nov 16, 2017
1 parent aed8c25 commit 3fc5c83
Show file tree
Hide file tree
Showing 113 changed files with 6,077 additions and 139 deletions.
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[中文版文档](https://github.com/LiqiNew/NoHttpRxUtils/blob/master/README_CHINESE.md) <br><br>
[![](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)
### Because NoHttpRxUtils through the RxJava-1 face NoHttp network framework for a series of bundle.First of all against RxJava and NoHttp network framework to do a brief introduction
### 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.<br>
In a responsive programming, when the data arrives, the consumer responds.<br>
Expand Down Expand Up @@ -30,7 +30,7 @@ Support breakpoint upload and breakpoint download.<br><br>
[NoHttp Frame GitHub(Zhenjie Yan)](https://github.com/yanzhenjie/NoHttp)

# What is the NoHttpRxUtils framework?
NoHttpRxUtils is mainly through the RxJava-1 framework for 'NoHttp' network framework operation re-encapsulation.<br>
NoHttpRxUtils is mainly through the RxJava framework for 'NoHttp' network framework operation re-encapsulation.<br>
Reduce the user's cumbersome calls, so that users are more focused on the project business, rather than the client and the server network communication between.<br>
Since the 'NoHttpRxUtils' network request is a 'NoHttp' synchronization request, the request queue is not a 'NoHttp' queue algorithm but a 'NoHttpRxUtils' queue algorithm.<br>
Sorry, the queue request priority setting is not supported at this time. If you want to make a request priority, you can use the RxJava thread single request.<br>
Expand All @@ -47,7 +47,7 @@ Sorry, because the Android system to write permissions on the SD card constraint
* Support the use of other network framework to polling requests.

# For your use more clarity, please read the following tutorials carefully.
##### RxJava in the internal use of the version is RxJava-1.1.9
##### RxJava in the internal use of the version is RxJava-1.1.9 and RxJava-2.1.5
##### NoHttp in the internal use of the version is NoHttp-1.1.4
##### Gson in the internal use of the version is Gson-2.8.0

Expand All @@ -64,11 +64,16 @@ repositories {
}
```

**2:The project directory build.gradle relies on the NohttpRxUtils framework**<br>
**2:The project directory build.gradle relies on the NoHttpRxUtils framework**<br>
* RxJava-1 project depends on
```gradle
compile 'com.github.liqinew:nohttprxutils:v.1.3.4'
```

* RxJava-2 project depends on
```gradle
compile 'com.github.liqinew:nohttprxutils:v.1.3.4'
```
NoHttpRxUtils use method
-----
### Chained mode call initialization NoHttp, suggested to the Application onCreate life cycle method inside.
Expand Down Expand Up @@ -132,7 +137,10 @@ NoHttpRxUtils use method

//Sets the number of global request failed retries.
//.setRetry(5)


//Set global request network appears unknown error hint message
.setAnUnknownErrorHint("Global unknown error hint message")

//Start initialization.
.startInit();
```
Expand Down Expand Up @@ -320,7 +328,10 @@ RxNoHttpUtils.rxNoHttpRequest()
//Note: If you do not set the load box here, then the default use of the global settings of the load box.
//If the global setting does not set the load box, then the load box and built-in prompts are not displayed.
.setDialogGetListener(new Dialog())


//Set request network appears unknown error hint message
.setAnUnknownErrorHint("Unknown error hint message")

//Create the request object to specify the response data conversion type,
//and then set the request to succeed or fail the callback interface.
.builder(Objects.class,new OnIsRequestListener<T>)
Expand Down Expand Up @@ -368,6 +379,7 @@ RxNoHttpUtils.rxNoHttpRequest()
//Note: If the behavioral event listener is implemented here,
//then the polling request is not maintained inside the framework,
//and the polling interceptor interface must be implemented to maintain the polling stop.
//RxNoHttpUtils.cancelPoll () cancel polling will be invalid, set the internal loading box will be invalid.
.setOnObserverEventListener(new OnObserverEventListener<RestRequest<T>, RxInformationModel<T>>(){
@Override
public RxInformationModel<T> onObserverEvent(RestRequest<T> transferValue) {
Expand Down
27 changes: 20 additions & 7 deletions README_CHINESE.md
Original file line number Diff line number Diff line change
@@ -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)
### 由于NoHttpRxUtils是通过RxJava-1对NoHttp网络框架操作进行一系列封装。<br>首先对RxJava和NoHttp网络框架做一个简介
### 由于NoHttpRxUtils是通过RxJava对NoHttp网络框架操作进行一系列封装。<br>首先对RxJava和NoHttp网络框架做一个简介
# RxJava框架是什么?
RxJava是响应式程序设计的一种实现。<br>
在响应式程序设计中,当数据到达的时候,消费者做出响应。<br>
Expand Down Expand Up @@ -29,7 +29,7 @@ GET、POST、PUT、PATCH、HEAD、DELETE、OPTIONS、TRACE等请求协议<br><br
##### 欢迎加入NoHttp作者QQ技术交流群:46523908
<a target="_blank" href="//shang.qq.com/wpa/qunwpa?idkey=28760218432b83451cf4849d585ccfe282f3ef136c44446f55720b6de4f98546"><img border="0" src="http://pub.idqqimg.com/wpa/images/group.png" alt="Android 愚公移山1群" title="Android 愚公移山1群"></a>(点击图标,可以直接加入)
# NoHttpRxUtils框架是什么?
NoHttpRxUtils主要是通过RxJava-1框架对NoHttp网络框架操作进行再次封装。<br>
NoHttpRxUtils主要是通过RxJava框架对NoHttp网络框架操作进行再次封装。<br>
减轻使用者繁琐的调用,让使用者更专注于项目业务,而非客户端与服务器之间的网络通讯。<br><br>
由于NoHttpRxUtils网络请求方面是采用NoHttp同步请求,所以请求队列不是NoHttp队列算法而是NoHttpRxUtils队列算法。<br>
暂时不支持队列请求优先级设置。如果要想让一个请求优先,可以使用RxJava线程单一请求。<br>
Expand All @@ -46,7 +46,7 @@ NoHttpRxUtils主要是通过RxJava-1框架对NoHttp网络框架操作进行再
* 支持使用其它网络框架去轮询请求

# 为了你使用更加清晰明了,请仔细阅读下面使用教程
##### 框架内部使用RxJava版本是RxJava-1.1.9
##### 框架内部使用RxJava版本是RxJava-1.1.9和RxJava-2.1.5
##### 框架内部使用NoHttp版本是NoHttp-1.1.4
##### 框架内部使用Gson版本是Gson-2.8.0

Expand All @@ -63,7 +63,13 @@ repositories {
}
```

**2:项目目录build.gradle中依赖NohttpRxUtils框架**<br>
**2:项目目录build.gradle中依赖NoHttpRxUtils框架**<br>
* 使用RxJava-1的项目请依赖
```gradle
compile 'com.github.liqinew:nohttprxutils:v.1.3.4'
```

* 使用RxJava-2的项目请依赖
```gradle
compile 'com.github.liqinew:nohttprxutils:v.1.3.4'
```
Expand Down Expand Up @@ -126,7 +132,10 @@ NoHttpRxUtils使用简介

//设置全局重试次数,配置后每个请求失败都会重试设置的次数。
//.setRetry(5)


//设置全局请求网络出现未知错误提示语
.setAnUnknownErrorHint("全局未知错误提示语")

//开始初始化NoHttp
.startInit();
```
Expand Down Expand Up @@ -311,7 +320,10 @@ RxNoHttpUtils.rxNoHttpRequest()
//注:如果此处没有设置加载框,那么就默认使用全局设置的加载框。
//如果全局设置也没有设置加载框,那么就不显示加载框和内置提示语。
.setDialogGetListener(new Dialog())


//设置请求网络出现未知错误提示语
.setAnUnknownErrorHint("未知错误提示语")

//创建请求对象指定响应数据转换类型,然后在设置请求成功或者失败回调接口
.builder(Objects.class,new OnIsRequestListener<T>)

Expand Down Expand Up @@ -355,7 +367,8 @@ RxNoHttpUtils.rxNoHttpRequest()

//设置被观察者产生的行为事件监听器
//(如果此处实现被观察者产生的行为事件监听器,
//那么框架内部就不去维护此轮询请求,必须实现轮询拦截器接口去维护此轮询什么时候停止。)
//那么框架内部就不去维护此轮询请求,必须实现轮询拦截器接口去维护此轮询什么时候停止。
//RxNoHttpUtils.cancelPoll()取消轮询将无效,设置内部加载框将无效)
.setOnObserverEventListener(new OnObserverEventListener<RestRequest<T>, RxInformationModel<T>>(){
@Override
public RxInformationModel<T> onObserverEvent(RestRequest<T> transferValue) {
Expand Down
4 changes: 2 additions & 2 deletions nohttputils/build.gradle → nohttputils-r1/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 11
targetSdkVersion 23
versionCode 2
versionName "1.1"
versionCode 1
versionName "1"
}
buildTypes {
release {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public interface DialogGetListener {
* 获取dialog
* @return
*/
public Dialog getDialog();
Dialog getDialog();

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public interface OnIsRequestListener<T> {
* 请求成功
* @param response
*/
public void onNext(T response);
void onNext(T response);

/**
* 请求失败
* @param e
*/
public void onError(Throwable e);
void onError(Throwable e);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.widget.Toast;

import com.liqi.nohttputils.R;
Expand All @@ -17,6 +18,7 @@
import com.yanzhenjie.nohttp.rest.ProtocolRequest;
import com.yanzhenjie.nohttp.rest.Response;

import java.net.ConnectException;
import java.net.ProtocolException;

import rx.Observable;
Expand Down Expand Up @@ -46,9 +48,9 @@ synchronized static RxNoHttp getRxNoHttp() {
* @param mDialogGetListener dialog获取接口
* @param responseInterfa 请求成功或者失败回调对象
*/
<T> void request(final ProtocolRequest<?, T> request, DialogGetListener mDialogGetListener, final OnIsRequestListener<T> responseInterfa) {
<T> void request(final ProtocolRequest<?, T> request, DialogGetListener mDialogGetListener, final OnIsRequestListener<T> responseInterfa, final String anUnknownErrorHint) {
final Dialog dialog = null == mDialogGetListener ? null : mDialogGetListener.getDialog();
if (null != dialog&&!dialog.isShowing()) {
if (null != dialog && !dialog.isShowing()) {
try {
dialog.show();
} catch (Exception e) {
Expand Down Expand Up @@ -101,6 +103,8 @@ public void onError(Throwable e) {
show(dialog, R.string.error_not_found_cache);
} else if (e instanceof ProtocolException) {
show(dialog, R.string.error_system_unsupport_method);
} else if (e instanceof ConnectException) {//没有连接到服务器
show(dialog, R.string.error_no_service);
} else {
Logger.e("NoHttpUtils捕获异常:" + e.toString());
StackTraceElement[] stackTrace = e.getStackTrace();
Expand All @@ -109,7 +113,11 @@ public void onError(Throwable e) {
Logger.e("NoHttpUtils捕获异常:" + traceElement.toString());
}
}
show(dialog, R.string.error_unknow);
if (TextUtils.isEmpty(anUnknownErrorHint)) {
show(dialog, R.string.error_unknow);
}else{
show(dialog,anUnknownErrorHint);
}
}


Expand Down Expand Up @@ -147,4 +155,15 @@ private void show(Dialog dialog, int stringId) {
Toast.makeText(context, context.getResources().getString(stringId), Toast.LENGTH_SHORT).show();
}
}
/**
* 土司提示
*
* @param hint 提示内容
*/
private void show(Dialog dialog, String hint) {
if (null != dialog) {
Context context = dialog.getContext();
Toast.makeText(context, hint, Toast.LENGTH_SHORT).show();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.liqi.nohttputils.nohttp.interfa.OnToJsonListEntityMethodListener;
import com.liqi.nohttputils.nohttp.interfa.OnToJsonObjectEntityMethodListener;
import com.liqi.nohttputils.nohttp.interfa.OnToStringEntityMethodListener;
import com.yanzhenjie.nohttp.Logger;
import com.yanzhenjie.nohttp.RequestMethod;
import com.yanzhenjie.nohttp.rest.CacheMode;

Expand Down Expand Up @@ -43,6 +44,7 @@ public class RxRequestConfig<T> {
private String mCacheKey;
private CacheMode mCacheMode = CacheMode.DEFAULT;
private RxRequestEntityBase mRxRequestEntityBase;
private String mAnUnknownErrorHint;

private RxRequestConfig() {

Expand All @@ -53,6 +55,10 @@ private RxRequestConfig() {
mOnIsRequestListener = onIsRequestListener;
}

public String getAnUnknownErrorHint() {
return mAnUnknownErrorHint;
}

RxRequestEntityBase getRxRequestEntityBase() {
return mRxRequestEntityBase;
}
Expand Down Expand Up @@ -206,9 +212,18 @@ public static class ConfigBuilder {
* 请求实体(body)
*/
private RxRequestEntityBase mRxRequestEntityBase;
/**
* 未知错误提示语
*/
private String mAnUnknownErrorHint;

public ConfigBuilder() {

try {
mAnUnknownErrorHint = RxUtilsConfig.ConfigBuilder.getConfigBuilder().getRxUtilsConfig().getAnUnknownErrorHint();
} catch (Exception e) {
Logger.e("NoHttpUtils捕获异常:请先初始化框架");
e.printStackTrace();
}
}

public ConfigBuilder get() {
Expand Down Expand Up @@ -481,6 +496,17 @@ public ConfigBuilder setCacheKey(String cacheKey) {
return this;
}

/**
* 设置未知错误提示语
*
* @param anUnknownErrorHint 未知错误提示语
* @return
*/
public ConfigBuilder setAnUnknownErrorHint(String anUnknownErrorHint) {
mAnUnknownErrorHint = anUnknownErrorHint;
return this;
}

/**
* 设置Json请求对象实体对象
* json样式:{"xx":"xxx","yy":"yyy"}
Expand Down Expand Up @@ -604,6 +630,7 @@ private <T> RxRequestConfig<T> getRxRequestConfig(@NonNull Class<T> clazz, OnIsR
requestConfig.mCacheKey = mCacheKey;
requestConfig.mCacheMode = mCacheMode;
requestConfig.mRxRequestEntityBase = mRxRequestEntityBase;
requestConfig.mAnUnknownErrorHint = mAnUnknownErrorHint;
return requestConfig;
}
}
Expand Down
Loading

0 comments on commit 3fc5c83

Please sign in to comment.