Search in sources :

Example 1 with LongList

use of com.hippo.yorozuya.collect.LongList 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 2 with LongList

use of com.hippo.yorozuya.collect.LongList in project EhViewer by seven332.

the class DownloadService method handleIntent.

private void handleIntent(Intent intent) {
    String action = null;
    if (intent != null) {
        action = intent.getAction();
    }
    if (ACTION_START.equals(action)) {
        GalleryInfo gi = intent.getParcelableExtra(KEY_GALLERY_INFO);
        String label = intent.getStringExtra(KEY_LABEL);
        if (gi != null && mDownloadManager != null) {
            mDownloadManager.startDownload(gi, label);
        }
    } else if (ACTION_START_RANGE.equals(action)) {
        LongList gidList = intent.getParcelableExtra(KEY_GID_LIST);
        if (gidList != null && mDownloadManager != null) {
            mDownloadManager.startRangeDownload(gidList);
        }
    } else if (ACTION_START_ALL.equals(action)) {
        if (mDownloadManager != null) {
            mDownloadManager.startAllDownload();
        }
    } else if (ACTION_STOP.equals(action)) {
        long gid = intent.getLongExtra(KEY_GID, -1);
        if (gid != -1 && mDownloadManager != null) {
            mDownloadManager.stopDownload(gid);
        }
    } else if (ACTION_STOP_CURRENT.equals(action)) {
        if (mDownloadManager != null) {
            mDownloadManager.stopCurrentDownload();
        }
    } else if (ACTION_STOP_RANGE.equals(action)) {
        LongList gidList = intent.getParcelableExtra(KEY_GID_LIST);
        if (gidList != null && mDownloadManager != null) {
            mDownloadManager.stopRangeDownload(gidList);
        }
    } else if (ACTION_STOP_ALL.equals(action)) {
        if (mDownloadManager != null) {
            mDownloadManager.stopAllDownload();
        }
    } else if (ACTION_DELETE.equals(action)) {
        long gid = intent.getLongExtra(KEY_GID, -1);
        if (gid != -1 && mDownloadManager != null) {
            mDownloadManager.deleteDownload(gid);
        }
    } else if (ACTION_DELETE_RANGE.equals(action)) {
        LongList gidList = intent.getParcelableExtra(KEY_GID_LIST);
        if (gidList != null && mDownloadManager != null) {
            mDownloadManager.deleteRangeDownload(gidList);
        }
    } else if (ACTION_CLEAR.equals(action)) {
        clear();
    }
    checkStopSelf();
}
Also used : GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo) LongList(com.hippo.yorozuya.collect.LongList)

Aggregations

LongList (com.hippo.yorozuya.collect.LongList)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Point (android.graphics.Point)1 SparseBooleanArray (android.util.SparseBooleanArray)1 CheckBoxDialogBuilder (com.hippo.app.CheckBoxDialogBuilder)1 EasyRecyclerView (com.hippo.easyrecyclerview.EasyRecyclerView)1 GalleryInfo (com.hippo.ehviewer.client.data.GalleryInfo)1 DownloadInfo (com.hippo.ehviewer.dao.DownloadInfo)1 DownloadService (com.hippo.ehviewer.download.DownloadService)1 GalleryActivity (com.hippo.ehviewer.ui.GalleryActivity)1 MainActivity (com.hippo.ehviewer.ui.MainActivity)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1