Merge remote-tracking branch 'origin/develop' into refresh_folder_contents_when_brows...
authormasensio <masensio@solidgear.es>
Tue, 1 Oct 2013 10:58:17 +0000 (12:58 +0200)
committermasensio <masensio@solidgear.es>
Tue, 1 Oct 2013 10:58:17 +0000 (12:58 +0200)
1  2 
src/com/owncloud/android/datamodel/FileDataStorageManager.java
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@@ -126,7 -126,7 +126,7 @@@ public class FileDataStorageManager imp
          cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
          cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype());
          cv.put(ProviderTableMeta.FILE_NAME, file.getFileName());
 -        if (file.getParentId() != 0)
 +        if (file.getParentId() != DataStorageManager.ROOT_PARENT_ID)
              cv.put(ProviderTableMeta.FILE_PARENT, file.getParentId());
          cv.put(ProviderTableMeta.FILE_PATH, file.getRemotePath());
          if (!file.isDirectory())
          cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties());
          cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, file.getLastSyncDateForData());
          cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, file.keepInSync() ? 1 : 0);
 +        cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag());
  
          boolean sameRemotePath = fileExists(file.getRemotePath());
          boolean changesSizeOfAncestors = false;
              cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
              cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype());
              cv.put(ProviderTableMeta.FILE_NAME, file.getFileName());
 -            if (file.getParentId() != 0)
 +            if (file.getParentId() != DataStorageManager.ROOT_PARENT_ID)
                  cv.put(ProviderTableMeta.FILE_PARENT, file.getParentId());
              cv.put(ProviderTableMeta.FILE_PATH, file.getRemotePath());
              if (!file.isDirectory())
              cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties());
              cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, file.getLastSyncDateForData());
              cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, file.keepInSync() ? 1 : 0);
 +            cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag());
  
              if (fileExists(file.getRemotePath())) {
                  OCFile oldFile = getFileByPath(file.getRemotePath());
                      getColumnIndex(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA)));
              file.setKeepInSync(c.getInt(
                      c.getColumnIndex(ProviderTableMeta.FILE_KEEP_IN_SYNC)) == 1 ? true : false);
 +            file.setEtag(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_ETAG)));
 +                    
          }
          return file;
      }
          
          OCFile file; 
  
 -        while (parentId != 0) {
 +        while (parentId != DataStorageManager.ROOT_PARENT_ID) {
              
-             Log_OC.d(TAG, "parent = " + parentId);
              // Update the size of the parent
              calculateFolderSize(parentId);
              
@@@ -22,8 -22,8 +22,8 @@@ import java.io.File
  
  import android.accounts.Account;
  import android.app.AlertDialog;
 -import android.app.ProgressDialog;
  import android.app.Dialog;
 +import android.app.ProgressDialog;
  import android.content.BroadcastReceiver;
  import android.content.ComponentName;
  import android.content.ContentResolver;
@@@ -72,16 -72,15 +72,16 @@@ import com.owncloud.android.operations.
  import com.owncloud.android.operations.OnRemoteOperationListener;
  import com.owncloud.android.operations.RemoteOperation;
  import com.owncloud.android.operations.RemoteOperationResult;
 +import com.owncloud.android.operations.RemoteOperationResult.ResultCode;
  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.operations.SynchronizeFolderOperation;
  import com.owncloud.android.syncadapter.FileSyncService;
  import com.owncloud.android.ui.dialog.EditNameDialog;
 +import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;
  import com.owncloud.android.ui.dialog.LoadingDialog;
  import com.owncloud.android.ui.dialog.SslValidatorDialog;
 -import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;
  import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;
  import com.owncloud.android.ui.fragment.FileDetailFragment;
  import com.owncloud.android.ui.fragment.FileFragment;
@@@ -118,7 -117,6 +118,7 @@@ OCFileListFragment.ContainerActivity, F
      private View mRightFragmentContainer;
  
      private static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
 +    private static final String KEY_SYNC_IN_PROGRESS = "SYNC_IN_PROGRESS";
  
      public static final int DIALOG_SHORT_WAIT = 0;
      private static final int DIALOG_CHOOSE_UPLOAD_SOURCE = 1;
  
      private OCFile mWaitingToPreview;
      private Handler mHandler;
 +    
 +    private boolean mSyncInProgress = false;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          /// Load of saved instance state
          if(savedInstanceState != null) {
              mWaitingToPreview = (OCFile) savedInstanceState.getParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW);
 -
 +            mSyncInProgress = savedInstanceState.getBoolean(KEY_SYNC_IN_PROGRESS);
 +           
          } else {
              mWaitingToPreview = null;
 -        }
 +            mSyncInProgress = false;
 +        }        
  
          /// USER INTERFACE
  
          // Action bar setup
          mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);
          getSupportActionBar().setHomeButtonEnabled(true);       // mandatory since Android ICS, according to the official documentation
 -        setSupportProgressBarIndeterminateVisibility(false);    // always AFTER setContentView(...) ; to work around bug in its implementation
 +        setSupportProgressBarIndeterminateVisibility(mSyncInProgress);    // always AFTER setContentView(...) ; to work around bug in its implementation        
          
          Log_OC.d(TAG, "onCreate() end");
      }
              FileFragment second = getSecondFragment();
              OCFile currentDir = getCurrentDir();
              if((currentDir != null && currentDir.getParentId() != 0) || 
 -                    (second != null && second.getFile() != null)) {
 +                    (second != null && second.getFile() != null)) {                
                  onBackPressed(); 
 +                
              }
              break;
          }
  
      @Override
      public void onBackPressed() {
 -        OCFileListFragment listOfFiles = getListOfFilesFragment(); 
 -        if (mDualPane || getSecondFragment() == null) {
 -            if (listOfFiles != null) {  // should never be null, indeed
 -                if (mDirectories.getCount() <= 1) {
 -                    finish();
 -                    return;
 +        if (!mSyncInProgress) {
 +            OCFileListFragment listOfFiles = getListOfFilesFragment(); 
 +            if (mDualPane || getSecondFragment() == null) {
 +                if (listOfFiles != null) {  // should never be null, indeed
 +                    if (mDirectories.getCount() <= 1) {
 +                        finish();
 +                        return;
 +                    }
 +                    popDirname();
 +                    listOfFiles.onBrowseUp();
                  }
 -                popDirname();
 -                listOfFiles.onBrowseUp();
              }
 +            if (listOfFiles != null) {  // should never be null, indeed
 +                setFile(listOfFiles.getCurrentFile());
 +            }
 +            cleanSecondFragment();
          }
 -        if (listOfFiles != null) {  // should never be null, indeed
 -            setFile(listOfFiles.getCurrentFile());
 -        }
 -        cleanSecondFragment();
      }
  
      @Override
          Log_OC.e(TAG, "onSaveInstanceState() start");
          super.onSaveInstanceState(outState);
          outState.putParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW, mWaitingToPreview);
 +        outState.putBoolean(FileDisplayActivity.KEY_SYNC_IN_PROGRESS, mSyncInProgress);
 +
          Log_OC.d(TAG, "onSaveInstanceState() end");
      }
      
  
  
      @Override
 +    protected void onStart() {
 +        super.onStart();
 +        Log_OC.e(TAG, "onStart() start");
 +        
 +        // Update the sync operation
 +        if (mSyncInProgress){
 +        }
 +        
 +        Log_OC.e(TAG, "onStart() end");
 +    }
 +
 +
 +    @Override
      protected void onPause() {
          super.onPause();
          Log_OC.e(TAG, "onPause() start");
              String accountName = intent.getStringExtra(FileSyncService.ACCOUNT_NAME);
  
              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); 
                      OCFileListFragment fileListFragment = getListOfFilesFragment();
                      if (fileListFragment != null) {
                          fileListFragment.listDirectory(currentDir);
 +                        
                      }
                      if (getSecondFragment() == null)
                          setFile(currentDir);
                  
                  setSupportProgressBarIndeterminateVisibility(inProgress);
                  removeStickyBroadcast(intent);
 +                
 +                mSyncInProgress = inProgress;
  
              }
  
 -            RemoteOperationResult synchResult = (RemoteOperationResult)intent.getSerializableExtra(FileSyncService.SYNC_RESULT);
 +            
              if (synchResult != null) {
                  if (synchResult.getCode().equals(RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED)) {
                      mLastSslUntrustedServerResult = synchResult;
              }
          }
      }
 -
 +    
  
      private class UploadFinishReceiver extends BroadcastReceiver {
          /**
      public void onBrowsedDownTo(OCFile directory) {
          pushDirname(directory);
          cleanSecondFragment();
 +        
 +        // Sync Folder
 +        startSyncFolderOperation(directory.getRemotePath(), directory.getFileId());
 +        
      }
  
      /**
          if (chosenFile == null || mDualPane) {
              // only list of files - set for browsing through folders
              OCFile currentDir = getCurrentDir();
 -            actionBar.setDisplayHomeAsUpEnabled(currentDir != null && currentDir.getParentId() != 0);
 +            actionBar.setDisplayHomeAsUpEnabled(currentDir != null && currentDir.getParentId() != 0 && !mSyncInProgress);
              actionBar.setDisplayShowTitleEnabled(false);
              actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
              actionBar.setListNavigationCallbacks(mDirectories, this);   // assuming mDirectories is updated
      }
  
  
 +//    private void updateDisplayHomeAtSync(){
 +//        ActionBar actionBar = getSupportActionBar();
 +//        OCFile currentDir = getCurrentDir();
 +//        if (currentDir.getParentId() != DataStorageManager.ROOT_PARENT_ID) {
 +//            actionBar.setHomeButtonEnabled(!mSyncInProgress);
 +//            actionBar.setDisplayHomeAsUpEnabled(!mSyncInProgress);
 +//        }
 +//        else {
 +//            actionBar.setHomeButtonEnabled(true);
 +//            actionBar.setDisplayHomeAsUpEnabled(false);
 +//        }
 +//    }
 +//    
      /**
       * {@inheritDoc}
       */
  
          } else if (operation instanceof CreateFolderOperation) {
              onCreateFolderOperationFinish((CreateFolderOperation)operation, result);
 -        }
 +            
 +        } 
      }
  
  
              refeshListOfFilesFragment();
  
          } else {
 -            //dismissDialog(DIALOG_SHORT_WAIT);
              dismissLoadingDialog();
              try {
                  Toast msg = Toast.makeText(FileDisplayActivity.this, R.string.create_dir_fail_msg, Toast.LENGTH_LONG); 
                  i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, getAccount());
                  startActivity(i);
  
 -            } else {
 -                Toast msg = Toast.makeText(this, R.string.sync_file_fail_msg, Toast.LENGTH_LONG); 
 -                msg.show();
 -            }
 +            } 
  
          } else {
              if (operation.transferWasRequested()) {
  
                  // Create directory
                  path += newDirectoryName + OCFile.PATH_SEPARATOR;
-                 RemoteOperation operation = new CreateFolderOperation(path, getCurrentDir().getFileId(), mStorageManager);
+                 RemoteOperation operation = new CreateFolderOperation(path, false, mStorageManager);
                  operation.execute(  getAccount(), 
                          FileDisplayActivity.this, 
                          FileDisplayActivity.this, 
          }
          return null;
      }
 +    
 +    public void startSyncFolderOperation(String remotePath, long parentId) {
 +        long currentSyncTime = System.currentTimeMillis(); 
 +        
 +        mSyncInProgress = true;
 +                
 +        // perform folder synchronization
 +        RemoteOperation synchFolderOp = new SynchronizeFolderOperation(  remotePath, 
 +                                                                                    currentSyncTime, 
 +                                                                                    parentId, 
 +                                                                                    false,
 +                                                                                    false,
 +                                                                                    getStorageManager(), 
 +                                                                                    getAccount(), 
 +                                                                                    getApplicationContext()
 +                                                                                  );
 +        synchFolderOp.execute(getAccount(), this, null, null, this);
 +        
 +        setSupportProgressBarIndeterminateVisibility(true);
 +    }
  
 +    
 +//    public void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
 +//        int childCount = viewGroup.getChildCount();
 +//        for (int i = 0; i < childCount; i++) {
 +//          View view = viewGroup.getChildAt(i);
 +//          view.setEnabled(enabled);
 +//          view.setClickable(!enabled);
 +//          if (view instanceof ViewGroup) {
 +//            enableDisableViewGroup((ViewGroup) view, enabled);
 +//          }
 +//        }
 +//      }
  }