Search in sources :

Example 1 with CheckBoxDialogBuilder

use of com.hippo.app.CheckBoxDialogBuilder 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 CheckBoxDialogBuilder

use of com.hippo.app.CheckBoxDialogBuilder in project EhViewer by seven332.

the class GalleryListScene method showQuickSearchTipDialog.

private void showQuickSearchTipDialog(final List<QuickSearch> list, final ArrayAdapter<QuickSearch> adapter, final ListView listView, final TextView tip) {
    Context context = getContext2();
    if (null == context) {
        return;
    }
    final CheckBoxDialogBuilder builder = new CheckBoxDialogBuilder(context, getString(R.string.add_quick_search_tip), getString(R.string.get_it), false);
    builder.setTitle(R.string.readme);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (builder.isChecked()) {
                Settings.putQuickSearchTip(false);
            }
            showAddQuickSearchDialog(list, adapter, listView, tip);
        }
    }).show();
}
Also used : Context(android.content.Context) DialogInterface(android.content.DialogInterface) CheckBoxDialogBuilder(com.hippo.app.CheckBoxDialogBuilder)

Aggregations

Context (android.content.Context)2 CheckBoxDialogBuilder (com.hippo.app.CheckBoxDialogBuilder)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 Point (android.graphics.Point)1 SparseBooleanArray (android.util.SparseBooleanArray)1 EasyRecyclerView (com.hippo.easyrecyclerview.EasyRecyclerView)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 LongList (com.hippo.yorozuya.collect.LongList)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1