Search in sources :

Example 6 with DownloadLabel

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);
}
Also used : DownloadLabelDao(com.hippo.ehviewer.dao.DownloadLabelDao) DownloadLabel(com.hippo.ehviewer.dao.DownloadLabel)

Example 7 with DownloadLabel

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();
    }
}
Also used : DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo) DownloadLabel(com.hippo.ehviewer.dao.DownloadLabel)

Example 8 with DownloadLabel

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));
        }
    }
}
Also used : DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo) DownloadLabel(com.hippo.ehviewer.dao.DownloadLabel)

Example 9 with DownloadLabel

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();
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Intent(android.content.Intent) DownloadManager(com.hippo.ehviewer.download.DownloadManager) DownloadService(com.hippo.ehviewer.download.DownloadService) ListCheckBoxDialogBuilder(com.hippo.app.ListCheckBoxDialogBuilder) DownloadLabel(com.hippo.ehviewer.dao.DownloadLabel)

Aggregations

DownloadLabel (com.hippo.ehviewer.dao.DownloadLabel)9 DownloadInfo (com.hippo.ehviewer.dao.DownloadInfo)4 DownloadManager (com.hippo.ehviewer.download.DownloadManager)3 DownloadLabelDao (com.hippo.ehviewer.dao.DownloadLabelDao)2 SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 Point (android.graphics.Point)1 AlertDialog (android.support.v7.app.AlertDialog)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 ShowcaseView (com.github.amlcurran.showcaseview.ShowcaseView)1 CheckBoxDialogBuilder (com.hippo.app.CheckBoxDialogBuilder)1