file = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR); // never returns null
}
setFile(file);
- mDirectories.clear();
- OCFile fileIt = file;
- while(fileIt != null && fileIt.getFileName() != OCFile.PATH_SEPARATOR) {
- if (fileIt.isDirectory()) {
- mDirectories.add(fileIt.getFileName());
- }
- fileIt = mStorageManager.getFileById(fileIt.getParentId());
- }
- mDirectories.add(OCFile.PATH_SEPARATOR);
+ setNavigationListWithFolder(file);
if (!stateWasRecovered) {
Log_OC.e(TAG, "Initializing Fragments in onAccountChanged..");
initFragmentsWithFile();
}
+ private void setNavigationListWithFolder(OCFile file) {
+ mDirectories.clear();
+ OCFile fileIt = file;
+ while(fileIt != null && fileIt.getFileName() != OCFile.PATH_SEPARATOR) {
+ if (fileIt.isDirectory()) {
+ mDirectories.add(fileIt.getFileName());
+ }
+ fileIt = mStorageManager.getFileById(fileIt.getParentId());
+ }
+ mDirectories.add(OCFile.PATH_SEPARATOR);
+ }
+
+
private void createMinFragments() {
OCFileListFragment listOfFiles = new OCFileListFragment();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
- int i = itemPosition;
- while (i-- != 0) {
- onBackPressed();
- }
- // the next operation triggers a new call to this method, but it's necessary to
- // ensure that the name exposed in the action bar is the current directory when the
- // user selected it in the navigation list
- if (itemPosition != 0)
+ if (itemPosition != 0) {
+ String targetPath = "";
+ for (int i=itemPosition; i < mDirectories.getCount() - 1; i++) {
+ targetPath = mDirectories.getItem(i) + OCFile.PATH_SEPARATOR + targetPath;
+ }
+ targetPath = OCFile.PATH_SEPARATOR + targetPath;
+ OCFile targetFolder = mStorageManager.getFileByPath(targetPath);
+ if (targetFolder != null) {
+ browseTo(targetFolder);
+ }
+
+ // the next operation triggers a new call to this method, but it's necessary to
+ // ensure that the name exposed in the action bar is the current directory when the
+ // user selected it in the navigation list
getSupportActionBar().setSelectedNavigationItem(0);
+ }
return true;
}
finish();
return;
}
- popDirname();
- listOfFiles.onBrowseUp();
+ int levelsUp = listOfFiles.onBrowseUp();
+ for (int i=0; i < levelsUp && mDirectories.getCount() > 1 ; i++) {
+ popDirname();
+ }
}
}
if (listOfFiles != null) { // should never be null, indeed
public void onReceive(Context context, Intent intent) {
boolean inProgress = intent.getBooleanExtra(FileSyncService.IN_PROGRESS, false);
String accountName = intent.getStringExtra(FileSyncService.ACCOUNT_NAME);
+ RemoteOperationResult synchResult = (RemoteOperationResult)intent.getSerializableExtra(FileSyncService.SYNC_RESULT);
Log_OC.d(TAG, "sync of account " + accountName + " is in_progress: " + inProgress);
- RemoteOperationResult synchResult = (RemoteOperationResult)intent.getSerializableExtra(FileSyncService.SYNC_RESULT);
-
if (getAccount() != null && accountName.equals(getAccount().name)) {
String synchFolderRemotePath = intent.getStringExtra(FileSyncService.SYNC_FOLDER_REMOTE_PATH);
- /*
- boolean fillBlankRoot = false;
- if (currentDir == null) {
- currentDir = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR);
- fillBlankRoot = (currentDir != null);
- }
- */
+ OCFile currentFile = (getFile() == null) ? null : mStorageManager.getFileByPath(getFile().getRemotePath());
+ OCFile currentDir = (getCurrentDir() == null) ? null : mStorageManager.getFileByPath(getCurrentDir().getRemotePath());
- OCFile currentDir = getCurrentDir();
- if (synchFolderRemotePath != null) {
-
- OCFile synchDir = getStorageManager().getFileByPath(synchFolderRemotePath);
- boolean needToRefresh = false;
- if (synchDir == null) {
- Log_OC.e(TAG, "SEARCHING NEW CURRENT");
- // after synchronizing the current folder does not exist (was deleted in the server) ; need to move to other
- String synchPath = synchFolderRemotePath;
- do {
- String synchParentPath = new File(synchPath).getParent();
- synchParentPath = synchParentPath.endsWith(OCFile.PATH_SEPARATOR) ? synchParentPath : synchParentPath + OCFile.PATH_SEPARATOR;
- synchDir = getStorageManager().getFileByPath(synchParentPath);
- popDirname();
- synchPath = synchParentPath;
- } while (synchDir == null); // sooner of later will get ROOT, that never is null
- currentDir = synchDir;
-
- Toast.makeText(FileDisplayActivity.this,
- String.format(getString(R.string.sync_current_folder_was_removed), synchPath),
- Toast.LENGTH_LONG).show();
- needToRefresh = true;
- }
+ if (currentDir == null) {
+ // current folder was removed from the server
+ Toast.makeText( FileDisplayActivity.this,
+ String.format(getString(R.string.sync_current_folder_was_removed), mDirectories.getItem(0)),
+ Toast.LENGTH_LONG)
+ .show();
+ browseToRoot();
- if (currentDir.getRemotePath().equals(synchFolderRemotePath)) {
- needToRefresh = true;
+ } else {
+ if (currentFile == null && !getFile().isDirectory()) {
+ // currently selected file was removed in the server, and now we know it
+ cleanSecondFragment();
+ currentFile = currentDir;
}
-
- if (needToRefresh) {
+
+ if (synchFolderRemotePath != null && currentDir.getRemotePath().equals(synchFolderRemotePath)) {
OCFileListFragment fileListFragment = getListOfFilesFragment();
if (fileListFragment != null) {
fileListFragment.listDirectory(currentDir);
}
- boolean existsSecondFragment = (getSecondFragment() != null);
- if (!existsSecondFragment) {
- setFile(currentDir);
- }
- //updateFragmentsVisibility(existsSecondFragment);
- updateNavigationElementsInActionBar(existsSecondFragment ? getFile() : null);
}
+ setFile(currentFile);
}
setSupportProgressBarIndeterminateVisibility(inProgress);
removeStickyBroadcast(intent);
-
mSyncInProgress = inProgress;
}
-
if (synchResult != null) {
if (synchResult.getCode().equals(RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED)) {
}
+ public void browseToRoot() {
+ OCFileListFragment listOfFiles = getListOfFilesFragment();
+ if (listOfFiles != null) { // should never be null, indeed
+ while (mDirectories.getCount() > 1) {
+ popDirname();
+ }
+ OCFile root = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR);
+ listOfFiles.listDirectory(root);
+ setFile(listOfFiles.getCurrentFile());
+ startSyncFolderOperation(root);
+ }
+ cleanSecondFragment();
+ }
+
+
+ public void browseTo(OCFile folder) {
+ if (folder == null || !folder.isDirectory()) {
+ throw new IllegalArgumentException("Trying to browse to invalid folder " + folder);
+ }
+ OCFileListFragment listOfFiles = getListOfFilesFragment();
+ if (listOfFiles != null) {
+ setNavigationListWithFolder(folder);
+ listOfFiles.listDirectory(folder);
+ setFile(listOfFiles.getCurrentFile());
+ startSyncFolderOperation(folder);
+ } else {
+ Log_OC.e(TAG, "Unexpected null when accessing list fragment");
+ }
+ cleanSecondFragment();
+ }
+
+
/**
* {@inheritDoc}
*
cleanSecondFragment();
// Sync Folder
- startSyncFolderOperation(directory.getRemotePath(), directory.getFileId());
+ startSyncFolderOperation(directory);
}
return null;
}
- public void startSyncFolderOperation(String remotePath, long parentId) {
+ public void startSyncFolderOperation(OCFile folder) {
long currentSyncTime = System.currentTimeMillis();
mSyncInProgress = true;
// perform folder synchronization
- RemoteOperation synchFolderOp = new SynchronizeFolderOperation( remotePath,
- currentSyncTime,
- parentId,
- false,
- false,
- getStorageManager(),
- getAccount(),
- getApplicationContext()
- );
+ RemoteOperation synchFolderOp = new SynchronizeFolderOperation( folder,
+ currentSyncTime,
+ false,
+ false,
+ getStorageManager(),
+ getAccount(),
+ getApplicationContext()
+ );
synchFolderOp.execute(getAccount(), this, null, null, this);
setSupportProgressBarIndeterminateVisibility(true);