@Override
 public void openItem(int position) {
   if (position == 0) {
     Uri uri_to_go = null;
     if (parentLink == SLS) uri_to_go = Uri.parse(HomeAdapter.DEFAULT_LOC);
     else {
       // 0000-0000:folder%2Fsubfolder
       uri_to_go = getParent(uri);
       if (uri_to_go == null) uri_to_go = Uri.parse(HomeAdapter.DEFAULT_LOC);
     }
     String pos_to = null;
     String cur_path = getPath(uri, true);
     if (cur_path != null) pos_to = cur_path.substring(cur_path.lastIndexOf('/'));
     commander.Navigate(uri_to_go, null, pos_to);
   } else {
     Item item = items[position - 1];
     if (item.dir) commander.Navigate((Uri) item.origin, null, null);
     else {
       Uri to_open;
       String full_name = getItemName(position, true);
       if (full_name != null && full_name.charAt(0) == '/')
         to_open = Uri.parse(Utils.escapePath(full_name));
       else to_open = (Uri) item.origin;
       commander.Open(to_open, null);
     }
   }
 }
  @Override
  public void onClick(DialogInterface idialog, int whichButton) {
    if (whichButton == DialogInterface.BUTTON_POSITIVE) {
      try {
        f.setComment(ce.getText().toString());
        String path = pe.getText().toString().trim();
        if (se != null) {
          Uri.Builder uri_b = uri.buildUpon();
          if (ftp) {
            uri_b.encodedQuery("");
            Object esio = en.getSelectedItem();
            if (esio instanceof String) {
              String enc_s = (String) esio;
              if (Utils.str(enc_s) && !"Default".equals(enc_s)) {
                enc_s = enc_s.substring(0, enc_s.indexOf("\n"));
                uri_b.appendQueryParameter("e", enc_s);
              }
            }
            if (active_ftp_cb.isChecked()) uri_b.appendQueryParameter("a", "true");
          }
          String serv = se.getText().toString().trim();
          f.setUri(
              uri_b
                  .encodedAuthority(Utils.encodeToAuthority(serv))
                  .encodedPath(Utils.escapePath(path))
                  .build());
          Log.i(TAG, "Uri:" + f.getUri());
          String domain = de != null ? de.getText().toString().trim() : "";
          String usernm = ue.getText().toString().trim();
          f.setCredentials(
              domain.length() > 0 ? domain + ";" + usernm : usernm, we.getText().toString().trim());
        } else {
          f.setUri(uri.buildUpon().encodedPath(Utils.escapePath(path)).build());
        }

        owner.invalidate();
      } catch (Exception e) {
        Log.e(TAG, null, e);
      }
    }
  }
    private final int copyFiles(File[] list, Uri dest) throws InterruptedException {
      File file = null;
      for (int i = 0; i < list.length; i++) {
        InputStream is = null;
        OutputStream os = null;
        file = list[i];
        if (file == null) {
          error(ctx.getString(R.string.unkn_err));
          break;
        }
        Uri dest_uri = null;
        try {
          if (isStopReq()) {
            error(ctx.getString(R.string.canceled));
            break;
          }
          String fn = file.getName();
          String to_append = "%2f" + Utils.escapePath(fn);
          dest_uri = dest.buildUpon().encodedPath(dest.getEncodedPath() + to_append).build();
          String mime = getMime(dest_uri);
          if (file.isDirectory()) {
            if (depth++ > 40) {
              error(ctx.getString(R.string.too_deep_hierarchy));
              break;
            }
            if (mime != null) {
              if (!Document.MIME_TYPE_DIR.equals(mime)) {
                error(ctx.getString(R.string.cant_md));
                break;
              }
            } else {
              DocumentsContract.createDocument(cr, dest, Document.MIME_TYPE_DIR, fn);
            }
            copyFiles(file.listFiles(), dest_uri);
            if (errMsg != null) break;
            depth--;
            counter++;
          } else {
            if (mime != null) {
              int res = askOnFileExist(ctx.getString(R.string.file_exist, fn), commander);
              if (res == Commander.SKIP) continue;
              if (res == Commander.ABORT) break;
              if (res == Commander.REPLACE) {
                File dest_file = new File(getPath(dest_uri, false));
                if (dest_file.equals(file)) {
                  Log.w(TAG, "Not going to copy file to itself");
                  continue;
                }
                Log.v(TAG, "Overwritting file " + fn);
                DocumentsContract.deleteDocument(cr, dest_uri);
              }
            } else mime = Utils.getMimeByExt(Utils.getFileExt(fn));
            dest_uri = DocumentsContract.createDocument(cr, dest, mime, fn);
            if (dest_uri == null) {
              error(ctx.getString(R.string.cant_create, fn, ""));
              break;
            }
            String dest_path = dest_uri.getPath();
            if (dest_path.indexOf(fn, dest_path.length() - fn.length() - 1) < 0) // SAF suxx
            dest_uri = DocumentsContract.renameDocument(cr, dest_uri, fn);

            is = new FileInputStream(file);
            os = cr.openOutputStream(dest_uri);
            long copied = 0, size = file.length();

            long start_time = 0;
            int speed = 0;
            int so_far = (int) (totalBytes * conv);

            String sz_s = Utils.getHumanSize(size);
            int fnl = fn.length();
            String rep_s =
                ctx.getString(
                    R.string.copying, fnl > CUT_LEN ? "\u2026" + fn.substring(fnl - CUT_LEN) : fn);
            int n = 0;
            long nn = 0;

            while (true) {
              if (nn == 0) {
                start_time = System.currentTimeMillis();
                sendProgress(
                    rep_s + sizeOfsize(copied, sz_s), so_far, (int) (totalBytes * conv), speed);
              }
              n = is.read(buf);
              if (n < 0) {
                long time_delta = System.currentTimeMillis() - start_time;
                if (time_delta > 0) {
                  speed = (int) (MILLI * nn / time_delta);
                  sendProgress(
                      rep_s + sizeOfsize(copied, sz_s), so_far, (int) (totalBytes * conv), speed);
                }
                break;
              }
              os.write(buf, 0, n);
              nn += n;
              copied += n;
              totalBytes += n;
              if (isStopReq()) {
                Log.d(TAG, "Interrupted!");
                error(ctx.getString(R.string.canceled));
                return counter;
              }
              long time_delta = System.currentTimeMillis() - start_time;
              if (time_delta > DELAY) {
                speed = (int) (MILLI * nn / time_delta);
                // Log.v( TAG, "bytes: " + nn + " time: " + time_delta + " speed: " + speed );
                nn = 0;
              }
            }
            is.close();
            os.close();
            is = null;
            os = null;
            /*
            ContentValues cv = new ContentValues();
            cv.put( Document.COLUMN_LAST_MODIFIED, file.lastModified() );
            cr.update( dest_uri, cv, null, null ); //throws..
            */
            if (i >= list.length - 1)
              sendProgress(
                  ctx.getString(R.string.copied_f, fn) + sizeOfsize(copied, sz_s),
                  (int) (totalBytes * conv));
            counter++;
          }
          if (move) {
            if (!file.delete()) {
              sendProgress(ctx.getString(R.string.cant_del, fn), -1);
              delerr_counter++;
            }
          }
        } catch (Exception e) {
          Log.e(TAG, "", e);
          error(ctx.getString(R.string.rtexcept, file.getAbsolutePath(), e.getMessage()));
        } finally {
          try {
            if (is != null) is.close();
            if (os != null) os.close();
          } catch (IOException e) {
            error(ctx.getString(R.string.acc_err, file.getAbsolutePath(), e.getMessage()));
          }
        }
      }
      return counter;
    }