1111import com .codingcoderscode .evolving .net .request .method .CCHttpMethod ;
1212import com .codingcoderscode .evolving .net .request .wrapper .CCDownloadRequestWrapper ;
1313import com .codingcoderscode .evolving .net .response .CCBaseResponse ;
14+ import com .codingcoderscode .evolving .net .util .CCLogUtil ;
1415
1516import org .reactivestreams .Publisher ;
1617import org .reactivestreams .Subscription ;
2223import java .util .concurrent .TimeUnit ;
2324import java .util .concurrent .atomic .AtomicInteger ;
2425
26+ import io .reactivex .BackpressureStrategy ;
2527import io .reactivex .Flowable ;
2628import io .reactivex .functions .BooleanSupplier ;
2729import io .reactivex .functions .Function ;
@@ -82,13 +84,18 @@ protected Call<ResponseBody> getRequestCall() {
8284
8385 @ Override
8486 protected Flowable <CCBaseResponse <T >> getRequestFlowable () {
85- return Flowable .intervalRange (0 , 1 , 0 , 5 * 60 * 1000 , TimeUnit .MILLISECONDS , Schedulers .computation ())
87+ return Flowable .intervalRange (0 , 1 , 0 , 5 * 60 * 1000 , TimeUnit .MILLISECONDS , Schedulers .io ())
8688 .repeatUntil (new BooleanSupplier () {
8789 @ Override
8890 public boolean getAsBoolean () throws Exception {
89- return false ;
91+
92+ boolean repeat = isRequestRunning () && !isForceCanceled ();
93+
94+ return !repeat ;
9095 }
9196 })
97+ .onBackpressureLatest ()
98+ //.onBackpressureBuffer(BackpressureStrategy.LATEST)
9299 //.subscribeOn(Schedulers.computation())
93100 //.unsubscribeOn(Schedulers.io())
94101 //.observeOn(Schedulers.io())
@@ -102,7 +109,7 @@ public Publisher<CCBaseResponse<T>> apply(Long aLong) throws Exception {
102109 }
103110 }
104111 })
105- .subscribeOn (Schedulers .computation ());
112+ /* .subscribeOn(Schedulers.computation())*/ ;
106113 }
107114
108115 /**
@@ -186,6 +193,7 @@ private void onSelectOneTaskToDownload() {
186193 .setSupportRage (true )
187194 .setDownloadProgressListener (this )
188195 .setRetryCount (DEFAULT_RETRY_COUNT )
196+ .setLifecycleDisposeComposer (this .getLifecycleDisposeComposer ())
189197 .setReqTag (CCMultiDownloadTaskWrapper .newInstance (getDefaultTaskReqTag (), toDownloadTask ));
190198
191199 downloadRequest .executeAsync ();
@@ -200,6 +208,7 @@ private void onSelectOneTaskToDownload() {
200208 .setSupportRage (true )
201209 .setDownloadProgressListener (this )
202210 .setRetryCount (DEFAULT_RETRY_COUNT )
211+ .setLifecycleDisposeComposer (this .getLifecycleDisposeComposer ())
203212 .setReqTag (CCMultiDownloadTaskWrapper .newInstance (getDefaultTaskReqTag (), toDownloadTask ));
204213
205214 downloadRequest .executeAsync ();
@@ -249,30 +258,36 @@ protected void onNextLocal(CCBaseResponse<T> tccBaseResponse) {
249258 if (getDownloadProgressListener () != null && isRequestRunning () && !isForceCanceled ()) {
250259 getDownloadProgressListener ().<T >onRequestSuccess (getReqTag ());
251260 }
261+ this .setRequestRunning (false );
262+ this .setForceCanceled (false );
252263 } catch (Exception e ) {
253264 e .printStackTrace ();
254265 }
255266 }
256267
257268 @ Override
258- public void onErrorLocal (Throwable t ) {
269+ protected void onErrorLocal (Throwable t ) {
259270 super .onErrorLocal (t );
260271 try {
261272 if (getDownloadProgressListener () != null && isRequestRunning () && !isForceCanceled ()) {
262273 getDownloadProgressListener ().<T >onRequestError (getReqTag (), t );
263274 }
275+ this .setRequestRunning (false );
276+ this .setForceCanceled (false );
264277 } catch (Exception e ) {
265278 e .printStackTrace ();
266279 }
267280 }
268281
269282 @ Override
270- public void onCompleteLocal () {
283+ protected void onCompleteLocal () {
271284 super .onCompleteLocal ();
272285 try {
273286 if (getDownloadProgressListener () != null && isRequestRunning () && !isForceCanceled ()) {
274287 getDownloadProgressListener ().<T >onRequestComplete (getReqTag ());
275288 }
289+ this .setRequestRunning (false );
290+ this .setForceCanceled (false );
276291 } catch (Exception e ) {
277292 e .printStackTrace ();
278293 }
@@ -573,7 +588,14 @@ public void onProgressSave(Object reqTag, CCDownloadTask downloadTask, int progr
573588 public void onProgress (Object tag , CCDownloadTask downloadTask , int progress , long netSpeed , long downloadedSize , long fileSize ) {
574589 if ((this .getDownloadProgressListener () != null ) && isRequestRunning () && !isForceCanceled ()) {
575590 this .getDownloadProgressListener ().onProgress (getReqTag (), getOriginalDownloadTask (tag , downloadTask ), progress , netSpeed , downloadedSize , fileSize );
591+
592+ CCLogUtil .printLog ("e" , getClass ().getCanonicalName (), "回调下载进度" );
593+ }else {
594+ CCLogUtil .printLog ("e" , getClass ().getCanonicalName (), "不能回调下载进度???" );
576595 }
596+
597+
598+
577599 }
578600
579601 @ Override
0 commit comments