Search in sources :

Example 16 with DownloadInfo

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

the class DownloadManager method deleteLabel.

public void deleteLabel(@NonNull String label) {
    // Find in label list and remove
    boolean found = false;
    for (Iterator<DownloadLabel> iterator = mLabelList.iterator(); iterator.hasNext(); ) {
        DownloadLabel raw = iterator.next();
        if (label.equals(raw.getLabel())) {
            found = true;
            iterator.remove();
            EhDB.removeDownloadLabel(raw);
            break;
        }
    }
    if (!found) {
        return;
    }
    LinkedList<DownloadInfo> list = mMap.remove(label);
    if (list == null) {
        return;
    }
    // Update info label
    for (DownloadInfo info : list) {
        info.label = null;
        // Update in DB
        EhDB.putDownloadInfo(info);
        mDefaultInfoList.add(info);
    }
    // Sort
    Collections.sort(mDefaultInfoList, DATE_DESC_COMPARATOR);
    // Notify listener
    for (DownloadInfoListener l : mDownloadInfoListeners) {
        l.onChange();
    }
}
Also used : DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo) DownloadLabel(com.hippo.ehviewer.dao.DownloadLabel)

Example 17 with DownloadInfo

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

the class DownloadManager method deleteDownload.

public void deleteDownload(long gid) {
    stopDownloadInternal(gid);
    DownloadInfo info = mAllInfoMap.get(gid);
    if (info != null) {
        // Remove from DB
        EhDB.removeDownloadInfo(info.gid);
        // Remove all list and map
        mAllInfoList.remove(info);
        mAllInfoMap.remove(info.gid);
        // Remove label list
        LinkedList<DownloadInfo> list = getInfoListForLabel(info.label);
        if (list != null) {
            int index = list.indexOf(info);
            if (index >= 0) {
                list.remove(info);
                // Update listener
                for (DownloadInfoListener l : mDownloadInfoListeners) {
                    l.onRemove(info, list, index);
                }
            }
        }
        // Ensure download
        ensureDownload();
    }
}
Also used : DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo)

Example 18 with DownloadInfo

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

the class DownloadManager method startDownload.

void startDownload(GalleryInfo galleryInfo, @Nullable String label) {
    if (mCurrentTask != null && mCurrentTask.gid == galleryInfo.gid) {
        // It is current task
        return;
    }
    // Check in download list
    DownloadInfo info = mAllInfoMap.get(galleryInfo.gid);
    if (info != null) {
        // Get it in download list
        if (info.state != DownloadInfo.STATE_WAIT) {
            // Set state DownloadInfo.STATE_WAIT
            info.state = DownloadInfo.STATE_WAIT;
            // Add to wait list
            mWaitList.add(info);
            // Update in DB
            EhDB.putDownloadInfo(info);
            // Notify state update
            List<DownloadInfo> list = getInfoListForLabel(info.label);
            if (list != null) {
                for (DownloadInfoListener l : mDownloadInfoListeners) {
                    l.onUpdate(info, list);
                }
            }
            // Make sure download is running
            ensureDownload();
        }
    } else {
        // It is new download info
        info = new DownloadInfo(galleryInfo);
        info.label = label;
        info.state = DownloadInfo.STATE_WAIT;
        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);
        // Add to wait list
        mWaitList.add(info);
        // Save to
        EhDB.putDownloadInfo(info);
        // Notify
        for (DownloadInfoListener l : mDownloadInfoListeners) {
            l.onAdd(info, list, list.size() - 1);
        }
        // Make sure download is running
        ensureDownload();
    }
}
Also used : DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo)

Example 19 with DownloadInfo

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

the class DownloadManager method addDownloadLabel.

public void addDownloadLabel(List<DownloadLabel> downloadLabelList) {
    for (DownloadLabel label : downloadLabelList) {
        String labelString = label.getLabel();
        if (!containLabel(labelString)) {
            mMap.put(labelString, new LinkedList<DownloadInfo>());
            mLabelList.add(EhDB.addDownloadLabel(label));
        }
    }
}
Also used : DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo) DownloadLabel(com.hippo.ehviewer.dao.DownloadLabel)

Example 20 with DownloadInfo

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

the class DownloadManager method deleteRangeDownload.

public void deleteRangeDownload(LongList gidList) {
    stopRangeDownloadInternal(gidList);
    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;
        }
        // Remove from DB
        EhDB.removeDownloadInfo(info.gid);
        // Remove from all info map
        mAllInfoList.remove(info);
        mAllInfoMap.remove(info.gid);
        // Remove from label list
        LinkedList<DownloadInfo> list = getInfoListForLabel(info.label);
        if (list != null) {
            list.remove(info);
        }
    }
    // Update listener
    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