Java Code Examples for com.liulishuo.filedownloader.model.FileDownloadStatus#completed()
The following examples show how to use
com.liulishuo.filedownloader.model.FileDownloadStatus#completed() .
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: FileDownloaderExecutor.java From Mysplash with GNU Lesser General Public License v3.0 | 6 votes |
private static void finishTask(Context context, @NonNull DownloadTask entity) { boolean complete = FileDownloader.getImpl() .getStatus((int) entity.taskId, entity.getFilePath(context)) == FileDownloadStatus.completed; if (complete) { innerUpdateTaskResult(entity, DownloadTask.RESULT_SUCCEED); context.sendBroadcast( new Intent( Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse(entity.getFilePath(context)) ) ); if (entity.downloadType != DownloadTask.COLLECTION_TYPE) { downloadPhotoSuccess(context, entity); } else { downloadCollectionSuccess(context, entity); } } else { FileDownloadUtils.deleteTempFile(FileDownloadUtils.getTempPath(entity.getFilePath(context))); innerUpdateTaskResult(entity, DownloadTask.RESULT_FAILED); if (entity.downloadType != DownloadTask.COLLECTION_TYPE) { downloadPhotoFailed(context, entity); } else { downloadCollectionFailed(context, entity); } } }
Example 2
Source File: FileDownloader.java From FileDownloader with Apache License 2.0 | 6 votes |
/** * @param id The downloadId. * @param path The target file path. * @return the downloading status. * @see FileDownloadStatus * @see #getStatus(String, String) * @see #getStatusIgnoreCompleted(int) */ public byte getStatus(final int id, final String path) { byte status; BaseDownloadTask.IRunningTask task = FileDownloadList.getImpl().get(id); if (task == null) { status = FileDownloadServiceProxy.getImpl().getStatus(id); } else { status = task.getOrigin().getStatus(); } if (path != null && status == FileDownloadStatus.INVALID_STATUS) { if (FileDownloadUtils.isFilenameConverted(FileDownloadHelper.getAppContext()) && new File(path).exists()) { status = FileDownloadStatus.completed; } } return status; }
Example 3
Source File: DownloadManager.java From v9porn with MIT License | 5 votes |
/** * 实时保存下载信息 * * @param task 任务信息 */ private void saveDownloadInfo(BaseDownloadTask task) { V9PornItem v9PornItem = dataManager.findV9PornItemByDownloadId(task.getId()); if (v9PornItem == null) { //不存在的任务清除掉 FileDownloader.getImpl().clear(task.getId(), task.getPath()); if (!BuildConfig.DEBUG) { // Bugsnag.notify(new Throwable(TAG + "::save download info failure:" + task.getUrl()), Severity.WARNING); } return; } int soFarBytes = task.getSmallFileSoFarBytes(); int totalBytes = task.getSmallFileTotalBytes(); if (soFarBytes > 0) { v9PornItem.setSoFarBytes(soFarBytes); } if (totalBytes > 0) { v9PornItem.setTotalFarBytes(totalBytes); } if (totalBytes > 0) { int p = (int) (((float) soFarBytes / totalBytes) * 100); v9PornItem.setProgress(p); } if (task.getStatus() == FileDownloadStatus.completed) { v9PornItem.setFinishedDownloadDate(new Date()); } v9PornItem.setSpeed(task.getSpeed()); v9PornItem.setStatus(task.getStatus()); dataManager.updateV9PornItem(v9PornItem); if (task.getStatus() == FileDownloadStatus.completed) { complete(task); } else { update(task); } }
Example 4
Source File: DownloadManager.java From v9porn with MIT License | 5 votes |
/** * 实时保存下载信息 * * @param task 任务信息 */ private void saveDownloadInfo(BaseDownloadTask task) { V9PornItem v9PornItem = dataManager.findV9PornItemByDownloadId(task.getId()); if (v9PornItem == null) { //不存在的任务清除掉 FileDownloader.getImpl().clear(task.getId(), task.getPath()); if (!BuildConfig.DEBUG) { // Bugsnag.notify(new Throwable(TAG + "::save download info failure:" + task.getUrl()), Severity.WARNING); } return; } int soFarBytes = task.getSmallFileSoFarBytes(); int totalBytes = task.getSmallFileTotalBytes(); if (soFarBytes > 0) { v9PornItem.setSoFarBytes(soFarBytes); } if (totalBytes > 0) { v9PornItem.setTotalFarBytes(totalBytes); } if (totalBytes > 0) { int p = (int) (((float) soFarBytes / totalBytes) * 100); v9PornItem.setProgress(p); } if (task.getStatus() == FileDownloadStatus.completed) { v9PornItem.setFinishedDownloadDate(new Date()); } v9PornItem.setSpeed(task.getSpeed()); v9PornItem.setStatus(task.getStatus()); dataManager.updateV9PornItem(v9PornItem); if (task.getStatus() == FileDownloadStatus.completed) { complete(task); } else { update(task); } }
Example 5
Source File: FileDownloadBroadcastHandler.java From FileDownloader with Apache License 2.0 | 5 votes |
public static void sendCompletedBroadcast(FileDownloadModel model) { if (model == null) throw new IllegalArgumentException(); if (model.getStatus() != FileDownloadStatus.completed) throw new IllegalStateException(); final Intent intent = new Intent(ACTION_COMPLETED); intent.putExtra(KEY_MODEL, model); FileDownloadHelper.getAppContext().sendBroadcast(intent); }
Example 6
Source File: FileDownloadLine.java From FileDownloader with Apache License 2.0 | 5 votes |
/** * The {@link FileDownloader#getStatus(int, String)} request. */ public byte getStatus(final int id, final String path) { if (FileDownloader.getImpl().isServiceConnected()) { return FileDownloader.getImpl().getStatus(id, path); } if (path != null && new File(path).exists()) { return FileDownloadStatus.completed; } final ConnectSubscriber subscriber = new ConnectSubscriber() { private byte mValue; @Override public void connected() { mValue = FileDownloader.getImpl().getStatus(id, path); } @Override public Object getValue() { return mValue; } }; wait(subscriber); return (byte) subscriber.getValue(); }
Example 7
Source File: FileDownloadUtils.java From okdownload with Apache License 2.0 | 5 votes |
public static byte convertDownloadStatus(final StatusUtil.Status status) { switch (status) { case COMPLETED: return FileDownloadStatus.completed; case IDLE: return FileDownloadStatus.paused; case PENDING: return FileDownloadStatus.pending; case RUNNING: return FileDownloadStatus.progress; default: return FileDownloadStatus.INVALID_STATUS; } }
Example 8
Source File: DownloadHelper.java From Mysplash with GNU Lesser General Public License v3.0 | 5 votes |
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 9
Source File: BlockCompleteMessage.java From FileDownloader with Apache License 2.0 | 5 votes |
public BlockCompleteMessageImpl(MessageSnapshot snapshot) { super(snapshot.getId()); if (snapshot.getStatus() != FileDownloadStatus.completed) { throw new IllegalArgumentException(FileDownloadUtils.formatString( "can't create the block complete message for id[%d], status[%d]", snapshot.getId(), snapshot.getStatus())); } this.mCompletedSnapshot = snapshot; }
Example 10
Source File: MessageSnapshotTaker.java From FileDownloader with Apache License 2.0 | 5 votes |
public static MessageSnapshot takeBlockCompleted(MessageSnapshot snapshot) { if (snapshot.getStatus() != FileDownloadStatus.completed) { throw new IllegalStateException( FileDownloadUtils.formatString("take block completed snapshot, must has " + "already be completed. %d %d", snapshot.getId(), snapshot.getStatus())); } return new BlockCompleteMessage.BlockCompleteMessageImpl(snapshot); }
Example 11
Source File: DownloadVideoAdapter.java From v9porn with MIT License | 4 votes |
@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 12
Source File: FileDownloadList.java From FileDownloader with Apache License 2.0 | 4 votes |
/** * @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 13
Source File: LargeMessageSnapshot.java From FileDownloader with Apache License 2.0 | 4 votes |
@Override public byte getStatus() { return FileDownloadStatus.completed; }
Example 14
Source File: SmallMessageSnapshot.java From FileDownloader with Apache License 2.0 | 4 votes |
@Override public byte getStatus() { return FileDownloadStatus.completed; }
Example 15
Source File: MessageSnapshot.java From FileDownloader with Apache License 2.0 | 4 votes |
@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 16
Source File: NotificationSampleActivity.java From FileDownloader with Apache License 2.0 | 4 votes |
@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 17
Source File: DownloadVideoAdapter.java From v9porn with MIT License | 4 votes |
@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 18
Source File: FileDownloader.java From okdownload with Apache License 2.0 | 3 votes |
/** * Task id will change in OkDownload, so cannot use id to get status. * Please use {@linkplain #getStatus(String, String)} * @return The downloading status without cover the completed status (if completed you will * receive * {@link FileDownloadStatus#INVALID_STATUS} ). */ @Deprecated public byte getStatusIgnoreCompleted(final int id) { byte status = getStatus(id, null); if (status == FileDownloadStatus.completed) status = FileDownloadStatus.INVALID_STATUS; return status; }
Example 19
Source File: TasksManagerDemoActivity.java From FileDownloader with Apache License 2.0 | 2 votes |
/** * @param status Download Status * @return has already downloaded * @see FileDownloadStatus */ public boolean isDownloaded(final int status) { return status == FileDownloadStatus.completed; }
Example 20
Source File: TasksManager.java From YCAudioPlayer with Apache License 2.0 | 2 votes |
/** * 判断是否下载完成 * @param status 下载状态 * @return 是否下载完成 * @see FileDownloadStatus */ public boolean isDownloaded(final int status) { return status == FileDownloadStatus.completed; }