Search in sources :

Example 6 with DownloadStatus

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());
        }
    });
}
Also used : Consumer(io.reactivex.functions.Consumer) DownloadEvent(zlc.season.rxdownload2.entity.DownloadEvent) DownloadStatus(zlc.season.rxdownload2.entity.DownloadStatus)

Example 7 with DownloadStatus

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());
}
Also used : DownloadStatus(zlc.season.rxdownload2.entity.DownloadStatus)

Example 8 with DownloadStatus

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;
}
Also used : DownloadEvent(zlc.season.rxdownload2.entity.DownloadEvent) DownloadMission(zlc.season.rxdownload2.entity.DownloadMission) File(java.io.File) DownloadRecord(zlc.season.rxdownload2.entity.DownloadRecord)

Aggregations

DownloadStatus (zlc.season.rxdownload2.entity.DownloadStatus)6 DownloadEvent (zlc.season.rxdownload2.entity.DownloadEvent)4 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Cursor (android.database.Cursor)1 Consumer (io.reactivex.functions.Consumer)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 RandomAccessFile (java.io.RandomAccessFile)1 MappedByteBuffer (java.nio.MappedByteBuffer)1 FileChannel (java.nio.channels.FileChannel)1 DownloadMission (zlc.season.rxdownload2.entity.DownloadMission)1 DownloadRecord (zlc.season.rxdownload2.entity.DownloadRecord)1