import android.accounts.Account;
import android.content.Context;
+import android.content.Intent;
+
import com.owncloud.android.Log_OC;
import com.owncloud.android.datamodel.DataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.operations.RemoteOperationResult.ResultCode;
+import com.owncloud.android.syncadapter.FileSyncService;
import com.owncloud.android.utils.FileStorageUtils;
import eu.alefzero.webdav.WebdavClient;
private Map<String, String> mForgottenLocalFiles;
+ private boolean mSyncFullAccount;
+
public SynchronizeFolderOperation( String remotePath,
long currentSyncTime,
long parentId,
boolean enforceMetadataUpdate,
+ boolean syncFullAccount,
DataStorageManager dataStorageManager,
Account account,
Context context ) {
mCurrentSyncTime = currentSyncTime;
mParentId = parentId;
mEnforceMetadataUpdate = enforceMetadataUpdate;
+ mSyncFullAccount = syncFullAccount;
mStorageManager = dataStorageManager;
mAccount = account;
mContext = context;
mFailsInFavouritesFound = 0;
mConflictsFound = 0;
mForgottenLocalFiles.clear();
- boolean fileChanged = false;
boolean dirChanged = false;
// code before in FileSyncAdapter.fetchData
OCFile oldFile = mStorageManager.getFileByPath(file.getRemotePath());
// Check if it is needed to synchronize the folder
- fileChanged = false;
if (oldFile != null) {
- if (!file.getEtag().equalsIgnoreCase(oldFile.getEtag())) {
- fileChanged = true;
+ if (!file.getEtag().equalsIgnoreCase(oldFile.getEtag())) {
}
- } else
- fileChanged= true;
-
-
- if (fileChanged){
- if (oldFile != null) {
- file.setKeepInSync(oldFile.keepInSync());
- file.setLastSyncDateForData(oldFile.getLastSyncDateForData());
- file.setModificationTimestampAtLastSyncForData(oldFile.getModificationTimestampAtLastSyncForData()); // must be kept unchanged when the file contents are not updated
- checkAndFixForeignStoragePath(oldFile);
- file.setStoragePath(oldFile.getStoragePath());
- if (file.isDirectory())
- file.setEtag(oldFile.getEtag());
- } else
- if (file.isDirectory())
- file.setEtag("");
-
- /// scan default location if local copy of file is not linked in OCFile instance
- if (file.getStoragePath() == null && !file.isDirectory()) {
- File f = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file));
- if (f.exists()) {
- file.setStoragePath(f.getAbsolutePath());
- file.setLastSyncDateForData(f.lastModified());
- }
- }
-
- /// prepare content synchronization for kept-in-sync files
- if (file.keepInSync()) {
- SynchronizeFileOperation operation = new SynchronizeFileOperation( oldFile,
- file,
- mStorageManager,
- mAccount,
- true,
- false,
- mContext
- );
- filesToSyncContents.add(operation);
+ }
+
+ if (oldFile != null) {
+ file.setKeepInSync(oldFile.keepInSync());
+ file.setLastSyncDateForData(oldFile.getLastSyncDateForData());
+ file.setModificationTimestampAtLastSyncForData(oldFile.getModificationTimestampAtLastSyncForData()); // must be kept unchanged when the file contents are not updated
+ checkAndFixForeignStoragePath(oldFile);
+ file.setStoragePath(oldFile.getStoragePath());
+ if (file.isDirectory())
+ file.setEtag(oldFile.getEtag());
+ } else
+ if (file.isDirectory())
+ file.setEtag("");
+
+ /// scan default location if local copy of file is not linked in OCFile instance
+ if (file.getStoragePath() == null && !file.isDirectory()) {
+ File f = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file));
+ if (f.exists()) {
+ file.setStoragePath(f.getAbsolutePath());
+ file.setLastSyncDateForData(f.lastModified());
}
+ }
- updatedFiles.add(file);
+ /// prepare content synchronization for kept-in-sync files
+ if (file.keepInSync()) {
+ SynchronizeFileOperation operation = new SynchronizeFileOperation( oldFile,
+ file,
+ mStorageManager,
+ mAccount,
+ true,
+ false,
+ mContext
+ );
+ filesToSyncContents.add(operation);
}
+
+ updatedFiles.add(file);
}
// save updated contents in local database; all at once, trying to get a best performance in database update (not a big deal, indeed)
Log_OC.e(TAG, "Synchronizing " + mAccount.name + ", folder " + mRemotePath + ": " + result.getLogMessage());
}
}
+
+ if (!mSyncFullAccount) {
+ sendStickyBroadcast(false, mRemotePath, result);
+ }
}
return result;
}
}
+ /**
+ * Sends a message to any application component interested in the progress of the synchronization.
+ *
+ * @param inProgress 'True' when the synchronization progress is not finished.
+ * @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);
+ i.putExtra(FileSyncService.IN_PROGRESS, inProgress);
+ i.putExtra(FileSyncService.ACCOUNT_NAME, mAccount.name);
+ if (dirRemotePath != null) {
+ i.putExtra(FileSyncService.SYNC_FOLDER_REMOTE_PATH, dirRemotePath);
+ }
+ if (result != null) {
+ i.putExtra(FileSyncService.SYNC_RESULT, result);
+ }
+ mContext.sendStickyBroadcast(i);
+ }
}
package com.owncloud.android.ui.activity;
import java.io.File;
-import java.io.IOException;
import android.accounts.Account;
-import android.accounts.AuthenticatorException;
-import android.accounts.OperationCanceledException;
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;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
-import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.owncloud.android.Log_OC;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountAuthenticator;
-import com.owncloud.android.authentication.AccountUtils;
-import com.owncloud.android.authentication.AccountUtils.AccountNotFoundException;
import com.owncloud.android.datamodel.DataStorageManager;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.services.FileObserverService;
import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
-import com.owncloud.android.network.OwnCloudClientUtils;
import com.owncloud.android.operations.CreateFolderOperation;
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.SynchronizeFolderOperation;
-import com.owncloud.android.operations.RemoteOperationResult.ResultCode;
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;
import com.owncloud.android.ui.preview.PreviewMediaFragment;
import com.owncloud.android.ui.preview.PreviewVideoActivity;
-import eu.alefzero.webdav.WebdavClient;
-
/**
* Displays, what files the user has available in his ownCloud.
*
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;
/// 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");
}
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 {
/**
}
- 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);
- }
- }
-
+// 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);
- } else if (operation instanceof SynchronizeFolderOperation) {
- onSynchronizeFolderOperationFinish((SynchronizeFolderOperation)operation, result);
- }
- }
-
-
- /**
- * Updates the view associated to the activity after the finish of an operation trying to synchronize a folder.
- *
- * @param operation Synchronize operation performed.
- * @param result Result of the synchronization.
- */
- private void onSynchronizeFolderOperationFinish(SynchronizeFolderOperation operation, RemoteOperationResult result) {
-
- OCFileListFragment list = getListOfFilesFragment();
- enableDisableViewGroup(list.getListView(), true);
- mSyncInProgress = false;
- updateDisplayHomeAtSync();
-
- setSupportProgressBarIndeterminateVisibility(false);
- if (result.isSuccess()) {
- if (result.getCode() != ResultCode.OK_NO_CHANGES_ON_DIR) {
- DataStorageManager storageManager = getStorageManager();
- OCFile parentDir = storageManager.getFileByPath(operation.getRemotePath());
-
- // Update folder size on DB
- getStorageManager().calculateFolderSize(parentDir.getFileId());
-
- // Refrest List
- refreshListOfFilesFragment(parentDir);
- }
- } else {
- try {
- Toast msg = Toast.makeText(FileDisplayActivity.this, R.string.sync_file_fail_msg, Toast.LENGTH_LONG);
- msg.show();
-
- } catch (NotFoundException e) {
- Log_OC.e(TAG, "Error while trying to show fail message " , e);
- }
- }
- }
-
-
- private void refreshListOfFilesFragment(OCFile parentDir) {
- OCFileListFragment fileListFragment = getListOfFilesFragment();
- if (fileListFragment != null) {
- fileListFragment.listDirectory(parentDir);
- }
+ }
}
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()) {
public void startSyncFolderOperation(String remotePath, long parentId) {
long currentSyncTime = System.currentTimeMillis();
- OCFileListFragment list = getListOfFilesFragment();
- enableDisableViewGroup(list.getListView(), false);
mSyncInProgress = true;
- updateDisplayHomeAtSync();
-
- // perform folder synchronization
+
+ // perform folder synchronization
RemoteOperation synchFolderOp = new SynchronizeFolderOperation( remotePath,
currentSyncTime,
parentId,
false,
+ false,
getStorageManager(),
getAccount(),
getApplicationContext()
);
- synchFolderOp.execute(getAccount(), this, this, mHandler, this);
+ 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);
- }
- }
- }
+// 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);
+// }
+// }
+// }
}