Search in sources :

Example 11 with DownloadInfo

use of com.hippo.ehviewer.dao.DownloadInfo in project EhViewer by seven332.

the class DownloadManager method startAllDownload.

void startAllDownload() {
    boolean update = false;
    // Start all STATE_NONE and STATE_FAILED item
    LinkedList<DownloadInfo> allInfoList = mAllInfoList;
    LinkedList<DownloadInfo> waitList = mWaitList;
    for (DownloadInfo info : allInfoList) {
        if (info.state == DownloadInfo.STATE_NONE || info.state == DownloadInfo.STATE_FAILED) {
            update = true;
            // Set state DownloadInfo.STATE_WAIT
            info.state = DownloadInfo.STATE_WAIT;
            // Add to wait list
            waitList.add(info);
            // Update in DB
            EhDB.putDownloadInfo(info);
        }
    }
    if (update) {
        // Notify Listener
        for (DownloadInfoListener l : mDownloadInfoListeners) {
            l.onUpdateAll();
        }
        // Ensure download
        ensureDownload();
    }
}
Also used : DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo)

Example 12 with DownloadInfo

use of com.hippo.ehviewer.dao.DownloadInfo in project EhViewer by seven332.

the class DownloadsScene method onClickSecondaryFab.

@Override
public void onClickSecondaryFab(FabLayout view, FloatingActionButton fab, int position) {
    Context context = getContext2();
    Activity activity = getActivity2();
    EasyRecyclerView recyclerView = mRecyclerView;
    if (null == context || null == activity || null == recyclerView) {
        return;
    }
    if (0 == position) {
        recyclerView.checkAll();
    } else {
        List<DownloadInfo> list = mList;
        if (list == null) {
            return;
        }
        LongList gidList = null;
        List<DownloadInfo> downloadInfoList = null;
        // Start, Stop, Delete
        boolean collectGid = position == 1 || position == 2 || position == 3;
        // Delete or Move
        boolean collectDownloadInfo = position == 3 || position == 4;
        if (collectGid) {
            gidList = new LongList();
        }
        if (collectDownloadInfo) {
            downloadInfoList = new LinkedList<>();
        }
        SparseBooleanArray stateArray = recyclerView.getCheckedItemPositions();
        for (int i = 0, n = stateArray.size(); i < n; i++) {
            if (stateArray.valueAt(i)) {
                DownloadInfo info = list.get(stateArray.keyAt(i));
                if (collectDownloadInfo) {
                    downloadInfoList.add(info);
                }
                if (collectGid) {
                    gidList.add(info.gid);
                }
            }
        }
        switch(position) {
            case 1:
                {
                    // Start
                    Intent intent = new Intent(activity, DownloadService.class);
                    intent.setAction(DownloadService.ACTION_START_RANGE);
                    intent.putExtra(DownloadService.KEY_GID_LIST, gidList);
                    activity.startService(intent);
                    // Cancel check mode
                    recyclerView.outOfCustomChoiceMode();
                    break;
                }
            case 2:
                {
                    // Stop
                    if (null != mDownloadManager) {
                        mDownloadManager.stopRangeDownload(gidList);
                    }
                    // Cancel check mode
                    recyclerView.outOfCustomChoiceMode();
                    break;
                }
            case 3:
                {
                    // Delete
                    CheckBoxDialogBuilder builder = new CheckBoxDialogBuilder(context, getString(R.string.download_remove_dialog_message_2, gidList.size()), getString(R.string.download_remove_dialog_check_text), Settings.getRemoveImageFiles());
                    DeleteRangeDialogHelper helper = new DeleteRangeDialogHelper(downloadInfoList, gidList, builder);
                    builder.setTitle(R.string.download_remove_dialog_title).setPositiveButton(android.R.string.ok, helper).show();
                    break;
                }
            case 4:
                {
                    // Move
                    List<DownloadLabel> labelRawList = EhApplication.getDownloadManager(context).getLabelList();
                    List<String> labelList = new ArrayList<>(labelRawList.size() + 1);
                    labelList.add(getString(R.string.default_download_label_name));
                    for (int i = 0, n = labelRawList.size(); i < n; i++) {
                        labelList.add(labelRawList.get(i).getLabel());
                    }
                    String[] labels = labelList.toArray(new String[labelList.size()]);
                    MoveDialogHelper helper = new MoveDialogHelper(labels, downloadInfoList);
                    new AlertDialog.Builder(context).setTitle(R.string.download_move_dialog_title).setItems(labels, helper).show();
                    break;
                }
        }
    }
}
Also used : Context(android.content.Context) EasyRecyclerView(com.hippo.easyrecyclerview.EasyRecyclerView) CheckBoxDialogBuilder(com.hippo.app.CheckBoxDialogBuilder) GalleryActivity(com.hippo.ehviewer.ui.GalleryActivity) MainActivity(com.hippo.ehviewer.ui.MainActivity) Activity(android.app.Activity) Intent(android.content.Intent) LongList(com.hippo.yorozuya.collect.LongList) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) DownloadService(com.hippo.ehviewer.download.DownloadService) DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo) SparseBooleanArray(android.util.SparseBooleanArray) List(java.util.List) LongList(com.hippo.yorozuya.collect.LongList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) CheckBoxDialogBuilder(com.hippo.app.CheckBoxDialogBuilder)

Example 13 with DownloadInfo

use of com.hippo.ehviewer.dao.DownloadInfo in project EhViewer by seven332.

the class DownloadsScene method handleArguments.

private boolean handleArguments(Bundle args) {
    if (null == args) {
        return false;
    }
    if (ACTION_CLEAR_DOWNLOAD_SERVICE.equals(args.getString(KEY_ACTION))) {
        DownloadService.clear();
    }
    long gid;
    if (null != mDownloadManager && -1L != (gid = args.getLong(KEY_GID, -1L))) {
        DownloadInfo info = mDownloadManager.getDownloadInfo(gid);
        if (null != info) {
            mLabel = info.getLabel();
            updateForLabel();
            updateView();
            // Get position
            if (null != mList) {
                int position = mList.indexOf(info);
                if (position >= 0 && null != mRecyclerView) {
                    mRecyclerView.scrollToPosition(position);
                } else {
                    mInitPosition = position;
                }
            }
            return true;
        }
    }
    return false;
}
Also used : DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 14 with DownloadInfo

use of com.hippo.ehviewer.dao.DownloadInfo in project EhViewer by seven332.

the class DownloadsScene method onItemClick.

@Override
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
    Activity activity = getActivity2();
    EasyRecyclerView recyclerView = mRecyclerView;
    if (null == activity || null == recyclerView) {
        return false;
    }
    if (recyclerView.isInCustomChoice()) {
        recyclerView.toggleItemChecked(position);
        return true;
    } else {
        List<DownloadInfo> list = mList;
        if (list == null) {
            return false;
        }
        if (position < 0 && position >= list.size()) {
            return false;
        }
        Intent intent = new Intent(activity, GalleryActivity.class);
        intent.setAction(GalleryActivity.ACTION_EH);
        intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, list.get(position));
        startActivity(intent);
        return true;
    }
}
Also used : EasyRecyclerView(com.hippo.easyrecyclerview.EasyRecyclerView) DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo) GalleryActivity(com.hippo.ehviewer.ui.GalleryActivity) MainActivity(com.hippo.ehviewer.ui.MainActivity) Activity(android.app.Activity) Intent(android.content.Intent)

Example 15 with DownloadInfo

use of com.hippo.ehviewer.dao.DownloadInfo in project EhViewer by seven332.

the class EhDB method getAllDownloadInfo.

public static synchronized List<DownloadInfo> getAllDownloadInfo() {
    DownloadsDao dao = sDaoSession.getDownloadsDao();
    List<DownloadInfo> list = dao.queryBuilder().orderDesc(DownloadsDao.Properties.Time).list();
    // Fix state
    for (DownloadInfo info : list) {
        if (info.state == DownloadInfo.STATE_WAIT || info.state == DownloadInfo.STATE_DOWNLOAD) {
            info.state = DownloadInfo.STATE_NONE;
        }
    }
    return list;
}
Also used : DownloadsDao(com.hippo.ehviewer.dao.DownloadsDao) DownloadInfo(com.hippo.ehviewer.dao.DownloadInfo)

Aggregations

DownloadInfo (com.hippo.ehviewer.dao.DownloadInfo)24 DownloadLabel (com.hippo.ehviewer.dao.DownloadLabel)4 SuppressLint (android.annotation.SuppressLint)2 Activity (android.app.Activity)2 Intent (android.content.Intent)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 Point (android.graphics.Point)2 EasyRecyclerView (com.hippo.easyrecyclerview.EasyRecyclerView)2 DownloadsDao (com.hippo.ehviewer.dao.DownloadsDao)2 HistoryInfo (com.hippo.ehviewer.dao.HistoryInfo)2 LocalFavoriteInfo (com.hippo.ehviewer.dao.LocalFavoriteInfo)2 QuickSearch (com.hippo.ehviewer.dao.QuickSearch)2 SpiderQueen (com.hippo.ehviewer.spider.SpiderQueen)2 GalleryActivity (com.hippo.ehviewer.ui.GalleryActivity)2 MainActivity (com.hippo.ehviewer.ui.MainActivity)2 IOException (java.io.IOException)2 Context (android.content.Context)1 Cursor (android.database.Cursor)1 SparseBooleanArray (android.util.SparseBooleanArray)1 CheckBoxDialogBuilder (com.hippo.app.CheckBoxDialogBuilder)1