Search in sources :

Example 21 with DownloadInfo

use of com.hippo.ehviewer.dao.DownloadInfo in project EhViewer by seven332.

the class DownloadManager method changeLabel.

/**
 * @param label Not allow new label
 */
public void changeLabel(List<DownloadInfo> list, String label) {
    if (null != label && !containLabel(label)) {
        Log.e(TAG, "Not exits label: " + label);
        return;
    }
    List<DownloadInfo> dstList = getInfoListForLabel(label);
    if (dstList == null) {
        Log.e(TAG, "Can't find label with label: " + label);
        return;
    }
    for (DownloadInfo info : list) {
        if (ObjectUtils.equal(info.label, label)) {
            continue;
        }
        List<DownloadInfo> srcList = getInfoListForLabel(info.label);
        if (srcList == null) {
            Log.e(TAG, "Can't find label with label: " + info.label);
            continue;
        }
        srcList.remove(info);
        dstList.add(info);
        info.label = label;
        Collections.sort(dstList, DATE_DESC_COMPARATOR);
        // Save to DB
        EhDB.putDownloadInfo(info);
    }
    for (DownloadInfoListener l : mDownloadInfoListeners) {
        l.onReload();
    }
}
Also used : DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo)

Example 22 with DownloadInfo

use of com.hippo.ehviewer.dao.DownloadInfo in project EhViewer by seven332.

the class DownloadManager method stopCurrentDownload.

void stopCurrentDownload() {
    DownloadInfo info = stopCurrentDownloadInternal();
    if (info != null) {
        // Update listener
        List<DownloadInfo> list = getInfoListForLabel(info.label);
        if (list != null) {
            for (DownloadInfoListener l : mDownloadInfoListeners) {
                l.onUpdate(info, list);
            }
        }
        // Ensure download
        ensureDownload();
    }
}
Also used : DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo)

Example 23 with DownloadInfo

use of com.hippo.ehviewer.dao.DownloadInfo in project EhViewer by seven332.

the class DownloadManager method ensureDownload.

private void ensureDownload() {
    if (mCurrentTask != null) {
        // Only one download
        return;
    }
    // Get download from wait list
    if (!mWaitList.isEmpty()) {
        DownloadInfo info = mWaitList.removeFirst();
        SpiderQueen spider = SpiderQueen.obtainSpiderQueen(mContext, info, SpiderQueen.MODE_DOWNLOAD);
        mCurrentTask = info;
        mCurrentSpider = spider;
        spider.addOnSpiderListener(this);
        info.state = DownloadInfo.STATE_DOWNLOAD;
        info.speed = -1;
        info.remaining = -1;
        info.total = -1;
        info.finished = 0;
        info.downloaded = 0;
        info.legacy = -1;
        // Update in DB
        EhDB.putDownloadInfo(info);
        // Start speed count
        mSpeedReminder.start();
        // Notify start downloading
        if (mDownloadListener != null) {
            mDownloadListener.onStart(info);
        }
        // Notify state update
        List<DownloadInfo> list = getInfoListForLabel(info.label);
        if (list != null) {
            for (DownloadInfoListener l : mDownloadInfoListeners) {
                l.onUpdate(info, list);
            }
        }
    }
}
Also used : DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo) SpiderQueen(com.hippo.ehviewer.spider.SpiderQueen)

Example 24 with DownloadInfo

use of com.hippo.ehviewer.dao.DownloadInfo in project EhViewer by seven332.

the class DownloadManager method stopRangeDownloadInternal.

// Update in DB
// Update mDownloadListener
private void stopRangeDownloadInternal(LongList gidList) {
    // Two way
    if (gidList.size() < mWaitList.size()) {
        for (int i = 0, n = gidList.size(); i < n; i++) {
            stopDownloadInternal(gidList.get(i));
        }
    } else {
        // Check current task
        if (mCurrentTask != null && gidList.contains(mCurrentTask.gid)) {
            // Stop current
            stopCurrentDownloadInternal();
        }
        // Check all in wait list
        for (Iterator<DownloadInfo> iterator = mWaitList.iterator(); iterator.hasNext(); ) {
            DownloadInfo info = iterator.next();
            if (gidList.contains(info.gid)) {
                // Remove from wait list
                iterator.remove();
                // Update state
                info.state = DownloadInfo.STATE_NONE;
                // Update in DB
                EhDB.putDownloadInfo(info);
            }
        }
    }
}
Also used : DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo)

Aggregations

DownloadInfo (com.hippo.ehviewer.dao.DownloadInfo)24 DownloadLabel (com.hippo.ehviewer.dao.DownloadLabel)4 SuppressLint (android.annotation.SuppressLint)2 Activity (android.app.Activity)2 Intent (android.content.Intent)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 Point (android.graphics.Point)2 EasyRecyclerView (com.hippo.easyrecyclerview.EasyRecyclerView)2 DownloadsDao (com.hippo.ehviewer.dao.DownloadsDao)2 HistoryInfo (com.hippo.ehviewer.dao.HistoryInfo)2 LocalFavoriteInfo (com.hippo.ehviewer.dao.LocalFavoriteInfo)2 QuickSearch (com.hippo.ehviewer.dao.QuickSearch)2 SpiderQueen (com.hippo.ehviewer.spider.SpiderQueen)2 GalleryActivity (com.hippo.ehviewer.ui.GalleryActivity)2 MainActivity (com.hippo.ehviewer.ui.MainActivity)2 IOException (java.io.IOException)2 Context (android.content.Context)1 Cursor (android.database.Cursor)1 SparseBooleanArray (android.util.SparseBooleanArray)1 CheckBoxDialogBuilder (com.hippo.app.CheckBoxDialogBuilder)1