-/* ownCloud Android client application
+/**
+ * ownCloud Android client application
+ *
* Copyright (C) 2015 ownCloud Inc.
*
* This program is free software: you can redistribute it and/or modify
import android.os.Message;
import android.util.Pair;
+import com.owncloud.android.MainApp;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.services.FileDownloader;
@Override
public void handleMessage(Message msg) {
Pair<Account, String> itemSyncKey = (Pair<Account, String>) msg.obj;
- /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
- "Handling sync folder " + itemSyncKey.second);*/
doOperation(itemSyncKey.first, itemSyncKey.second);
+ Log_OC.d(TAG, "Stopping after command with id " + msg.arg1);
mService.stopSelf(msg.arg1);
}
*/
private void doOperation(Account account, String remotePath) {
- /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
- "Getting sync folder " + remotePath);*/
mCurrentSyncOperation = mPendingOperations.get(account, remotePath);
if (mCurrentSyncOperation != null) {
mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(ocAccount, mService);
- /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
- "Executing sync folder " + remotePath);*/
result = mCurrentSyncOperation.execute(mOwnCloudClient, mStorageManager);
} catch (AccountsException e) {
} catch (IOException e) {
Log_OC.e(TAG, "Error while trying to get authorization", e);
} finally {
- /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
- "Removing payload " + remotePath);*/
-
mPendingOperations.removePayload(account, remotePath);
- mService.dispatchResultToOperationListeners(null, mCurrentSyncOperation, result);
+ mService.dispatchResultToOperationListeners(mCurrentSyncOperation, result);
sendBroadcastFinishedSyncFolder(account, remotePath, result.isSuccess());
}
}
}
- public void add(Account account, String remotePath, SynchronizeFolderOperation syncFolderOperation){
+ public void add(Account account, String remotePath,
+ SynchronizeFolderOperation syncFolderOperation){
mPendingOperations.putIfAbsent(account, remotePath, syncFolderOperation);
sendBroadcastNewSyncFolder(account, remotePath); // TODO upgrade!
}
Log_OC.e(TAG, "Cannot cancel with NULL parameters");
return;
}
- /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
- "Removing sync folder " + file.getRemotePath());*/
Pair<SynchronizeFolderOperation, String> removeResult =
mPendingOperations.remove(account, file.getRemotePath());
SynchronizeFolderOperation synchronization = removeResult.first;
if (synchronization != null) {
- /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
- "Canceling returned sync of " + file.getRemotePath());*/
synchronization.cancel();
} else {
// TODO synchronize?
if (mCurrentSyncOperation != null && mCurrentAccount != null &&
mCurrentSyncOperation.getRemotePath().startsWith(file.getRemotePath()) &&
account.name.equals(mCurrentAccount.name)) {
- /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
- "Canceling current sync as descendant: " + mCurrentSyncOperation.getRemotePath());*/
mCurrentSyncOperation.cancel();
- } else {
- /*Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(),
- "Nothing else in cancelation of " + file.getRemotePath());*/
}
}
}
/**
- * TODO review this method when "folder synchronization" replaces "folder download"; this is a fast and ugly
- * patch.
+ * TODO review this method when "folder synchronization" replaces "folder download";
+ * this is a fast and ugly patch.
*/
private void sendBroadcastNewSyncFolder(Account account, String remotePath) {
Intent added = new Intent(FileDownloader.getDownloadAddedMessage());
added.putExtra(FileDownloader.ACCOUNT_NAME, account.name);
added.putExtra(FileDownloader.EXTRA_REMOTE_PATH, remotePath);
- added.putExtra(FileDownloader.EXTRA_FILE_PATH, FileStorageUtils.getSavePath(account.name) + remotePath);
+ added.putExtra(FileDownloader.EXTRA_FILE_PATH, FileStorageUtils.getSavePath(account.name)
+ + remotePath);
mService.sendStickyBroadcast(added);
}
/**
- * TODO review this method when "folder synchronization" replaces "folder download"; this is a fast and ugly
- * patch.
+ * TODO review this method when "folder synchronization" replaces "folder download";
+ * this is a fast and ugly patch.
*/
- private void sendBroadcastFinishedSyncFolder(Account account, String remotePath, boolean success) {
+ private void sendBroadcastFinishedSyncFolder(Account account, String remotePath,
+ boolean success) {
Intent finished = new Intent(FileDownloader.getDownloadFinishMessage());
finished.putExtra(FileDownloader.ACCOUNT_NAME, account.name);
finished.putExtra(FileDownloader.EXTRA_REMOTE_PATH, remotePath);
- finished.putExtra(FileDownloader.EXTRA_FILE_PATH, FileStorageUtils.getSavePath(account.name) + remotePath);
+ finished.putExtra(FileDownloader.EXTRA_FILE_PATH,
+ FileStorageUtils.getSavePath(account.name) + remotePath);
finished.putExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, success);
mService.sendStickyBroadcast(finished);
}