Java Code Examples for com.liulishuo.filedownloader.model.FileDownloadStatus#INVALID_STATUS

The following examples show how to use com.liulishuo.filedownloader.model.FileDownloadStatus#INVALID_STATUS . 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: FileDownloader.java    From FileDownloader with Apache License 2.0 6 votes vote down vote up
/**
 * @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 2
Source File: FileDownloadList.java    From FileDownloader with Apache License 2.0 6 votes vote down vote up
List<BaseDownloadTask.IRunningTask> getReceiveServiceTaskList(final int id) {
    final List<BaseDownloadTask.IRunningTask> list = new ArrayList<>();
    synchronized (this.mList) {
        for (BaseDownloadTask.IRunningTask task : this.mList) {
            if (task.is(id) && !task.isOver()) {

                final byte status = task.getOrigin().getStatus();
                if (status != FileDownloadStatus.INVALID_STATUS
                        && status != FileDownloadStatus.toLaunchPool) {
                    list.add(task);
                }
            }
        }
    }

    return list;
}
 
Example 3
Source File: DownloadTaskHunter.java    From FileDownloader with Apache License 2.0 6 votes vote down vote up
@Override
public void reset() {
    mThrowable = null;

    mEtag = null;
    mIsResuming = false;
    mRetryingTimes = 0;
    mIsReusedOldFile = false;
    mIsLargeFile = false;

    mSoFarBytes = 0;
    mTotalBytes = 0;

    mSpeedMonitor.reset();

    if (FileDownloadStatus.isOver(mStatus)) {
        mMessenger.discard();
        mMessenger = new FileDownloadMessenger(mTask.getRunningTask(), this);
    } else {
        mMessenger.reAppointment(mTask.getRunningTask(), this);
    }

    mStatus = FileDownloadStatus.INVALID_STATUS;
}
 
Example 4
Source File: FileDownloader.java    From okdownload with Apache License 2.0 5 votes vote down vote up
/**
 * Task id will change in OkDownload, so cannot use id to get status.
 * Please use {@linkplain #getStatus(String, String)}
 */
@Deprecated
public byte getStatus(final int id, final String path) {
    byte status;
    BaseDownloadTask.IRunningTask task = FileDownloadList.getImpl().get(id);
    if (task == null) {
        return FileDownloadStatus.INVALID_STATUS;
    } else {
        status = task.getOrigin().getStatus();
    }

    return status;
}
 
Example 5
Source File: FileDownloadUtils.java    From okdownload with Apache License 2.0 5 votes vote down vote up
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 6
Source File: FileDownloadManager.java    From FileDownloader with Apache License 2.0 5 votes vote down vote up
public byte getStatus(final int id) {
    final FileDownloadModel model = mDatabase.find(id);
    if (model == null) {
        return FileDownloadStatus.INVALID_STATUS;
    }

    return model.getStatus();
}
 
Example 7
Source File: FileDownloadServiceUIGuard.java    From FileDownloader with Apache License 2.0 5 votes vote down vote up
@Override
public byte getStatus(final int id) {
    if (!isConnected()) {
        return DownloadServiceNotConnectedHelper.getStatus(id);
    }

    byte status = FileDownloadStatus.INVALID_STATUS;
    try {
        status = getService().getStatus(id);
    } catch (RemoteException e) {
        e.printStackTrace();
    }

    return status;
}
 
Example 8
Source File: DownloadTaskHunter.java    From FileDownloader with Apache License 2.0 5 votes vote down vote up
@Override
public void free() {
    if (FileDownloadLog.NEED_LOG) {
        FileDownloadLog.d(this, "free the task %d, when the status is %d", getId(), mStatus);
    }
    mStatus = FileDownloadStatus.INVALID_STATUS;
}
 
Example 9
Source File: StatusAssist.java    From okdownload with Apache License 2.0 4 votes vote down vote up
public synchronized boolean isUsing() {
    return getStatus() != FileDownloadStatus.INVALID_STATUS;
}
 
Example 10
Source File: QueuesHandler.java    From FileDownloader with Apache License 2.0 4 votes vote down vote up
@Override
public boolean handleMessage(final Message msg) {
    if (msg.what == WHAT_SERIAL_NEXT) {
        if (msg.arg1 >= mList.size()) {
            synchronized (mRunningSerialMap) {
                mRunningSerialMap.remove(mList.get(0).getAttachKey());
            }
            // final serial tasks
            if (this.mHandler != null && this.mHandler.getLooper() != null) {
                this.mHandler.getLooper().quit();
                this.mHandler = null;
                this.mList = null;
                this.mSerialFinishListener = null;
            }

            if (FileDownloadLog.NEED_LOG) {
                FileDownloadLog.d(SerialHandlerCallback.class, "final serial %s %d",
                        this.mList == null ? null : this.mList.get(0) == null
                                ? null : this.mList.get(0).getOrigin().getListener(),
                        msg.arg1);
            }
            return true;
        }

        mRunningIndex = msg.arg1;
        final BaseDownloadTask.IRunningTask stackTopTask = this.mList.get(mRunningIndex);
        synchronized (stackTopTask.getPauseLock()) {
            if (stackTopTask.getOrigin().getStatus() != FileDownloadStatus.INVALID_STATUS
                    || FileDownloadList.getImpl().isNotContains(stackTopTask)) {
                // pause?
                if (FileDownloadLog.NEED_LOG) {
                    FileDownloadLog.d(SerialHandlerCallback.class,
                            "direct go next by not contains %s %d", stackTopTask, msg.arg1);
                }
                goNext(msg.arg1 + 1);
                return true;
            }

            stackTopTask.getOrigin()
                    .addFinishListener(
                            mSerialFinishListener.setNextIndex(mRunningIndex + 1));
            stackTopTask.startTaskByQueue();
        }

    } else if (msg.what == WHAT_FREEZE) {
        freeze();
    } else if (msg.what == WHAT_UNFREEZE) {
        unfreeze();
    }
    return true;
}
 
Example 11
Source File: DownloadTaskHunter.java    From FileDownloader with Apache License 2.0 4 votes vote down vote up
@Override
public void intoLaunchPool() {
    synchronized (mPauseLock) {
        if (mStatus != FileDownloadStatus.INVALID_STATUS) {
            FileDownloadLog.w(this, "High concurrent cause, this task %d will not input "
                            + "to launch pool, because of the status isn't idle : %d",
                    getId(), mStatus);
            return;
        }

        mStatus = FileDownloadStatus.toLaunchPool;
    }

    final BaseDownloadTask.IRunningTask runningTask = mTask.getRunningTask();
    final BaseDownloadTask origin = runningTask.getOrigin();

    if (FileDownloadMonitor.isValid()) {
        FileDownloadMonitor.getMonitor().onRequestStart(origin);
    }

    if (FileDownloadLog.NEED_LOG) {
        FileDownloadLog.v(this, "call start "
                        + "Url[%s], Path[%s] Listener[%s], Tag[%s]",
                origin.getUrl(), origin.getPath(), origin.getListener(), origin.getTag());
    }

    boolean ready = true;

    try {
        prepare();
    } catch (Throwable e) {
        ready = false;

        FileDownloadList.getImpl().add(runningTask);
        FileDownloadList.getImpl().remove(runningTask, prepareErrorMessage(e));
    }

    if (ready) {
        FileDownloadTaskLauncher.getImpl().launch(this);
    }

    if (FileDownloadLog.NEED_LOG) {
        FileDownloadLog.v(this, "the task[%d] has been into the launch pool.", getId());
    }
}
 
Example 12
Source File: DownloadServiceNotConnectedHelper.java    From FileDownloader with Apache License 2.0 4 votes vote down vote up
public static byte getStatus(final int id) {
    log("request get the status for the task[%d] in the download service", id);
    return FileDownloadStatus.INVALID_STATUS;
}
 
Example 13
Source File: DownloadTask.java    From FileDownloader with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isUsing() {
    return mHunter.getStatus() != FileDownloadStatus.INVALID_STATUS;
}
 
Example 14
Source File: FileDownloader.java    From okdownload with Apache License 2.0 3 votes vote down vote up
/**
 * 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;
}