use of zlc.season.rxdownload2.entity.DownloadStatus in project RxDownload by ssseasonnn.
the class MultiMissionDownloadActivity method onResume.
@Override
protected void onResume() {
super.onResume();
//
startMultiMission();
//
disposable1 = rxDownload.receiveDownloadStatus(url1).subscribe(new Consumer<DownloadEvent>() {
@Override
public void accept(DownloadEvent downloadEvent) throws Exception {
int flag = downloadEvent.getFlag();
switch(flag) {
case DownloadFlag.NORMAL:
binding.contentMultiMissionDownload.control1.setVisibility(View.GONE);
break;
case DownloadFlag.WAITING:
binding.contentMultiMissionDownload.control1.setVisibility(View.VISIBLE);
binding.contentMultiMissionDownload.control1.setText("等待中");
break;
case DownloadFlag.STARTED:
binding.contentMultiMissionDownload.control1.setText("下载中");
break;
case DownloadFlag.PAUSED:
binding.contentMultiMissionDownload.control1.setText("已暂停");
break;
case DownloadFlag.COMPLETED:
binding.contentMultiMissionDownload.control1.setText("已完成");
break;
case DownloadFlag.FAILED:
Throwable throwable = downloadEvent.getError();
log(throwable);
binding.contentMultiMissionDownload.control1.setText("失败");
break;
}
DownloadStatus status = downloadEvent.getDownloadStatus();
binding.contentMultiMissionDownload.progress1.setProgress(status.getPercentNumber());
}
});
//
disposable2 = rxDownload.receiveDownloadStatus(url2).subscribe(new Consumer<DownloadEvent>() {
@Override
public void accept(DownloadEvent downloadEvent) throws Exception {
int flag = downloadEvent.getFlag();
switch(flag) {
case DownloadFlag.NORMAL:
binding.contentMultiMissionDownload.control2.setVisibility(View.GONE);
break;
case DownloadFlag.WAITING:
binding.contentMultiMissionDownload.control2.setVisibility(View.VISIBLE);
binding.contentMultiMissionDownload.control2.setText("等待中");
break;
case DownloadFlag.STARTED:
binding.contentMultiMissionDownload.control2.setText("下载中");
break;
case DownloadFlag.PAUSED:
binding.contentMultiMissionDownload.control2.setText("已暂停");
break;
case DownloadFlag.COMPLETED:
binding.contentMultiMissionDownload.control2.setText("已完成");
break;
case DownloadFlag.FAILED:
Throwable throwable = downloadEvent.getError();
log(throwable);
binding.contentMultiMissionDownload.control2.setText("失败");
break;
}
DownloadStatus status = downloadEvent.getDownloadStatus();
binding.contentMultiMissionDownload.progress2.setProgress(status.getPercentNumber());
}
});
//
disposable3 = rxDownload.receiveDownloadStatus(url3).subscribe(new Consumer<DownloadEvent>() {
@Override
public void accept(DownloadEvent downloadEvent) throws Exception {
int flag = downloadEvent.getFlag();
switch(flag) {
case DownloadFlag.NORMAL:
binding.contentMultiMissionDownload.control3.setVisibility(View.GONE);
break;
case DownloadFlag.WAITING:
binding.contentMultiMissionDownload.control3.setVisibility(View.VISIBLE);
binding.contentMultiMissionDownload.control3.setText("等待中");
break;
case DownloadFlag.STARTED:
binding.contentMultiMissionDownload.control3.setText("下载中");
break;
case DownloadFlag.PAUSED:
binding.contentMultiMissionDownload.control3.setText("已暂停");
break;
case DownloadFlag.COMPLETED:
binding.contentMultiMissionDownload.control3.setText("已完成");
break;
case DownloadFlag.FAILED:
Throwable throwable = downloadEvent.getError();
log(throwable);
binding.contentMultiMissionDownload.control3.setText("失败");
break;
}
DownloadStatus status = downloadEvent.getDownloadStatus();
binding.contentMultiMissionDownload.progress3.setProgress(status.getPercentNumber());
}
});
}
use of zlc.season.rxdownload2.entity.DownloadStatus in project RxDownload by ssseasonnn.
the class ServiceDownloadActivity method updateProgress.
private void updateProgress(DownloadEvent event) {
DownloadStatus status = event.getDownloadStatus();
binding.contentServiceDownload.progress.setIndeterminate(status.isChunked);
binding.contentServiceDownload.progress.setMax((int) status.getTotalSize());
binding.contentServiceDownload.progress.setProgress((int) status.getDownloadSize());
serviceModel.setPercent(status.getPercent());
serviceModel.setSize(status.getFormatStatusString());
}
use of zlc.season.rxdownload2.entity.DownloadStatus in project RxDownload by ssseasonnn.
the class DownloadService method receiveDownloadEvent.
/**
* Receive the url download event.
* <p>
* Will receive the following event:
* {@link DownloadFlag#NORMAL}、{@link DownloadFlag#WAITING}、
* {@link DownloadFlag#STARTED}、{@link DownloadFlag#PAUSED}、
* {@link DownloadFlag#COMPLETED}、{@link DownloadFlag#FAILED};
* <p>
* Every event has {@link DownloadStatus}, you can get it and display it on the interface.
*
* @param url url
* @return DownloadEvent
*/
public FlowableProcessor<DownloadEvent> receiveDownloadEvent(String url) {
FlowableProcessor<DownloadEvent> processor = createProcessor(url, processorMap);
DownloadMission mission = missionMap.get(url);
if (mission == null) {
//Not yet add this url mission.
DownloadRecord record = dataBaseHelper.readSingleRecord(url);
if (record == null) {
processor.onNext(normal(null));
} else {
File file = getFiles(record.getSaveName(), record.getSavePath())[0];
if (file.exists()) {
processor.onNext(createEvent(record.getFlag(), record.getStatus()));
} else {
processor.onNext(normal(null));
}
}
}
return processor;
}
Aggregations