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

The following examples show how to use com.liulishuo.filedownloader.model.FileDownloadStatus#error() . 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: CacheDownloadingAdapter.java    From YCAudioPlayer with Apache License 2.0 6 votes vote down vote up
@Override
public void updateNotDownloaded(int status, long sofar, long total) {
    AppLogUtils.e("ViewHolder----"+"updateNotDownloaded--------"+status+"---"+sofar+"---"+total);
    if (sofar > 0 && total > 0) {
        final float percent = sofar / (float) total;
        pb.setProgress((int) (percent * 100));
    } else {
        pb.setProgress(0);
    }
    switch (status) {
        case FileDownloadStatus.error:
            ivDownload.setBackgroundResource(R.drawable.ic_note_btn_play_white);
            ivDownload.setTag(R.drawable.ic_note_btn_play_white);
            tvState.setText("错误");
            break;
        case FileDownloadStatus.paused:
            ivDownload.setBackgroundResource(R.drawable.ic_note_btn_play_white);
            ivDownload.setTag(R.drawable.ic_note_btn_play_white);
            tvState.setText("暂停");
            break;
        default:
            ivDownload.setBackgroundResource(R.drawable.ic_note_btn_play_white);
            ivDownload.setTag(R.drawable.ic_note_btn_play_white);
            break;
    }
}
 
Example 2
Source File: DialogListAdapter.java    From YCAudioPlayer with Apache License 2.0 6 votes vote down vote up
@Override
public void updateNotDownloaded(int status, long sofar, long total) {
    AppLogUtils.e("ViewHolder----"+"updateNotDownloaded--------"+status+"---"+sofar+"---"+total);
    if (sofar > 0 && total > 0) {
        final float percent = sofar / (float) total;
        circlePb.setProgress((int) (percent * 100));
    } else {
        circlePb.setProgress(0);
    }
    switch (status) {
        case FileDownloadStatus.error:
            ivDownload.setBackgroundResource(R.drawable.icon_cache_download);
            tvState.setText("错误");
            break;
        case FileDownloadStatus.paused:
            ivDownload.setBackgroundResource(R.drawable.icon_cache_download);
            tvState.setText("暂停");
            break;
        default:
            ivDownload.setBackgroundResource(R.drawable.icon_cache_download);
            break;
    }
    tvState.setTag(STATE_START);
}
 
Example 3
Source File: TasksManagerDemoActivity.java    From FileDownloader with Apache License 2.0 6 votes vote down vote up
public void updateNotDownloaded(final int status, final long sofar, final long total) {
    if (sofar > 0 && total > 0) {
        final float percent = sofar
                / (float) total;
        taskPb.setMax(100);
        taskPb.setProgress((int) (percent * 100));
    } else {
        taskPb.setMax(1);
        taskPb.setProgress(0);
    }

    switch (status) {
        case FileDownloadStatus.error:
            taskStatusTv.setText(R.string.tasks_manager_demo_status_error);
            break;
        case FileDownloadStatus.paused:
            taskStatusTv.setText(R.string.tasks_manager_demo_status_paused);
            break;
        default:
            taskStatusTv.setText(R.string.tasks_manager_demo_status_not_downloaded);
            break;
    }
    taskActionBtn.setText(R.string.start);
}
 
Example 4
Source File: DownloadHelper.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
private int getDownloadResult(DownloadMissionEntity entity) {
    switch (FileDownloader.getImpl().getStatus((int) entity.missionId, entity.getFilePath())) {
        case FileDownloadStatus.completed:
            return RESULT_SUCCEED;

        case FileDownloadStatus.error:
        case FileDownloadStatus.warn:
        case FileDownloadStatus.paused:
            return RESULT_FAILED;

        default:
            return RESULT_DOWNLOADING;
    }
}
 
Example 5
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 6
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 7
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 8
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 9
Source File: SmallMessageSnapshot.java    From FileDownloader with Apache License 2.0 4 votes vote down vote up
@Override
public byte getStatus() {
    return FileDownloadStatus.error;
}
 
Example 10
Source File: LargeMessageSnapshot.java    From FileDownloader with Apache License 2.0 4 votes vote down vote up
@Override
public byte getStatus() {
    return FileDownloadStatus.error;
}
 
Example 11
Source File: FileDownloadList.java    From FileDownloader with Apache License 2.0 4 votes vote down vote up
/**
 * @param willRemoveDownload will be remove
 */
public boolean remove(final BaseDownloadTask.IRunningTask willRemoveDownload,
                      MessageSnapshot snapshot) {
    final byte removeByStatus = snapshot.getStatus();
    boolean succeed;
    synchronized (mList) {
        succeed = mList.remove(willRemoveDownload);
        if (succeed && mList.size() == 0) {
            if (FileDownloadServiceProxy.getImpl().isRunServiceForeground()) {
                FileDownloader.getImpl().stopForeground(true);
            }
        }
    }
    if (FileDownloadLog.NEED_LOG) {
        if (mList.size() == 0) {
            FileDownloadLog.v(this, "remove %s left %d %d",
                    willRemoveDownload, removeByStatus, mList.size());
        }
    }

    if (succeed) {
        final IFileDownloadMessenger messenger = willRemoveDownload.getMessageHandler().
                getMessenger();
        // Notify 2 Listener
        switch (removeByStatus) {
            case FileDownloadStatus.warn:
                messenger.notifyWarn(snapshot);
                break;
            case FileDownloadStatus.error:
                messenger.notifyError(snapshot);
                break;
            case FileDownloadStatus.paused:
                messenger.notifyPaused(snapshot);
                break;
            case FileDownloadStatus.completed:
                messenger
                        .notifyBlockComplete(MessageSnapshotTaker.takeBlockCompleted(snapshot));
                break;
            default:
                // ignored
        }
    } else {
        FileDownloadLog.e(this, "remove error, not exist: %s %d", willRemoveDownload,
                removeByStatus);
    }

    return succeed;
}
 
Example 12
Source File: DownloadTaskHunter.java    From FileDownloader with Apache License 2.0 4 votes vote down vote up
@Override
public MessageSnapshot prepareErrorMessage(Throwable cause) {
    mStatus = FileDownloadStatus.error;
    mThrowable = cause;
    return MessageSnapshotTaker.catchException(getId(), getSofarBytes(), cause);
}