Skip to content

Commit 4ed8e86

Browse files
author
ghc
committed
分支:master_dev
1.代码结构修改 2.功能实现调整
1 parent 12d417d commit 4ed8e86

38 files changed

Lines changed: 1134 additions & 941 deletions

‎EvolvingNet/src/main/java/com/codingcoderscode/evolving/net/CCRxNetManager.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import com.codingcoderscode.evolving.net.request.interceptor.CCHeaderInterceptor;
1515
import com.codingcoderscode.evolving.net.request.interceptor.CCHttpLoggingInterceptor;
1616
import com.codingcoderscode.evolving.net.request.ssl.HttpsUtil;
17-
import com.codingcoderscode.evolving.net.util.NetLogUtil;
18-
import com.codingcoderscode.evolving.net.util.Utils;
17+
import com.codingcoderscode.evolving.net.util.CCLogUtil;
18+
import com.codingcoderscode.evolving.net.util.CCUtils;
1919
import com.google.gson.Gson;
2020

2121
import java.io.IOException;
@@ -84,7 +84,7 @@ public Builder() {
8484
* @return
8585
*/
8686
public Builder baseUrl(String baseUrl) {
87-
this.retrofitBuilder.baseUrl(Utils.checkNotNull(baseUrl, "baseUrl == null"));
87+
this.retrofitBuilder.baseUrl(CCUtils.checkNotNull(baseUrl, "baseUrl == null"));
8888
return this;
8989
}
9090

@@ -172,7 +172,7 @@ public <T> Builder commonHeaders(Map<String, T> headerMap) {
172172
*/
173173
public Builder enableLogInterceptor(boolean enableLog) {
174174
if (enableLog) {
175-
NetLogUtil.setDebugAble(true);
175+
CCLogUtil.setDebugAble(true);
176176
CCHttpLoggingInterceptor loggingInterceptor = new CCHttpLoggingInterceptor("CCNetLib");
177177
loggingInterceptor.setPrintLevel(CCHttpLoggingInterceptor.Level.BODY); //log打印级别,决定了log显示的详细程度
178178
loggingInterceptor.setColorLevel(Level.INFO); //log颜色级别,决定了log在控制台显示的颜色
@@ -407,9 +407,9 @@ public void accept(Throwable throwable) throws Exception {
407407
return;
408408
}
409409
//Log.warning("Undeliverable exception received, not sure what to do", e);
410-
NetLogUtil.printLog("e", LOG_TAG, "Undeliverable exception received, not sure what to do", throwable);
410+
CCLogUtil.printLog("e", LOG_TAG, "Undeliverable exception received, not sure what to do", throwable);
411411
} catch (Exception e) {
412-
NetLogUtil.printLog("e", LOG_TAG, "DefaultErrorHandler捕获未知类型异常", e);
412+
CCLogUtil.printLog("e", LOG_TAG, "DefaultErrorHandler捕获未知类型异常", e);
413413
}
414414
}
415415
}

‎EvolvingNet/src/main/java/com/codingcoderscode/evolving/net/request/CCDeleteRequest.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.codingcoderscode.evolving.net.request.api.CCNetApiService;
44
import com.codingcoderscode.evolving.net.request.base.CCRequest;
5+
import com.codingcoderscode.evolving.net.request.base.CCSimpleRequest;
56
import com.codingcoderscode.evolving.net.request.method.CCHttpMethod;
67
import com.codingcoderscode.evolving.net.util.CCNetUtil;
78

@@ -14,7 +15,7 @@
1415
* DELETE类型请求类
1516
*/
1617

17-
public class CCDeleteRequest<T> extends CCRequest<T, CCDeleteRequest<T>> {
18+
public class CCDeleteRequest<T> extends CCSimpleRequest<T> {
1819

1920
public CCDeleteRequest(String url, CCNetApiService apiService) {
2021
super(url, apiService);

‎EvolvingNet/src/main/java/com/codingcoderscode/evolving/net/request/CCDownloadRequest.java‎

Lines changed: 66 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@
66
import android.os.Looper;
77
import android.text.TextUtils;
88

9-
import com.codingcoderscode.evolving.net.cache.mode.CCCMode;
109
import com.codingcoderscode.evolving.net.request.api.CCNetApiService;
11-
import com.codingcoderscode.evolving.net.request.base.CCRequest;
12-
import com.codingcoderscode.evolving.net.request.callback.CCDownloadFileWriteListener;
13-
import com.codingcoderscode.evolving.net.request.callback.CCDownloadProgressListener;
10+
import com.codingcoderscode.evolving.net.request.base.CCSimpleDownloadRequest;
11+
import com.codingcoderscode.evolving.net.request.listener.CCDownloadFileWriteListener;
12+
import com.codingcoderscode.evolving.net.request.listener.CCSingleDownloadProgressListener;
1413
import com.codingcoderscode.evolving.net.request.entity.CCDownloadTask;
1514
import com.codingcoderscode.evolving.net.request.exception.CCUnExpectedException;
1615
import com.codingcoderscode.evolving.net.request.exception.NoEnoughSpaceException;
1716
import com.codingcoderscode.evolving.net.request.exception.NoResponseBodyDataException;
18-
import com.codingcoderscode.evolving.net.request.method.CCHttpMethod;
1917
import com.codingcoderscode.evolving.net.request.retry.FlowableRetryWithDelay;
2018
import com.codingcoderscode.evolving.net.response.CCBaseResponse;
2119
import com.codingcoderscode.evolving.net.util.CCFileUtils;
20+
import com.codingcoderscode.evolving.net.util.CCLogUtil;
2221
import com.codingcoderscode.evolving.net.util.CCNetUtil;
23-
import com.codingcoderscode.evolving.net.util.NetLogUtil;
24-
import com.codingcoderscode.evolving.net.util.SDCardUtil;
22+
import com.codingcoderscode.evolving.net.util.CCSDCardUtil;
2523

2624
import org.reactivestreams.Publisher;
25+
import org.reactivestreams.Subscription;
2726

2827
import java.io.File;
2928
import java.io.InputStream;
@@ -46,10 +45,10 @@
4645
* 下载文件请求类
4746
*/
4847

49-
public class CCDownloadRequest<T> extends CCRequest<T, CCDownloadRequest<T>> {
48+
public class CCDownloadRequest<T> extends CCSimpleDownloadRequest<T> {
5049

5150
//进度回调
52-
//private CCDownloadProgressListener ccDownloadProgressCallback;
51+
private CCSingleDownloadProgressListener mSingleDownloadProgressListener;
5352
//下载文件的本地保存路径
5453
private String fileSavePath;
5554
//下载文件的本地名称,含后缀
@@ -86,8 +85,6 @@ public class CCDownloadRequest<T> extends CCRequest<T, CCDownloadRequest<T>> {
8685

8786
private CCDownloadFileWriteListener mDownloadFileWriteListener;
8887

89-
private CCDownloadProgressListener mDownloadProgressListener;
90-
9188
private final int DEFAULT_BUFFER_SIZE = 8 * 1024;
9289

9390
private CCDownloadTask mDownloadTask;
@@ -97,21 +94,6 @@ public CCDownloadRequest(String url, CCNetApiService apiService) {
9794
this.supportRage = false;
9895
}
9996

100-
@Override
101-
protected int getHttpMethod() {
102-
return CCHttpMethod.GET;
103-
}
104-
105-
@Override
106-
public int getCacheQueryMode() {
107-
return CCCMode.QueryMode.MODE_NET;
108-
}
109-
110-
@Override
111-
public int getCacheSaveMode() {
112-
return CCCMode.SaveMode.MODE_NONE;
113-
}
114-
11597
@Override
11698
protected Flowable<CCBaseResponse<T>> getRequestFlowable() {
11799

@@ -181,6 +163,54 @@ protected Call<ResponseBody> getRequestCall() {
181163
return call;
182164
}
183165

166+
@Override
167+
protected void onSubscribeLocal(Subscription s) {
168+
super.onSubscribeLocal(s);
169+
try {
170+
if (getDownloadProgressListener() != null && isRequestRunning() && !isForceCanceled()) {
171+
getDownloadProgressListener().<T>onStart(getReqTag(), this.mDownloadTask, getNetCCCanceler());
172+
}
173+
} catch (Exception e) {
174+
e.printStackTrace();
175+
}
176+
}
177+
178+
@Override
179+
protected void onNextLocal(CCBaseResponse<T> tccBaseResponse) {
180+
super.onNextLocal(tccBaseResponse);
181+
try {
182+
if (getDownloadProgressListener() != null && isRequestRunning() && !isForceCanceled()) {
183+
getDownloadProgressListener().<T>onSuccess(getReqTag(), this.mDownloadTask);
184+
}
185+
} catch (Exception e) {
186+
e.printStackTrace();
187+
}
188+
}
189+
190+
@Override
191+
public void onErrorLocal(Throwable t) {
192+
super.onErrorLocal(t);
193+
try {
194+
if (getDownloadProgressListener() != null && isRequestRunning() && !isForceCanceled()) {
195+
getDownloadProgressListener().<T>onError(getReqTag(), this.mDownloadTask, t);
196+
}
197+
} catch (Exception e) {
198+
e.printStackTrace();
199+
}
200+
}
201+
202+
@Override
203+
public void onCompleteLocal() {
204+
super.onCompleteLocal();
205+
try {
206+
if (getDownloadProgressListener() != null && isRequestRunning() && !isForceCanceled()) {
207+
getDownloadProgressListener().<T>onComplete(getReqTag(), this.mDownloadTask);
208+
}
209+
} catch (Exception e) {
210+
e.printStackTrace();
211+
}
212+
}
213+
184214
private long convertStringToLong(String source) {
185215
long result = 0;
186216
try {
@@ -209,7 +239,7 @@ protected void onTryToWriteFileToSDCard(Response<ResponseBody> retrofitResponse,
209239
} else {
210240
long contentLengthLong = convertStringToLong(contentLengthStr);
211241

212-
if (contentLengthLong > SDCardUtil.getSDCardAvailableSize() * 1024 * 1024) {
242+
if (contentLengthLong > CCSDCardUtil.getSDCardAvailableSize() * 1024 * 1024) {
213243
throw new NoEnoughSpaceException("write failed: ENOSPC (No space left on device)");
214244
}
215245

@@ -307,7 +337,7 @@ public void run() {
307337
}
308338
} catch (Exception exception) {
309339
if ((exception instanceof java.io.InterruptedIOException) && isForceCanceled()) {
310-
NetLogUtil.printLog("e", "CCDownloadRequest", "当前异常类型是java.io.InterruptedIOException,且是强制中断,为用户主动取消网络传输");
340+
CCLogUtil.printLog("e", "CCDownloadRequest", "当前异常类型是java.io.InterruptedIOException,且是强制中断,为用户主动取消网络传输");
311341
} else {
312342
throw new CCUnExpectedException(exception);
313343
}
@@ -324,7 +354,7 @@ private void onCloseInputStream(InputStream inputStream) {
324354
inputStream.close();
325355
}
326356
} catch (Exception e) {
327-
NetLogUtil.printLog("e", getClass().getCanonicalName(), "发生异常", e);
357+
CCLogUtil.printLog("e", getClass().getCanonicalName(), "发生异常", e);
328358
}
329359
}
330360

@@ -334,7 +364,7 @@ private void onCloseOutputStream(OutputStream outputStream) {
334364
outputStream.close();
335365
}
336366
} catch (Exception e) {
337-
NetLogUtil.printLog("e", getClass().getCanonicalName(), "发生异常", e);
367+
CCLogUtil.printLog("e", getClass().getCanonicalName(), "发生异常", e);
338368
}
339369
}
340370

@@ -344,7 +374,7 @@ private void onCloseRandomAccessFile(RandomAccessFile rafFile) {
344374
rafFile.close();
345375
}
346376
} catch (Exception e) {
347-
NetLogUtil.printLog("e", getClass().getCanonicalName(), "发生异常", e);
377+
CCLogUtil.printLog("e", getClass().getCanonicalName(), "发生异常", e);
348378
}
349379
}
350380

@@ -386,7 +416,7 @@ private void onFileSaveCheck(boolean supportRage) {
386416
file.createNewFile();
387417

388418
} catch (Exception exception) {
389-
NetLogUtil.printLog("e", getClass().getCanonicalName(), "发生异常", exception);
419+
CCLogUtil.printLog("e", getClass().getCanonicalName(), "发生异常", exception);
390420
}
391421
}
392422

@@ -438,12 +468,12 @@ public CCDownloadRequest<T> setCCDownloadFileWriteListener(CCDownloadFileWriteLi
438468
return this;
439469
}
440470

441-
public CCDownloadProgressListener getDownloadProgressListener() {
442-
return mDownloadProgressListener;
471+
public CCSingleDownloadProgressListener getDownloadProgressListener() {
472+
return mSingleDownloadProgressListener;
443473
}
444474

445-
public CCDownloadRequest<T> setDownloadProgressListener(CCDownloadProgressListener downloadProgressListener) {
446-
this.mDownloadProgressListener = downloadProgressListener;
475+
public CCDownloadRequest<T> setDownloadProgressListener(CCSingleDownloadProgressListener downloadProgressListener) {
476+
this.mSingleDownloadProgressListener = downloadProgressListener;
447477
return this;
448478
}
449479
}

‎EvolvingNet/src/main/java/com/codingcoderscode/evolving/net/request/CCGetRequest.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import com.codingcoderscode.evolving.net.request.api.CCNetApiService;
55
import com.codingcoderscode.evolving.net.request.base.CCRequest;
6+
import com.codingcoderscode.evolving.net.request.base.CCSimpleRequest;
67
import com.codingcoderscode.evolving.net.request.method.CCHttpMethod;
78
import com.codingcoderscode.evolving.net.util.CCNetUtil;
89

@@ -15,7 +16,7 @@
1516
* GET类型请求类
1617
*/
1718

18-
public class CCGetRequest<T> extends CCRequest<T, CCGetRequest<T>> {
19+
public class CCGetRequest<T> extends CCSimpleRequest<T> {
1920

2021
public CCGetRequest(String url, CCNetApiService apiService) {
2122
super(url, apiService);

‎EvolvingNet/src/main/java/com/codingcoderscode/evolving/net/request/CCHeadRequest.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import com.codingcoderscode.evolving.net.request.api.CCNetApiService;
55
import com.codingcoderscode.evolving.net.request.base.CCRequest;
6+
import com.codingcoderscode.evolving.net.request.base.CCSimpleRequest;
67
import com.codingcoderscode.evolving.net.request.method.CCHttpMethod;
78
import com.codingcoderscode.evolving.net.util.CCNetUtil;
89

@@ -15,7 +16,7 @@
1516
* HEAD类型请求类
1617
*/
1718

18-
public class CCHeadRequest<T> extends CCRequest<T, CCHeadRequest<T>> {
19+
public class CCHeadRequest<T> extends CCSimpleRequest<T> {
1920

2021
public CCHeadRequest(String url, CCNetApiService apiService) {
2122
super(url, apiService);

0 commit comments

Comments
 (0)