OSDN Git Service

Use System Resolver
[android-x86/packages-apps-CMFileManager.git] / src / com / cyanogenmod / filemanager / ui / widgets / NavigationView.java
old mode 100644 (file)
new mode 100755 (executable)
index 9573f68..6d8ba67
@@ -164,6 +164,12 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
             try {
                 // Response if the item can be removed
                 FileSystemObjectAdapter adapter = (FileSystemObjectAdapter)parent.getAdapter();
+
+                // Short circuit to protect OOBE
+                if (position < 0 || position >= adapter.getCount()) {
+                    return false;
+                }
+
                 FileSystemObject fso = adapter.getItem(position);
                 if (fso != null) {
                     if (fso instanceof ParentDirectory) {
@@ -214,15 +220,20 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
         private String mNewDirChecked;
         private final SearchInfoParcelable mSearchInfo;
         private final FileSystemObject mScrollTo;
+        private final Map<DisplayRestrictions, Object> mRestrictions;
+        private final boolean mChRooted;
 
         public NavigationTask(boolean useCurrent, boolean addToHistory, boolean reload,
-                SearchInfoParcelable searchInfo, FileSystemObject scrollTo) {
+                SearchInfoParcelable searchInfo, FileSystemObject scrollTo,
+                Map<DisplayRestrictions, Object> restrictions, boolean chRooted) {
             super();
             this.mUseCurrent = useCurrent;
             this.mAddToHistory = addToHistory;
             this.mSearchInfo = searchInfo;
             this.mReload = reload;
             this.mScrollTo = scrollTo;
+            this.mRestrictions = restrictions;
+            this.mChRooted = chRooted;
         }
 
         /**
@@ -234,15 +245,9 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
             // is created)
             mNewDirChecked = checkChRootedNavigation(params[0]);
 
-            //Check that it is really necessary change the directory
-            if (!mReload && NavigationView.this.mCurrentDir != null &&
-                    NavigationView.this.mCurrentDir.compareTo(mNewDirChecked) == 0) {
-                return null;
-            }
-
-            mHasChanged = !(NavigationView.this.mCurrentDir != null &&
-                    NavigationView.this.mCurrentDir.compareTo(mNewDirChecked) == 0);
-            mIsNewHistory = (NavigationView.this.mCurrentDir != null);
+            mHasChanged = !(NavigationView.this.mPreviousDir != null &&
+                    NavigationView.this.mPreviousDir.compareTo(mNewDirChecked) == 0);
+            mIsNewHistory = (NavigationView.this.mPreviousDir != null);
 
             try {
                 //Reset the custom title view and returns to breadcrumb
@@ -275,7 +280,12 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
                 if (!mUseCurrent) {
                     files = CommandHelper.listFiles(getContext(), mNewDirChecked, null);
                 }
-                return files;
+
+                //Apply user preferences
+                List<FileSystemObject> sortedFiles =
+                        FileHelper.applyUserPreferences(files, this.mRestrictions, this.mChRooted);
+
+                return sortedFiles;
 
             } catch (final ConsoleAllocException e) {
                 //Show exception and exists
@@ -369,13 +379,11 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
         @Override
         protected void onPostExecute(List<FileSystemObject> files) {
             // This means an exception. This method will be recalled then
-            if (files != null) {
-                onPostExecuteTask(files, mAddToHistory, mIsNewHistory, mHasChanged,
+            onPostExecuteTask(files, mAddToHistory, mIsNewHistory, mHasChanged,
                         mSearchInfo, mNewDirChecked, mScrollTo);
 
-                // Do animation
-                fadeEfect(false);
-            }
+            // Do animation
+            fadeEfect(false);
         }
 
         /**
@@ -402,6 +410,7 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
 
     private int mId;
     private String mCurrentDir;
+    private String mPreviousDir;
     private NavigationLayoutMode mCurrentMode;
     /**
      * @hide
@@ -422,6 +431,8 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
     // Restrictions
     private Map<DisplayRestrictions, Object> mRestrictions;
 
+    private NavigationTask mNavigationTask;
+
     /**
      * @hide
      */
@@ -494,7 +505,7 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
         //Return the persistent the data
         NavigationViewInfoParcelable parcel = new NavigationViewInfoParcelable();
         parcel.setId(this.mId);
-        parcel.setCurrentDir(this.mCurrentDir);
+        parcel.setCurrentDir(this.mPreviousDir);
         parcel.setChRooted(this.mChRooted);
         parcel.setSelectedFiles(this.mAdapter.getSelectedItems());
         parcel.setFiles(this.mFiles);
@@ -802,8 +813,25 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
             return;
         }
 
+        boolean addToHistory = false;
+        boolean reload = true;
+        boolean useCurrent = false;
+        SearchInfoParcelable searchInfo = null;
+
+        String newDir = this.mCurrentDir;
+        if (this.mNavigationTask != null) {
+            addToHistory = this.mNavigationTask.mAddToHistory;
+            reload = this.mNavigationTask.mReload;
+            useCurrent = this.mNavigationTask.mUseCurrent;
+            searchInfo = this.mNavigationTask.mSearchInfo;
+            this.mNavigationTask.cancel(true);
+            this.mNavigationTask = null;
+            this.mCurrentDir = this.mPreviousDir;
+            this.mPreviousDir = null;
+        }
+
         //Reload data
-        changeCurrentDir(this.mCurrentDir, false, true, false, null, scrollTo);
+        changeCurrentDir(newDir, addToHistory, reload, useCurrent, searchInfo, scrollTo);
     }
 
     /**
@@ -1008,9 +1036,18 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
             final String newDir, final boolean addToHistory,
             final boolean reload, final boolean useCurrent,
             final SearchInfoParcelable searchInfo, final FileSystemObject scrollTo) {
-        NavigationTask task = new NavigationTask(useCurrent, addToHistory, reload,
-                searchInfo, scrollTo);
-        task.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, newDir);
+        if (mNavigationTask != null) {
+            this.mCurrentDir = this.mPreviousDir;
+            this.mPreviousDir = null;
+            mNavigationTask.cancel(true);
+            mNavigationTask = null;
+        }
+
+        this.mPreviousDir = this.mCurrentDir;
+        this.mCurrentDir = newDir;
+        mNavigationTask = new NavigationTask(useCurrent, addToHistory, reload,
+                searchInfo, scrollTo, mRestrictions, mChRooted);
+        mNavigationTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, newDir);
     }
 
     /**
@@ -1054,13 +1091,10 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
         try {
             //Check that there is not errors and have some data
             if (files == null) {
+                this.mCurrentDir = this.mPreviousDir;
                 return;
             }
 
-            //Apply user preferences
-            List<FileSystemObject> sortedFiles =
-                    FileHelper.applyUserPreferences(files, this.mRestrictions, this.mChRooted);
-
             //Remove parent directory if we are in the root of a chrooted environment
             if (this.mChRooted && StorageHelper.isStorageVolume(newDir)) {
                 if (files.size() > 0 && files.get(0) instanceof ParentDirectory) {
@@ -1077,8 +1111,8 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
             }
 
             //Load the data
-            loadData(sortedFiles);
-            this.mFiles = sortedFiles;
+            loadData(files);
+            this.mFiles = files;
             if (searchInfo != null) {
                 searchInfo.setSuccessNavigation(true);
             }
@@ -1092,17 +1126,20 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
             scrollTo(scrollTo);
 
             //The current directory is now the "newDir"
-            this.mCurrentDir = newDir;
             if (this.mOnDirectoryChangedListener != null) {
                 FileSystemObject dir = FileHelper.createFileSystemObject(new File(newDir));
                 this.mOnDirectoryChangedListener.onDirectoryChanged(dir);
             }
+
         } finally {
             //If calling activity is search, then save the search history
             if (searchInfo != null) {
                 this.mOnHistoryListener.onNewHistory(searchInfo);
             }
 
+            this.mPreviousDir = null;
+            mNavigationTask = null;
+
             //End of loading data
             try {
                 NavigationView.this.mBreadcrumb.endLoading();
@@ -1139,6 +1176,9 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
 
         // Get the adapter and the fso
         FileSystemObjectAdapter adapter = ((FileSystemObjectAdapter)parent.getAdapter());
+        if (adapter == null || position < 0 || (position >= adapter.getCount())) {
+            return false;
+        }
         FileSystemObject fso = adapter.getItem(position);
 
         // Parent directory hasn't actions
@@ -1176,7 +1216,7 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
             changeCurrentDir(fso.getFullPath(), searchInfo);
         } else {
             // Open the file with the preferred registered app
-            IntentsActionPolicy.openFileSystemObject(getContext(), fso, false, null, null);
+            IntentsActionPolicy.openFileSystemObject(getContext(), fso, false, null);
         }
     }
 
@@ -1208,7 +1248,7 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
             // Open the file (edit or pick)
             if (this.mNavigationMode.compareTo(NAVIGATION_MODE.BROWSABLE) == 0) {
                 // Open the file with the preferred registered app
-                IntentsActionPolicy.openFileSystemObject(getContext(), fso, false, null, null);
+                IntentsActionPolicy.openFileSystemObject(getContext(), fso, false, null);
             } else {
                 // Request a file pick selection
                 if (this.mOnFilePickedListener != null) {
@@ -1266,6 +1306,11 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
         // Ignored
     }
 
+    @Override
+    public void onCancel() {
+        // nop
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -1372,7 +1417,7 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
 
         //Change to first storage volume
         StorageVolume[] volumes =
-                StorageHelper.getStorageVolumes(getContext());
+                StorageHelper.getStorageVolumes(getContext(), false);
         if (volumes != null && volumes.length > 0) {
             changeCurrentDir(volumes[0].getPath(), false, true, false, null, null);
         }
@@ -1403,7 +1448,7 @@ BreadcrumbListener, OnSelectionChangedListener, OnSelectionListener, OnRequestRe
 
         // Check if the path is owned by one of the storage volumes
         if (!StorageHelper.isPathInStorageVolume(newDir)) {
-            StorageVolume[] volumes = StorageHelper.getStorageVolumes(getContext());
+            StorageVolume[] volumes = StorageHelper.getStorageVolumes(getContext(), false);
             if (volumes != null && volumes.length > 0) {
                 return volumes[0].getPath();
             }