-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f6da5c
commit 09e26ca
Showing
43 changed files
with
239 additions
and
3,004 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion 23 | ||
buildToolsVersion "23.0.1" | ||
|
||
defaultConfig { | ||
minSdkVersion 12 | ||
targetSdkVersion 23 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile project(path: ':xsnow') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/xyy/android-sdk-macosx/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.vise.netexpand"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
> | ||
|
||
</application> | ||
|
||
</manifest> |
37 changes: 37 additions & 0 deletions
37
netexpand/src/main/java/com/vise/netexpand/common/ResponseHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.vise.netexpand.common; | ||
|
||
import com.vise.netexpand.mode.ApiResult; | ||
import com.vise.netexpand.mode.ResponseCode; | ||
|
||
/** | ||
* @Description: | ||
* @author: <a href="http://www.xiaoyaoyou1212.com">DAWI</a> | ||
* @date: 17/5/17 23:59. | ||
*/ | ||
public class ResponseHelper { | ||
|
||
public static boolean isSuccess(ApiResult apiResult) { | ||
if (apiResult == null) { | ||
return false; | ||
} | ||
if (apiResult.getCode() == ResponseCode.HTTP_SUCCESS || ignoreSomeIssue(apiResult.getCode())) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
private static boolean ignoreSomeIssue(int code) { | ||
switch (code) { | ||
case ResponseCode.TIMESTAMP_ERROR://时间戳过期 | ||
case ResponseCode.ACCESS_TOKEN_EXPIRED://AccessToken错误或已过期 | ||
case ResponseCode.REFRESH_TOKEN_EXPIRED://RefreshToken错误或已过期 | ||
case ResponseCode.OTHER_PHONE_LOGIN://帐号在其它手机已登录 | ||
case ResponseCode.NO_ACCESS_TOKEN://缺少授权信息,没有AccessToken | ||
case ResponseCode.SIGN_ERROR://签名错误 | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...now/net/convert/GsonConverterFactory.java → ...texpand/convert/GsonConverterFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...net/convert/GsonRequestBodyConverter.java → ...and/convert/GsonRequestBodyConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...et/convert/JsonResponseBodyConverter.java → ...nd/convert/JsonResponseBodyConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.vise.xsnow.net.convert; | ||
package com.vise.netexpand.convert; | ||
|
||
import java.io.IOException; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...om/vise/xsnow/net/func/ApiResultFunc.java → ...om/vise/netexpand/func/ApiResultFunc.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...va/com/vise/xsnow/net/mode/ApiResult.java → ...va/com/vise/netexpand/mode/ApiResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.vise.xsnow.net.mode; | ||
package com.vise.netexpand.mode; | ||
|
||
/** | ||
* @Description: 封装的通用服务器返回对象,可自行定义 | ||
|
23 changes: 23 additions & 0 deletions
23
netexpand/src/main/java/com/vise/netexpand/mode/ResponseCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.vise.netexpand.mode; | ||
|
||
/** | ||
* @Description: Response响应码(根据服务器提供文档进行定义) | ||
* @author: <a href="http://xiaoyaoyou1212.360doc.com">DAWI</a> | ||
* @date: 2016-12-30 18:11 | ||
*/ | ||
public class ResponseCode { | ||
//HTTP请求成功状态码 | ||
public static final int HTTP_SUCCESS = 0; | ||
//AccessToken错误或已过期 | ||
public static final int ACCESS_TOKEN_EXPIRED = 10001; | ||
//RefreshToken错误或已过期 | ||
public static final int REFRESH_TOKEN_EXPIRED = 10002; | ||
//帐号在其它手机已登录 | ||
public static final int OTHER_PHONE_LOGIN = 10003; | ||
//时间戳过期 | ||
public static final int TIMESTAMP_ERROR = 10004; | ||
//缺少授权信息,没有AccessToken | ||
public static final int NO_ACCESS_TOKEN = 10005; | ||
//签名错误 | ||
public static final int SIGN_ERROR = 10006; | ||
} |
61 changes: 61 additions & 0 deletions
61
netexpand/src/main/java/com/vise/netexpand/request/ApiGetRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.vise.netexpand.request; | ||
|
||
import android.content.Context; | ||
|
||
import com.vise.netexpand.func.ApiDataFunc; | ||
import com.vise.netexpand.func.ApiResultFunc; | ||
import com.vise.netexpand.mode.ApiResult; | ||
import com.vise.utils.assist.ClassUtil; | ||
import com.vise.xsnow.net.ViseNet; | ||
import com.vise.xsnow.net.callback.ACallback; | ||
import com.vise.xsnow.net.func.ApiRetryFunc; | ||
import com.vise.xsnow.net.mode.CacheResult; | ||
import com.vise.xsnow.net.request.BaseRequest; | ||
import com.vise.xsnow.net.request.GetRequest; | ||
import com.vise.xsnow.net.subscriber.ApiCallbackSubscriber; | ||
|
||
import rx.Observable; | ||
import rx.Subscription; | ||
import rx.android.schedulers.AndroidSchedulers; | ||
import rx.schedulers.Schedulers; | ||
|
||
/** | ||
* @Description: | ||
* @author: <a href="http://www.xiaoyaoyou1212.com">DAWI</a> | ||
* @date: 17/5/13 14:31. | ||
*/ | ||
public class ApiGetRequest extends GetRequest { | ||
@Override | ||
protected <T> Observable<T> execute(Class<T> clazz) { | ||
return apiService.get(suffixUrl, params).map(new ApiResultFunc<T>(clazz)).compose(this.<T>apiTransformer()); | ||
} | ||
|
||
@Override | ||
protected <T> Observable<CacheResult<T>> cacheExecute(Class<T> clazz) { | ||
return execute(clazz).compose(ViseNet.getInstance().getApiCache().transformer(cacheMode, clazz)); | ||
} | ||
|
||
@Override | ||
protected <T> Subscription execute(Context context, ACallback<T> callback) { | ||
if (isLocalCache) { | ||
return this.cacheExecute(ClassUtil.getTClass(callback)) | ||
.subscribe(new ApiCallbackSubscriber(context, callback)); | ||
} | ||
return this.execute(ClassUtil.getTClass(callback)) | ||
.subscribe(new ApiCallbackSubscriber(context, callback)); | ||
} | ||
|
||
protected <T> Observable.Transformer<ApiResult<T>, T> apiTransformer() { | ||
return new Observable.Transformer<ApiResult<T>, T>() { | ||
@Override | ||
public Observable<T> call(Observable<ApiResult<T>> apiResultObservable) { | ||
return apiResultObservable | ||
.subscribeOn(Schedulers.io()) | ||
.unsubscribeOn(Schedulers.io()) | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.map(new ApiDataFunc<T>()) | ||
.retryWhen(new ApiRetryFunc(retryCount, retryDelayMillis)); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<resources> | ||
<string name="app_name">netexpand</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
include ':app', ':xsnow' | ||
include ':app', ':xsnow', ':netexpand' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.