Search in sources :

Example 1 with PathAdapter

use of com.foobnix.pdf.info.presentation.PathAdapter in project LibreraReader by foobnix.

the class PrefDialogs method chooseFolderDialog.

public static void chooseFolderDialog(final FragmentActivity a, final Runnable onChanges, final Runnable onScan) {
    final PathAdapter recentAdapter = new PathAdapter();
    recentAdapter.setPaths(AppState.get().searchPaths);
    final AlertDialog.Builder builder = new AlertDialog.Builder(a);
    builder.setTitle(R.string.scan_device_for_new_books);
    final ListView list = new ListView(a);
    list.setAdapter(recentAdapter);
    builder.setView(list);
    builder.setPositiveButton(R.string.search, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
            onScan.run();
        }
    });
    builder.setNeutralButton(R.string.add, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
            ChooserDialogFragment.chooseFolder(a, AppState.get().dirLastPath).setOnSelectListener(new ResultResponse2<String, Dialog>() {

                @Override
                public boolean onResultRecive(String nPath, Dialog dialog) {
                    boolean isExists = false;
                    String existPath = "";
                    for (String str : AppState.get().searchPaths.split(",")) {
                        if (str != null && str.trim().length() != 0 && nPath.equals(str)) {
                            isExists = true;
                            existPath = str;
                            break;
                        }
                    }
                    if (ExtUtils.isExteralSD(nPath)) {
                        Toast.makeText(a, R.string.incorrect_value, Toast.LENGTH_SHORT).show();
                    } else if (isExists) {
                        Toast.makeText(a, String.format("[ %s == %s ] %s", nPath, existPath, a.getString(R.string.this_directory_is_already_in_the_list)), Toast.LENGTH_LONG).show();
                    } else {
                        if (AppState.get().searchPaths.endsWith(",")) {
                            AppState.get().searchPaths = AppState.get().searchPaths + "" + nPath;
                        } else {
                            AppState.get().searchPaths = AppState.get().searchPaths + "," + nPath;
                        }
                    }
                    dialog.dismiss();
                    onChanges.run();
                    chooseFolderDialog(a, onChanges, onScan);
                    return false;
                }
            });
        }
    });
    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
        }
    });
    recentAdapter.setOnDeleClick(new ResultResponse<Uri>() {

        @Override
        public boolean onResultRecive(Uri result) {
            String path = result.getPath();
            LOG.d("TEST", "Remove " + AppState.get().searchPaths);
            LOG.d("TEST", "Remove " + path);
            StringBuilder builder = new StringBuilder();
            for (String str : AppState.get().searchPaths.split(",")) {
                if (str != null && str.trim().length() > 0 && !str.equals(path)) {
                    builder.append(str);
                    builder.append(",");
                }
            }
            AppState.get().searchPaths = builder.toString();
            LOG.d("TEST", "Remove " + AppState.get().searchPaths);
            recentAdapter.setPaths(AppState.get().searchPaths);
            onChanges.run();
            return false;
        }
    });
    AlertDialog create = builder.create();
    create.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            Keyboards.hideNavigation(a);
        }
    });
    create.show();
}
Also used : AlertDialog(android.app.AlertDialog) ResultResponse2(com.foobnix.android.utils.ResultResponse2) DialogInterface(android.content.DialogInterface) PathAdapter(com.foobnix.pdf.info.presentation.PathAdapter) OnDismissListener(android.content.DialogInterface.OnDismissListener) Uri(android.net.Uri) ListView(android.widget.ListView) Dialog(android.app.Dialog) AlertDialog(android.app.AlertDialog)

Aggregations

AlertDialog (android.app.AlertDialog)1 Dialog (android.app.Dialog)1 DialogInterface (android.content.DialogInterface)1 OnDismissListener (android.content.DialogInterface.OnDismissListener)1 Uri (android.net.Uri)1 ListView (android.widget.ListView)1 ResultResponse2 (com.foobnix.android.utils.ResultResponse2)1 PathAdapter (com.foobnix.pdf.info.presentation.PathAdapter)1