Browse Source

Exit the current folder when not existing in the server any more

David A. Velasco 11 years ago
parent
commit
ab3bcf6fe6

+ 1 - 0
res/values/strings.xml

@@ -129,6 +129,7 @@
     <string name="sync_foreign_files_forgotten_ticker">Some local files were forgotten</string>
     <string name="sync_foreign_files_forgotten_content">%1$d files out of the %2$s directory could not be copied into</string>
     <string name="sync_foreign_files_forgotten_explanation">As of version 1.3.16, files uploaded from this device are copied into the local %1$s folder to prevent data loss when a single file is synced with multiple accounts.\n\nDue to this change, all files uploaded in previous versions of this app were copied into the %2$s folder. However, an error prevented the completion of this operation during account synchronization. You may either leave the file(s) as is and remove the link to %3$s, or move the file(s) into the %1$s directory and retain the link to %4$s.\n\nListed below are the local file(s), and the the remote file(s) in %5$s they were linked to.</string>
+	<string name="sync_current_folder_was_removed">Current folder was removed\n Browsing up to %1$s</string>    
     <string name="foreign_files_move">"Move all"</string>
     <string name="foreign_files_success">"All files were moved"</string>
     <string name="foreign_files_fail">"Some files could not be moved"</string>

+ 7 - 0
src/com/owncloud/android/operations/SynchronizeFolderOperation.java

@@ -293,6 +293,13 @@ public class SynchronizeFolderOperation extends RemoteOperation {
                 }
                 
             } else {
+                if (status == HttpStatus.SC_NOT_FOUND) {
+                    OCFile dir = mStorageManager.getFileByPath(mRemotePath);
+                    if (dir != null) {
+                        String currentSavePath = FileStorageUtils.getSavePath(mAccount.name);
+                        mStorageManager.removeFile(dir, (dir.isDown() && dir.getStoragePath().startsWith(currentSavePath)));
+                    }
+                }
                 result = new RemoteOperationResult(false, status, query.getResponseHeaders());
             }
 

+ 40 - 14
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -871,27 +871,53 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
 
                 String synchFolderRemotePath = intent.getStringExtra(FileSyncService.SYNC_FOLDER_REMOTE_PATH); 
 
+                /*
                 boolean fillBlankRoot = false;
-                OCFile currentDir = getCurrentDir();
                 if (currentDir == null) {
                     currentDir = mStorageManager.getFileByPath(OCFile.PATH_SEPARATOR);
                     fillBlankRoot = (currentDir != null);                   
                 }
+                */
+
+                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.getRemotePath().equals(synchFolderRemotePath)) {
+                        needToRefresh = true;
+                    }
 
-                if ((synchFolderRemotePath != null && currentDir != null && (currentDir.getRemotePath().equals(synchFolderRemotePath)))
-                        || fillBlankRoot ) {
-                    if (synchResult == null || synchResult.isSuccess()) {
-                        if (!fillBlankRoot) 
-                            currentDir = getStorageManager().getFileByPath(synchFolderRemotePath);
-                        if (currentDir != null) {
-                            OCFileListFragment fileListFragment = getListOfFilesFragment();
-                            if (fileListFragment != null) {
-                                fileListFragment.listDirectory(currentDir);
-                                
-                            }
-                            if (getSecondFragment() == null)
-                                setFile(currentDir);
+                    if (needToRefresh) {
+                        OCFileListFragment fileListFragment = getListOfFilesFragment();
+                        if (fileListFragment != null) {
+                            fileListFragment.listDirectory(currentDir);
+                        }
+                        boolean existsSecondFragment = (getSecondFragment() != null); 
+                        if (!existsSecondFragment) {
+                            setFile(currentDir);
                         }
+                        //updateFragmentsVisibility(existsSecondFragment);
+                        updateNavigationElementsInActionBar(existsSecondFragment ? getFile() : null);
                     }
                 }