From: David A. Velasco Date: Tue, 8 Oct 2013 09:17:20 +0000 (+0200) Subject: Fixed search of an existing current folder when the activity detects that the current... X-Git-Tag: oc-android-1.5.5~155^2~21 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/fc2baec2f6b84159aec9c198075b88ba741e3609 Fixed search of an existing current folder when the activity detects that the current folder does not exist any more --- diff --git a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java index 4935a616..f8b69f4a 100644 --- a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -327,12 +327,16 @@ public class SynchronizeFolderOperation extends RemoteOperation { private void removeObsoleteFiles() { mChildren = mStorageManager.getDirectoryContent(mLocalFolder); OCFile file; - String currentSavePath = FileStorageUtils.getSavePath(mAccount.name); for (int i=0; i < mChildren.size(); ) { file = mChildren.get(i); if (file.getLastSyncDateForProperties() != mCurrentSyncTime) { - Log_OC.d(TAG, "removing file: " + file); - mStorageManager.removeFile(file, (file.isDown() && file.getStoragePath().startsWith(currentSavePath))); + if (file.isDirectory()) { + Log_OC.d(TAG, "removing folder: " + file); + mStorageManager.removeDirectory(file, true, true); + } else { + Log_OC.d(TAG, "removing file: " + file); + mStorageManager.removeFile(file, true); + } mChildren.remove(i); } else { i++; diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 6e2091b1..249691f5 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -601,8 +601,10 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa 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 @@ -870,8 +872,8 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa String synchFolderRemotePath = intent.getStringExtra(FileSyncService.SYNC_FOLDER_REMOTE_PATH); - OCFile currentFile = (getFile() == null) ? null : mStorageManager.getFileById(getFile().getFileId()); - OCFile currentDir = (getCurrentDir() == null) ? null : mStorageManager.getFileById(getCurrentDir().getFileId()); + OCFile currentFile = (getFile() == null) ? null : mStorageManager.getFileByPath(getFile().getRemotePath()); + OCFile currentDir = (getCurrentDir() == null) ? null : mStorageManager.getFileByPath(getCurrentDir().getRemotePath()); if (currentDir == null) { // current folder was removed from the server diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index 58ad639f..10b132b5 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -25,15 +25,18 @@ import com.owncloud.android.Log_OC; import com.owncloud.android.R; import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.datamodel.DataStorageManager; +import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.FileHandler; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; import com.owncloud.android.operations.OnRemoteOperationListener; import com.owncloud.android.operations.RemoteOperation; +import com.owncloud.android.operations.RemoteOperationResult; import com.owncloud.android.operations.RemoveFileOperation; import com.owncloud.android.operations.RenameFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation; +import com.owncloud.android.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.ui.activity.TransferServiceGetter; import com.owncloud.android.ui.adapter.FileListListAdapter; @@ -121,20 +124,35 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName /** - * Call this, when the user presses the up button + * Call this, when the user presses the up button. + * + * Tries to move up the current folder one level. If the parent folder was removed from the database, + * it continues browsing up until finding an existing folders. + * + * return Count of folder levels browsed up. */ - public void onBrowseUp() { + public int onBrowseUp() { OCFile parentDir = null; + int moveCount = 0; if(mFile != null){ DataStorageManager storageManager = mContainerActivity.getStorageManager(); - if (mFile.getParentId() == 0) { - parentDir = storageManager.getFileById(1); - } - else { - parentDir = storageManager.getFileById(mFile.getParentId()); - } + String parentPath = null; + if (mFile.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) { + parentPath = new File(mFile.getRemotePath()).getParent(); + parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : parentPath + OCFile.PATH_SEPARATOR; + parentDir = storageManager.getFileByPath(parentPath); + moveCount++; + } else { + parentDir = storageManager.getFileByPath(OCFile.PATH_SEPARATOR); // never returns null; keep the path in root folder + } + while (parentDir == null) { + parentPath = new File(parentPath).getParent(); + parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : parentPath + OCFile.PATH_SEPARATOR; + parentDir = storageManager.getFileByPath(parentPath); + moveCount++; + } // exit is granted because storageManager.getFileByPath("/") never returns null mFile = parentDir; } @@ -142,8 +160,9 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName listDirectory(mFile); mContainerActivity.startSyncFolderOperation(mFile); - } + } // else - should never happen now + return moveCount; } @Override