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;
}
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);
}
}
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();
}
}
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;
}
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();
}
}
Aggregations