Example #1
0
  public void setActiveOrAdd(@NonNull Crumb crumb, boolean forceRecreate) {
    if (forceRecreate || !setActive(crumb)) {
      clearCrumbs();
      final List<File> newPathSet = new ArrayList<>();

      newPathSet.add(0, crumb.getFile());

      File p = crumb.getFile();
      if (!isStorageOrSd(p)) {
        while ((p = p.getParent()) != null) {
          newPathSet.add(0, p);
          if (isStorageOrSd(p)) break;
        }
      }

      for (int index = 0; index < newPathSet.size(); index++) {
        final File fi = newPathSet.get(index);
        crumb = new Crumb(fi);

        // Restore scroll positions saved before clearing
        if (mOldCrumbs != null) {
          for (Iterator<Crumb> iterator = mOldCrumbs.iterator(); iterator.hasNext(); ) {
            Crumb old = iterator.next();
            if (old.equals(crumb)) {
              crumb.setScrollPosition(old.getScrollPosition());
              crumb.setScrollOffset(old.getScrollOffset());
              crumb.setQuery(old.getQuery());
              iterator.remove(); // minimize number of linear passes by removing un-used crumbs from
              // history
              break;
            }
          }
        }

        addCrumb(crumb, true);
      }

      // History no longer needed
      mOldCrumbs = null;
    } else {
      if (isStorageOrSd(crumb.getFile())) {
        Crumb c = mCrumbs.get(0);
        while (c != null && !isStorageOrSd(c.getFile())) {
          removeCrumbAt(0);
          if (mCrumbs.size() > 0) c = mCrumbs.get(0);
        }
        updateIndices();
        requestLayout();
      }
    }
  }
Example #2
0
 public static boolean isStorageOrSd(File fi) {
   if (fi == null) return false;
   else if (fi.getPluginPackage() != null)
     return File.isRootPluginFolder(fi.getUri(), ((PluginFileImpl) fi).getPlugin());
   return fi.isSDCardDirectory()
       || fi.isStorageDirectory()
       || (fi.isDocumentTreeFile() && fi.getParent() == null);
 }
Example #3
0
  public boolean trim(String str, boolean dir, boolean archive) {
    if (!dir && !archive) return false;
    int index = -1;
    for (int i = mCrumbs.size() - 1; i >= 0; i--) {
      File fi = mCrumbs.get(i).getFile();
      if (fi.getUri() != null && fi.getUri().toString().equals(str)) {
        index = i;
        break;
      }
    }

    boolean removedActive = index >= mActive;
    if (index > -1) {
      while (index <= mCrumbs.size() - 1) removeCrumbAt(index);
      if (mChildFrame.getChildCount() > 0) {
        int lastIndex = mCrumbs.size() - 1;
        invalidateActivated(mChildFrame.getChildAt(lastIndex), mActive == lastIndex, false, false);
      }
    }
    return removedActive || mCrumbs.size() == 0;
  }
Example #4
0
 public String getTitle(Context context) {
   if (mFile.getPluginPackage() != null) {
     if (PluginFileImpl.isRootPluginFolder(
         mFile.getUri(), ((PluginFileImpl) mFile).getPlugin())) {
       final String pluginAcc = mFile.getPluginAccount();
       if (pluginAcc != null) {
         final String accDisplay =
             PluginDataProvider.getAccountDisplay(context, mFile.getPluginPackage(), pluginAcc);
         if (accDisplay == null || accDisplay.trim().isEmpty()) return pluginAcc;
         return accDisplay;
       }
     }
   }
   String title = mFile.getDisplay(context);
   if (title == null) title = mFile.getName();
   else if (title.equals(context.getString(R.string.storage)))
     title = context.getString(R.string.internal_storage);
   return title;
 }
Example #5
0
 public boolean trim(File file) {
   return trim(file.getUri().toString(), file.isDirectory(), file.isViewableArchive(getContext()));
 }