import android.content.SharedPreferences;
import android.content.res.TypedArray;
import android.os.AsyncTask;
-import android.os.FileObserver;
import android.os.storage.StorageVolume;
import android.util.AttributeSet;
import android.util.Log;
// 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
@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);
}
/**
private int mId;
private String mCurrentDir;
+ private String mPreviousDir;
private NavigationLayoutMode mCurrentMode;
/**
* @hide
// Restrictions
private Map<DisplayRestrictions, Object> mRestrictions;
- private FileObserver mCurrentDirObserver;
+ private NavigationTask mNavigationTask;
/**
* @hide
//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);
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);
}
/**
public void recycle() {
if (this.mAdapter != null) {
this.mAdapter.dispose();
- this.mCurrentDirObserver.stopWatching();
}
}
}
/**
+ * Method that removes a {@link FileSystemObject} from the view
+ *
+ * @param fso The file system object
+ */
+ public void removeItem(FileSystemObject fso) {
+ // Delete also from internal list
+ if (fso != null) {
+ int cc = this.mFiles.size()-1;
+ for (int i = cc; i >= 0; i--) {
+ FileSystemObject f = this.mFiles.get(i);
+ if (f != null && f.compareTo(fso) == 0) {
+ this.mFiles.remove(i);
+ break;
+ }
+ }
+ }
+ this.mAdapter.remove(fso);
+ }
+
+ /**
+ * Method that removes a file system object from his path from the view
+ *
+ * @param path The file system object path
+ */
+ public void removeItem(String path) {
+ FileSystemObject fso = this.mAdapter.getItem(path);
+ if (fso != null) {
+ this.mAdapter.remove(fso);
+ }
+ }
+
+ /**
* Method that returns the current directory.
*
* @return String The current directory
final String newDir, final boolean addToHistory,
final boolean reload, final boolean useCurrent,
final SearchInfoParcelable searchInfo, final FileSystemObject scrollTo) {
- if (mCurrentDirObserver != null) {
- mCurrentDirObserver.stopWatching();
- mCurrentDirObserver = null;
+ if (mNavigationTask != null) {
+ this.mCurrentDir = this.mPreviousDir;
+ this.mPreviousDir = null;
+ mNavigationTask.cancel(true);
+ mNavigationTask = null;
}
- NavigationTask task = new NavigationTask(useCurrent, addToHistory, reload,
+
+ this.mPreviousDir = this.mCurrentDir;
+ this.mCurrentDir = newDir;
+ mNavigationTask = new NavigationTask(useCurrent, addToHistory, reload,
searchInfo, scrollTo, mRestrictions, mChRooted);
- task.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, newDir);
+ mNavigationTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, newDir);
}
/**
void onPostExecuteTask(
List<FileSystemObject> files, boolean addToHistory, boolean isNewHistory,
boolean hasChanged, SearchInfoParcelable searchInfo,
- final String newDir, final FileSystemObject scrollTo) {
+ String newDir, final FileSystemObject scrollTo) {
try {
//Check that there is not errors and have some data
if (files == null) {
+ this.mCurrentDir = this.mPreviousDir;
return;
}
scrollTo(scrollTo);
//The current directory is now the "newDir"
- this.mCurrentDir = newDir;
- mCurrentDirObserver = new FileObserver(newDir) {
- @Override
- public void onEvent(int event, final String path) {
- Runnable runnable = null;
- final String fullPath = newDir + '/' + path;
- // This is done because the implementation doesn't match the documentation
- // for FileObserver and we are given undocumented flags.
- event &= FileObserver.ALL_EVENTS;
-
- switch (event) {
- case FileObserver.CREATE:
- case FileObserver.MOVED_TO: {
- final FileSystemObject fso = FileHelper.createFileSystemObject(
- new File(fullPath));
-
- if (FileHelper.shouldShow(fso, mRestrictions, mChRooted)) {
- runnable = new Runnable() {
- @Override
- public void run() {
- mAdapter.add(fso);
- // TODO: refactor to move this off of UI thread
- mAdapter.sort(FileHelper.getSortComparator());
- }
- };
- break;
- }
- } case FileObserver.DELETE:
- case FileObserver.MOVED_FROM: {
- runnable = new Runnable() {
- @Override
- public void run() {
- mAdapter.remove(mAdapter.getItem(fullPath));
- }
- };
- break;
- } case FileObserver.DELETE_SELF: {
- // TODO: Actually handle this
- break;
-
- } case FileObserver.MODIFY: {
- runnable = new Runnable() {
- @Override
- public void run() {
- FileHelper.updateFileSystemObject(mAdapter.getItem(fullPath));
- mAdapter.notifyDataSetChanged();
- }
- };
- break;
- }
- default:
- Log.w(TAG, "Unknown event " + event + " for " + fullPath);
- }
-
- if (runnable != null) {
- post(runnable);
- }
- }
- };
- mCurrentDirObserver.startWatching();
-
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();
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);
}
}
// 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) {
*/
@Override
public void onRequestRefresh(Object o, boolean clearSelection) {
+ if (o instanceof FileSystemObject) {
+ refresh((FileSystemObject)o);
+ } else if (o == null) {
+ refresh();
+ }
if (clearSelection) {
onDeselectAll();
}
*/
@Override
public void onRequestRemove(Object o, boolean clearSelection) {
+ if (o != null && o instanceof FileSystemObject) {
+ removeItem((FileSystemObject)o);
+ } else {
+ onRequestRefresh(null, clearSelection);
+ }
if (clearSelection) {
onDeselectAll();
}