Search in sources :

Example 6 with DownloadInfo

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

the class DownloadManager method stopDownloadInternal.

// Update in DB
// Update listener
// No ensureDownload
private DownloadInfo stopDownloadInternal(long gid) {
    // Check current task
    if (mCurrentTask != null && mCurrentTask.gid == gid) {
        // Stop current
        return stopCurrentDownloadInternal();
    }
    for (Iterator<DownloadInfo> iterator = mWaitList.iterator(); iterator.hasNext(); ) {
        DownloadInfo info = iterator.next();
        if (info.gid == gid) {
            // Remove from wait list
            iterator.remove();
            // Update state
            info.state = DownloadInfo.STATE_NONE;
            // Update in DB
            EhDB.putDownloadInfo(info);
            return info;
        }
    }
    return null;
}
Also used : DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo)

Example 7 with DownloadInfo

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

the class DownloadManager method addDownload.

public void addDownload(GalleryInfo galleryInfo, @Nullable String label) {
    if (containDownloadInfo(galleryInfo.gid)) {
        // Contain
        return;
    }
    // It is new download info
    DownloadInfo info = new DownloadInfo(galleryInfo);
    info.label = label;
    info.state = DownloadInfo.STATE_NONE;
    info.time = System.currentTimeMillis();
    // Add to label download list
    LinkedList<DownloadInfo> list = getInfoListForLabel(info.label);
    if (list == null) {
        Log.e(TAG, "Can't find download info list with label: " + label);
        return;
    }
    list.addFirst(info);
    // Add to all download list and map
    mAllInfoList.addFirst(info);
    mAllInfoMap.put(galleryInfo.gid, info);
    // Save to
    EhDB.putDownloadInfo(info);
    // Notify
    for (DownloadInfoListener l : mDownloadInfoListeners) {
        l.onAdd(info, list, list.size() - 1);
    }
}
Also used : DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo)

Example 8 with DownloadInfo

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

the class DownloadManager method startRangeDownload.

void startRangeDownload(LongList gidList) {
    boolean update = false;
    for (int i = 0, n = gidList.size(); i < n; i++) {
        long gid = gidList.get(i);
        DownloadInfo info = mAllInfoMap.get(gid);
        if (null == info) {
            Log.d(TAG, "Can't get download info with gid: " + gid);
            continue;
        }
        if (info.state == DownloadInfo.STATE_NONE || info.state == DownloadInfo.STATE_FAILED || info.state == DownloadInfo.STATE_FINISH) {
            update = true;
            // Set state DownloadInfo.STATE_WAIT
            info.state = DownloadInfo.STATE_WAIT;
            // Add to wait list
            mWaitList.add(info);
            // Update in DB
            EhDB.putDownloadInfo(info);
        }
    }
    if (update) {
        // Notify Listener
        for (DownloadInfoListener l : mDownloadInfoListeners) {
            l.onUpdateAll();
        }
        // Ensure download
        ensureDownload();
    }
}
Also used : DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo)

Example 9 with DownloadInfo

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

the class DownloadManager method stopCurrentDownloadInternal.

// Update in DB
// Update mDownloadListener
private DownloadInfo stopCurrentDownloadInternal() {
    DownloadInfo info = mCurrentTask;
    SpiderQueen spider = mCurrentSpider;
    // Release spider
    if (spider != null) {
        spider.removeOnSpiderListener(DownloadManager.this);
        SpiderQueen.releaseSpiderQueen(spider, SpiderQueen.MODE_DOWNLOAD);
    }
    mCurrentTask = null;
    mCurrentSpider = null;
    // Stop speed reminder
    mSpeedReminder.stop();
    if (info == null) {
        return null;
    }
    // Update state
    info.state = DownloadInfo.STATE_NONE;
    // Update in DB
    EhDB.putDownloadInfo(info);
    // Listener
    if (mDownloadListener != null) {
        mDownloadListener.onCancel(info);
    }
    return info;
}
Also used : DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo) SpiderQueen(com.hippo.ehviewer.spider.SpiderQueen)

Example 10 with DownloadInfo

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

the class DownloadManager method addDownload.

public void addDownload(List<DownloadInfo> downloadInfoList) {
    for (DownloadInfo info : downloadInfoList) {
        if (containDownloadInfo(info.gid)) {
            // Contain
            return;
        }
        // Ensure download state
        if (DownloadInfo.STATE_WAIT == info.state || DownloadInfo.STATE_DOWNLOAD == info.state) {
            info.state = DownloadInfo.STATE_NONE;
        }
        // Add to label download list
        LinkedList<DownloadInfo> list = getInfoListForLabel(info.label);
        if (null == list) {
            // Can't find the label in label list
            list = new LinkedList<>();
            mMap.put(info.label, list);
            if (!containLabel(info.label)) {
                // Add label to DB and list
                mLabelList.add(EhDB.addDownloadLabel(info.label));
            }
        }
        list.add(info);
        // Sort
        Collections.sort(list, DATE_DESC_COMPARATOR);
        // Add to all download list and map
        mAllInfoList.add(info);
        mAllInfoMap.put(info.gid, info);
        // Save to
        EhDB.putDownloadInfo(info);
    }
    // Sort all download list
    Collections.sort(mAllInfoList, DATE_DESC_COMPARATOR);
    // Notify
    for (DownloadInfoListener l : mDownloadInfoListeners) {
        l.onReload();
    }
}
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