/**
   * The action will take after another activity reply to this one
   *
   * @param requestCode -- the key to get result
   * @param resultCode -- result state
   * @param data -- intent to get data
   */
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.i(thisClass, "in FileChooser result");
    if (resultCode == RESULT_OK) {
      switch (requestCode) {
        case PICK_FILE_REQUEST_CODE:
          Uri fileUri = data.getData();

          //                    if (BuildConfig.DEBUG) {
          //                FileUtility.deleteAllFiles(currentSelectedDir());
          //                    }

          // create a file save the content under the related folder
          String path = UriUtility.getPath(this, fileUri);
          String name = FileUtility.getNameFromPath(path);
          FileEncryption file;
          File saveFile;
          try {
            saveFile = fileChooserBL.getEncryptedFilePath(currentSelectedDir(), name);
            file = new FileEncryption(saveFile, path, fileUri.toString(), password);
          } catch (IOException | NoSuchAlgorithmException e) {
            Log.e(thisClass, "File write failed: " + e.toString());
            return;
          }
          try {
            boolean succ = file.encrypt();
            if (!succ) {
              Toast.makeText(
                      getApplicationContext(), getString(R.string.encryptFail), Toast.LENGTH_SHORT)
                  .show();
              return;
            } else {
              Toast.makeText(
                      getApplicationContext(), getString(R.string.encryptSucc), Toast.LENGTH_SHORT)
                  .show();
            }
            if (!file.deleteOriginal()) {
              throw new EncryptionException("fail to delete original file");
            }
          } catch (IOException e) {
            Log.e(thisClass, "File encrypt failed: " + e.toString());
          } catch (NoSuchAlgorithmException | UnrecoverableEntryException | InvalidKeyException e) {
            Log.e(thisClass, " failed: " + e.toString());
          }
          // update the view as if it is clicked
          folderFragmentClick(fatherIndex);
          break;
      }
    } else {
      Log.e(thisClass, " fail to start activity " + data);
    }
  }
  @Override
  public void detailFragmentClick(int position) {
    Log.d(thisClass, position + " is choose");

    ArrayList<UIFileInfo> children = UIFileInfo.addFileFrom(currentSelectedDir());
    if (children != null) {
      if (position >= children.size()) {
        throw new RuntimeException("position < childrenCache.get(fatherIndex).size()");
      }
    } else {
      throw new RuntimeException("");
    }
    UIFileInfo UIFileInfo = children.get(position);
    if (UIFileInfo.isDir()) {
      folderFragment.clearListView();
      folderFragment.addListView(children).notifyDataSetChanged();

      updateDetailFileInfo(UIFileInfo.toFile());
    } else {
      // decrypt file and show it
      FileEncryption fileEncryption;
      try {
        fileEncryption = new FileEncryption(UIFileInfo.toFile(), password);
      } catch (IOException e) {
        Log.e(thisClass, "can't read file" + e);
        return;
      }
      DecryptedFile decryptedFile;
      try {
        if (fileEncryption.largeLinkedSize()) {
          decryptedFile = fileEncryption.decryptPart();
        } else {
          fileEncryption.decryptAll(true);
        }
      } catch (InvalidAlgorithmParameterException
          | InvalidKeyException
          | NoSuchAlgorithmException
          | IOException
          | UnrecoverableEntryException e) {
        Log.e(thisClass, " failed: " + e.toString());
      }

      // add file path of to be deleted file
      delPaths.add(fileEncryption.getEncryptedFilePath());

      // start app to view different file
      //            Intent intent = getMyImgIntent(this, fileEncryption);
      Intent intent = new Intent(Intent.ACTION_VIEW);
      intent.setDataAndType(
          Uri.parse(fileEncryption.getFileUri()),
          FileUtility.getMimeType(fileEncryption.getLinkedFilePath()));

      if (IntentUtil.intentSafe(intent, this)) {
        startActivity(intent);
      }
    }
  }