Ejemplo n.º 1
0
  @Override
  public void onItemClick(AdapterView<?> aListView, View aView, int aPosition, long aID) {
    final FileWrapper item = adapter.getItem(aPosition);

    if (item.parentItem && backStack.get(backStack.size() - 1).parentIsBack) {
      backStack.remove(backStack.size() - 1);
      wrapFiles();
      return;
    } else if (item.dirSelectItem) {
      finishWithPath(listedDirectory.getAbsolutePath());
      return;
    }

    final File selected = item.parentItem ? listedDirectory.getParentFile() : item.file;

    if (selected.isDirectory()) {
      backStack.add(new BackStackItem(selected.getAbsolutePath(), !item.parentItem));
      wrapFiles();
    } else {
      String filePath = selected.getAbsolutePath();
      finishWithPath(filePath);
    }
  }
Ejemplo n.º 2
0
  private void wrapFiles() {
    listedDirectory = new File(backStack.get(backStack.size() - 1).path);

    if (!listedDirectory.isDirectory()) {
      throw new IllegalArgumentException("Directory is not valid.");
    }

    adapter.clear();
    setTitle(listedDirectory.getAbsolutePath());

    if (isDirectoryTarget) adapter.add(new FileWrapper(null, FileWrapper.DIRSELECT, true));

    if (listedDirectory.getParentFile() != null)
      adapter.add(new FileWrapper(null, FileWrapper.PARENT, true));

    // Copy new items
    final File[] files = listedDirectory.listFiles();
    if (files != null) {
      for (File file : files) {
        String path = file.getName();

        boolean allowFile = file.isDirectory() || (filterPath(path) && !isDirectoryTarget);

        if (allowFile)
          adapter.add(new FileWrapper(file, FileWrapper.FILE, file.isDirectory() || true));
      }
    }

    // Sort items
    adapter.sort(
        new Comparator<FileWrapper>() {
          @Override
          public int compare(FileWrapper aLeft, FileWrapper aRight) {
            return aLeft.compareTo(aRight);
          };
        });

    // Update
    adapter.notifyDataSetChanged();
  }