Search in sources :

Example 1 with DownloadEvent

use of zlc.season.rxdownload2.entity.DownloadEvent in project RxDownload by ssseasonnn.

the class DownloadEventFactory method createEvent.

private static DownloadEvent createEvent(int flag, DownloadStatus status, Throwable throwable) {
    DownloadEvent event = createEvent(flag, status);
    event.setError(throwable);
    return event;
}
Also used : DownloadEvent(zlc.season.rxdownload2.entity.DownloadEvent)

Example 2 with DownloadEvent

use of zlc.season.rxdownload2.entity.DownloadEvent in project RxDownload by ssseasonnn.

the class DownloadEventFactory method createEvent.

public static DownloadEvent createEvent(int flag, DownloadStatus status) {
    DownloadEvent event = new DownloadEvent();
    event.setDownloadStatus(status == null ? new DownloadStatus() : status);
    event.setFlag(flag);
    return event;
}
Also used : DownloadEvent(zlc.season.rxdownload2.entity.DownloadEvent) DownloadStatus(zlc.season.rxdownload2.entity.DownloadStatus)

Example 3 with DownloadEvent

use of zlc.season.rxdownload2.entity.DownloadEvent 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 4 with DownloadEvent

use of zlc.season.rxdownload2.entity.DownloadEvent 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 5 with DownloadEvent

use of zlc.season.rxdownload2.entity.DownloadEvent 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

DownloadEvent (zlc.season.rxdownload2.entity.DownloadEvent)4 DownloadStatus (zlc.season.rxdownload2.entity.DownloadStatus)3 Consumer (io.reactivex.functions.Consumer)1 File (java.io.File)1 DownloadMission (zlc.season.rxdownload2.entity.DownloadMission)1 DownloadRecord (zlc.season.rxdownload2.entity.DownloadRecord)1