[tx-robot] updated from transifex
[pub/Android/ownCloud.git] / src / com / owncloud / android / syncadapter / FileSyncAdapter.java
index 4b40ff4..9204aa0 100644 (file)
@@ -27,8 +27,8 @@ import java.util.Map;
 import org.apache.jackrabbit.webdav.DavException;
 
 import com.owncloud.android.Log_OC;
+import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
-import com.owncloud.android.authentication.AccountAuthenticator;
 import com.owncloud.android.authentication.AuthenticatorActivity;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
@@ -149,7 +149,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
             updateOCVersion();
             mCurrentSyncTime = System.currentTimeMillis();
             if (!mCancellation) {
-                synchronizeFolder(getStorageManager().getFileByPath(OCFile.PATH_SEPARATOR), true);
+                synchronizeFolder(getStorageManager().getFileByPath(OCFile.ROOT_PATH));
                 
             } else {
                 Log_OC.d(TAG, "Leaving synchronization before synchronizing the root folder because cancelation request");
@@ -218,9 +218,8 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
      *  depth first strategy. 
      * 
      *  @param folder                   Folder to synchronize.
-     *  @param updateFolderProperties   When 'true', updates also the properties of the of the target folder.
      */
-    private void synchronizeFolder(OCFile folder, boolean updateFolderProperties) {
+    private void synchronizeFolder(OCFile folder) {
         
         if (mFailedResultsCounter > MAX_FAILED_RESULTS || isFinisher(mLastFailedResult))
             return;
@@ -239,7 +238,6 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
         // folder synchronization
         SynchronizeFolderOperation synchFolderOp = new SynchronizeFolderOperation(  folder, 
                                                                                     mCurrentSyncTime, 
-                                                                                    updateFolderProperties,
                                                                                     true,
                                                                                     getStorageManager(), 
                                                                                     getAccount(), 
@@ -261,19 +259,17 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
             if (synchFolderOp.getForgottenLocalFiles().size() > 0) {
                 mForgottenLocalFiles.putAll(synchFolderOp.getForgottenLocalFiles());
             }
-            // synchronize children folders 
-            List<OCFile> children = synchFolderOp.getChildren();
-            fetchChildren(children);    // beware of the 'hidden' recursion here!
-            
-            // update folder size again after recursive synchronization
-            getStorageManager().calculateFolderSize(folder.getFileId());  
-            sendStickyBroadcast(true, folder.getRemotePath(), null);        // notify again
+            if (result.isSuccess()) {
+                // synchronize children folders 
+                List<OCFile> children = synchFolderOp.getChildren();
+                fetchChildren(folder, children, synchFolderOp.getRemoteFolderChanged());    // beware of the 'hidden' recursion here!
+            }
             
         } else {
             // in failures, the statistics for the global result are updated
             if (result.getCode() == RemoteOperationResult.ResultCode.UNAUTHORIZED ||
                     ( result.isIdPRedirection() && 
-                            AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(getClient().getAuthTokenType()))) {
+                            MainApp.getAuthTokenTypeSamlSessionCookie().equals(getClient().getAuthTokenType()))) {
                 mSyncResult.stats.numAuthExceptions++;
                 
             } else if (result.getException() instanceof DavException) {
@@ -311,12 +307,23 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
      * 
      * @param files         Files to recursively synchronize.
      */
-    private void fetchChildren(List<OCFile> files) {
+    private void fetchChildren(OCFile parent, List<OCFile> files, boolean parentEtagChanged) {
         int i;
+        OCFile newFile = null;
+        String etag = null;
+        boolean syncDown = false;
         for (i=0; i < files.size() && !mCancellation; i++) {
-            OCFile newFile = files.get(i);
-            if (newFile.isDirectory()) {
-                synchronizeFolder(newFile, false);
+            newFile = files.get(i);
+            if (newFile.isFolder()) {
+                /*
+                etag = newFile.getEtag();
+                syncDown = (parentEtagChanged || etag == null || etag.length() == 0);
+                if(syncDown) { */
+                    synchronizeFolder(newFile);
+                    // update the size of the parent folder again after recursive synchronization 
+                    //getStorageManager().updateFolderSize(parent.getFileId());  
+                    sendStickyBroadcast(true, parent.getRemotePath(), null);        // notify again to refresh size in UI
+                //}
             }
         }
        
@@ -331,7 +338,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
      * @param dirRemotePath     Remote path of a folder that was just synchronized (with or without success)
      */
     private void sendStickyBroadcast(boolean inProgress, String dirRemotePath, RemoteOperationResult result) {
-        Intent i = new Intent(FileSyncService.SYNC_MESSAGE);
+        Intent i = new Intent(FileSyncService.getSyncMessage());
         i.putExtra(FileSyncService.IN_PROGRESS, inProgress);
         i.putExtra(FileSyncService.ACCOUNT_NAME, getAccount().name);
         if (dirRemotePath != null) {
@@ -355,7 +362,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
                                              (  mLastFailedResult.getCode() == ResultCode.UNAUTHORIZED ||
                                                 // (mLastFailedResult.isTemporalRedirection() && mLastFailedResult.isIdPRedirection() && 
                                                 ( mLastFailedResult.isIdPRedirection() && 
-                                                 AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(getClient().getAuthTokenType()))
+                                                 MainApp.getAuthTokenTypeSamlSessionCookie().equals(getClient().getAuthTokenType()))
                                              )
                                            );
         // TODO put something smart in the contentIntent below for all the possible errors