Java Code Examples for com.liulishuo.filedownloader.model.FileDownloadStatus#retry()

The following examples show how to use com.liulishuo.filedownloader.model.FileDownloadStatus#retry() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DownloadStatusCallback.java    From FileDownloader with Apache License 2.0 6 votes vote down vote up
@Override
public boolean handleMessage(Message msg) {
    handlingMessage = true;
    final int status = msg.what;

    try {
        switch (status) {
            case FileDownloadStatus.progress:
                handleProgress();
                break;
            case FileDownloadStatus.retry:
                handleRetry((Exception) msg.obj, msg.arg1);
                break;
            default:
                // ignored.
        }
    } finally {
        handlingMessage = false;
        if (parkThread != null) LockSupport.unpark(parkThread);
    }


    return true;
}
 
Example 2
Source File: DownloadVideoAdapter.java    From v9porn with MIT License 4 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, V9PornItem item) {
    helper.setText(R.id.tv_91porn_item_title, item.getTitleWithDuration());
    ImageView simpleDraweeView = helper.getView(R.id.iv_91porn_item_img);
    Uri uri = Uri.parse(item.getImgUrl());
    GlideApp.with(helper.itemView).load(uri).placeholder(R.drawable.placeholder).transition(new DrawableTransitionOptions().crossFade(300)).into(simpleDraweeView);
    helper.setProgress(R.id.progressBar_download, item.getProgress());
    helper.setText(R.id.tv_download_progress, String.valueOf(item.getProgress()) + "%");
    helper.setText(R.id.tv_download_filesize, Formatter.formatFileSize(helper.itemView.getContext(), item.getSoFarBytes()).replace("MB", "") + "/ " + Formatter.formatFileSize(helper.itemView.getContext(), item.getTotalFarBytes()));
    if (item.getStatus() == FileDownloadStatus.completed) {
        helper.setText(R.id.tv_download_speed, "已完成");
        helper.setVisible(R.id.iv_download_control, false);
    } else {
        //未下载完成,显示控制
        helper.setVisible(R.id.iv_download_control, true);
        if (FileDownloader.getImpl().isServiceConnected()) {
            helper.setImageResource(R.id.iv_download_control, R.drawable.pause_download);
            if (item.getStatus() == FileDownloadStatus.progress) {
                helper.setText(R.id.tv_download_speed, item.getSpeed() + " KB/s");
            } else if (item.getStatus() == FileDownloadStatus.paused) {
                helper.setText(R.id.tv_download_speed, "暂停中");
                helper.setImageResource(R.id.iv_download_control, R.drawable.start_download);
            } else if (item.getStatus() == FileDownloadStatus.pending) {
                helper.setText(R.id.tv_download_speed, "准备中");
            } else if (item.getStatus() == FileDownloadStatus.started) {
                helper.setText(R.id.tv_download_speed, "开始下载");
            } else if (item.getStatus() == FileDownloadStatus.connected) {
                helper.setText(R.id.tv_download_speed, "连接中");
            } else if (item.getStatus() == FileDownloadStatus.error) {
                helper.setText(R.id.tv_download_speed, "下载错误");
                helper.setImageResource(R.id.iv_download_control, R.drawable.start_download);
            } else if (item.getStatus() == FileDownloadStatus.retry) {
                helper.setText(R.id.tv_download_speed, "重试中");
            } else if (item.getStatus() == FileDownloadStatus.warn) {
                helper.setText(R.id.tv_download_speed, "警告");
                helper.setImageResource(R.id.iv_download_control, R.drawable.start_download);
            }

        } else {
            helper.setText(R.id.tv_download_speed, "暂停中");
            helper.setImageResource(R.id.iv_download_control, R.drawable.start_download);
        }
    }
    helper.addOnClickListener(R.id.iv_download_control);
    helper.addOnClickListener(R.id.right_menu_delete);
}
 
Example 3
Source File: DownloadVideoAdapter.java    From v9porn with MIT License 4 votes vote down vote up
@Override
protected void convert(BaseViewHolder helper, V9PornItem item) {
    helper.setText(R.id.tv_91porn_item_title, item.getTitleWithDuration());
    ImageView simpleDraweeView = helper.getView(R.id.iv_91porn_item_img);
    Uri uri = Uri.parse(item.getImgUrl());
    GlideApp.with(helper.itemView).load(uri).placeholder(R.drawable.placeholder).transition(new DrawableTransitionOptions().crossFade(300)).into(simpleDraweeView);
    helper.setProgress(R.id.progressBar_download, item.getProgress());
    helper.setText(R.id.tv_download_progress, String.valueOf(item.getProgress()) + "%");
    helper.setText(R.id.tv_download_filesize, Formatter.formatFileSize(helper.itemView.getContext(), item.getSoFarBytes()).replace("MB", "") + "/ " + Formatter.formatFileSize(helper.itemView.getContext(), item.getTotalFarBytes()));
    if (item.getStatus() == FileDownloadStatus.completed) {
        helper.setText(R.id.tv_download_speed, "已完成");
        helper.setVisible(R.id.iv_download_control, false);
    } else {
        //未下载完成,显示控制
        helper.setVisible(R.id.iv_download_control, true);
        if (FileDownloader.getImpl().isServiceConnected()) {
            helper.setImageResource(R.id.iv_download_control, R.drawable.pause_download);
            if (item.getStatus() == FileDownloadStatus.progress) {
                helper.setText(R.id.tv_download_speed, item.getSpeed() + " KB/s");
            } else if (item.getStatus() == FileDownloadStatus.paused) {
                helper.setText(R.id.tv_download_speed, "暂停中");
                helper.setImageResource(R.id.iv_download_control, R.drawable.start_download);
            } else if (item.getStatus() == FileDownloadStatus.pending) {
                helper.setText(R.id.tv_download_speed, "准备中");
            } else if (item.getStatus() == FileDownloadStatus.started) {
                helper.setText(R.id.tv_download_speed, "开始下载");
            } else if (item.getStatus() == FileDownloadStatus.connected) {
                helper.setText(R.id.tv_download_speed, "连接中");
            } else if (item.getStatus() == FileDownloadStatus.error) {
                helper.setText(R.id.tv_download_speed, "下载错误");
                helper.setImageResource(R.id.iv_download_control, R.drawable.start_download);
            } else if (item.getStatus() == FileDownloadStatus.retry) {
                helper.setText(R.id.tv_download_speed, "重试中");
            } else if (item.getStatus() == FileDownloadStatus.warn) {
                helper.setText(R.id.tv_download_speed, "警告");
                helper.setImageResource(R.id.iv_download_control, R.drawable.start_download);
            }

        } else {
            helper.setText(R.id.tv_download_speed, "暂停中");
            helper.setImageResource(R.id.iv_download_control, R.drawable.start_download);
        }
    }
    helper.addOnClickListener(R.id.iv_download_control);
    helper.addOnClickListener(R.id.right_menu_delete);
}
 
Example 4
Source File: NotificationSampleActivity.java    From FileDownloader with Apache License 2.0 4 votes vote down vote up
@Override
public void show(boolean statusChanged, int status, boolean isShowProgress) {
    String desc = "";
    switch (status) {
        case FileDownloadStatus.pending:
            desc += " pending";
            builder.setProgress(getTotal(), getSofar(), true);
            break;
        case FileDownloadStatus.started:
            desc += " started";
            builder.setProgress(getTotal(), getSofar(), true);
            break;
        case FileDownloadStatus.progress:
            desc += " progress";
            builder.setProgress(getTotal(), getSofar(), getTotal() <= 0);
            break;
        case FileDownloadStatus.retry:
            desc += " retry";
            builder.setProgress(getTotal(), getSofar(), true);
            break;
        case FileDownloadStatus.error:
            desc += " error";
            builder.setProgress(getTotal(), getSofar(), false);
            break;
        case FileDownloadStatus.paused:
            desc += " paused";
            builder.setProgress(getTotal(), getSofar(), false);
            break;
        case FileDownloadStatus.completed:
            desc += " completed";
            builder.setProgress(getTotal(), getSofar(), false);
            break;
        case FileDownloadStatus.warn:
            desc += " warn";
            builder.setProgress(0, 0, true);
            break;
    }

    builder.setContentTitle(getTitle()).setContentText(desc);
    getManager().notify(getId(), builder.build());
}
 
Example 5
Source File: MessageSnapshot.java    From FileDownloader with Apache License 2.0 4 votes vote down vote up
@Override
public MessageSnapshot createFromParcel(Parcel source) {
    boolean largeFile = source.readByte() == 1;
    byte status = source.readByte();
    final MessageSnapshot snapshot;
    switch (status) {
        case FileDownloadStatus.pending:
            if (largeFile) {
                snapshot = new LargeMessageSnapshot.PendingMessageSnapshot(source);
            } else {
                snapshot = new SmallMessageSnapshot.PendingMessageSnapshot(source);
            }
            break;
        case FileDownloadStatus.started:
            snapshot = new StartedMessageSnapshot(source);
            break;
        case FileDownloadStatus.connected:
            if (largeFile) {
                snapshot = new LargeMessageSnapshot.ConnectedMessageSnapshot(source);
            } else {
                snapshot = new SmallMessageSnapshot.ConnectedMessageSnapshot(source);
            }
            break;
        case FileDownloadStatus.progress:
            if (largeFile) {
                snapshot = new LargeMessageSnapshot.ProgressMessageSnapshot(source);
            } else {
                snapshot = new SmallMessageSnapshot.ProgressMessageSnapshot(source);
            }
            break;
        case FileDownloadStatus.retry:
            if (largeFile) {
                snapshot = new LargeMessageSnapshot.RetryMessageSnapshot(source);
            } else {
                snapshot = new SmallMessageSnapshot.RetryMessageSnapshot(source);
            }
            break;
        case FileDownloadStatus.error:
            if (largeFile) {
                snapshot = new LargeMessageSnapshot.ErrorMessageSnapshot(source);
            } else {
                snapshot = new SmallMessageSnapshot.ErrorMessageSnapshot(source);
            }
            break;
        case FileDownloadStatus.completed:
            if (largeFile) {
                snapshot = new LargeMessageSnapshot.CompletedSnapshot(source);
            } else {
                snapshot = new SmallMessageSnapshot.CompletedSnapshot(source);
            }
            break;
        case FileDownloadStatus.warn:
            if (largeFile) {
                snapshot = new LargeMessageSnapshot.WarnMessageSnapshot(source);
            } else {
                snapshot = new SmallMessageSnapshot.WarnMessageSnapshot(source);
            }
            break;
        default:
            snapshot = null;
    }

    if (snapshot != null) {
        snapshot.isLargeFile = largeFile;
    } else {
        throw new IllegalStateException("Can't restore the snapshot because unknown "
                + "status: " + status);
    }

    return snapshot;
}
 
Example 6
Source File: SmallMessageSnapshot.java    From FileDownloader with Apache License 2.0 4 votes vote down vote up
@Override
public byte getStatus() {
    return FileDownloadStatus.retry;
}
 
Example 7
Source File: LargeMessageSnapshot.java    From FileDownloader with Apache License 2.0 4 votes vote down vote up
@Override
public byte getStatus() {
    return FileDownloadStatus.retry;
}