瀏覽代碼

Fixed search of an existing current folder when the activity detects that the current folder does not exist any more

David A. Velasco 11 年之前
父節點
當前提交
fc2baec2f6

+ 7 - 3
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++;

+ 6 - 4
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 

+ 28 - 9
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