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