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