use of com.hippo.ehviewer.dao.DownloadLabel in project EhViewer by seven332.
the class EhDB method moveDownloadLabel.
public static synchronized void moveDownloadLabel(int fromPosition, int toPosition) {
if (fromPosition == toPosition) {
return;
}
boolean reverse = fromPosition > toPosition;
int offset = reverse ? toPosition : fromPosition;
int limit = reverse ? fromPosition - toPosition + 1 : toPosition - fromPosition + 1;
DownloadLabelDao dao = sDaoSession.getDownloadLabelDao();
List<DownloadLabel> list = dao.queryBuilder().orderAsc(DownloadLabelDao.Properties.Time).offset(offset).limit(limit).list();
int step = reverse ? 1 : -1;
int start = reverse ? limit - 1 : 0;
int end = reverse ? 0 : limit - 1;
long toTime = list.get(end).getTime();
for (int i = end; reverse ? i < start : i > start; i += step) {
list.get(i).setTime(list.get(i + step).getTime());
}
list.get(start).setTime(toTime);
dao.updateInTx(list);
}
use of com.hippo.ehviewer.dao.DownloadLabel 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.DownloadLabel 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.DownloadLabel in project EhViewer by seven332.
the class CommonOperations method startDownload.
// TODO Add context if activity and context are different style
public static void startDownload(final MainActivity activity, final GalleryInfo galleryInfo, boolean forceDefault) {
final DownloadManager dm = EhApplication.getDownloadManager(activity);
boolean justStart = forceDefault || dm.containDownloadInfo(galleryInfo.gid);
String label = null;
// Get default download label
if (!justStart && Settings.getHasDefaultDownloadLabel()) {
label = Settings.getDefaultDownloadLabel();
justStart = label == null || dm.containLabel(label);
}
// If there is no other label, just use null label
if (!justStart && 0 == dm.getLabelList().size()) {
justStart = true;
label = null;
}
if (justStart) {
// Already in download list or get default label
Intent intent = new Intent(activity, DownloadService.class);
intent.setAction(DownloadService.ACTION_START);
intent.putExtra(DownloadService.KEY_LABEL, label);
intent.putExtra(DownloadService.KEY_GALLERY_INFO, galleryInfo);
activity.startService(intent);
// Notify
activity.showTip(R.string.added_to_download_list, BaseScene.LENGTH_SHORT);
} else {
// Let use chose label
List<DownloadLabel> list = dm.getLabelList();
final String[] items = new String[list.size() + 1];
items[0] = activity.getString(R.string.default_download_label_name);
for (int i = 0, n = list.size(); i < n; i++) {
items[i + 1] = list.get(i).getLabel();
}
new ListCheckBoxDialogBuilder(activity, items, new ListCheckBoxDialogBuilder.OnItemClickListener() {
@Override
public void onItemClick(ListCheckBoxDialogBuilder builder, AlertDialog dialog, int position) {
String label;
if (position == 0) {
label = null;
} else {
label = items[position];
if (!dm.containLabel(label)) {
label = null;
}
}
// Start download
Intent intent = new Intent(activity, DownloadService.class);
intent.setAction(DownloadService.ACTION_START);
intent.putExtra(DownloadService.KEY_LABEL, label);
intent.putExtra(DownloadService.KEY_GALLERY_INFO, galleryInfo);
activity.startService(intent);
// Save settings
if (builder.isChecked()) {
Settings.putHasDefaultDownloadLabel(true);
Settings.putDefaultDownloadLabel(label);
} else {
Settings.putHasDefaultDownloadLabel(false);
}
// Notify
activity.showTip(R.string.added_to_download_list, BaseScene.LENGTH_SHORT);
}
}, activity.getString(R.string.remember_download_label), false).setTitle(R.string.download).show();
}
}
Aggregations