X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/407f64f5e062cbd59b82043406923f082c6fa911..407a31b3caa64451275670252c6815765dd0c111:/src/com/owncloud/android/services/OperationsService.java?ds=sidebyside diff --git a/src/com/owncloud/android/services/OperationsService.java b/src/com/owncloud/android/services/OperationsService.java index d3b6df34..eef9362d 100644 --- a/src/com/owncloud/android/services/OperationsService.java +++ b/src/com/owncloud/android/services/OperationsService.java @@ -172,12 +172,13 @@ public class OperationsService extends Service { return START_NOT_STICKY; } Account account = intent.getParcelableExtra(EXTRA_ACCOUNT); - OCFile file = intent.getParcelableExtra(EXTRA_REMOTE_PATH); - Pair itemSyncKey = new Pair(account, file); + String remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH); + + Pair itemSyncKey = new Pair(account, remotePath); Pair itemToQueue = newOperation(intent); if (itemToQueue != null) { - mSyncFolderHandler.add(account, file, (SynchronizeFolderOperation)itemToQueue.second); + mSyncFolderHandler.add(account, remotePath, (SynchronizeFolderOperation)itemToQueue.second); Message msg = mSyncFolderHandler.obtainMessage(); msg.arg1 = startId; msg.obj = itemSyncKey; @@ -189,10 +190,10 @@ public class OperationsService extends Service { return START_NOT_STICKY; } Account account = intent.getParcelableExtra(EXTRA_ACCOUNT); - OCFile file = intent.getParcelableExtra(EXTRA_REMOTE_PATH); + String remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH); // Cancel operation - mSyncFolderHandler.cancel(account,file); + mSyncFolderHandler.cancel(account,remotePath); } else { Message msg = mOperationsHandler.obtainMessage(); msg.arg1 = startId; @@ -375,7 +376,6 @@ public class OperationsService extends Service { private ConcurrentMap mPendingOperations = new ConcurrentHashMap(); - private RemoteOperation mCurrentOperation = null; private OwnCloudClient mOwnCloudClient = null; private FileDataStorageManager mStorageManager; private SynchronizeFolderOperation mCurrentSyncOperation; @@ -391,8 +391,8 @@ public class OperationsService extends Service { @Override public void handleMessage(Message msg) { - Pair itemSyncKey = (Pair) msg.obj; - nextOperation(itemSyncKey.first,itemSyncKey.second); + Pair itemSyncKey = (Pair) msg.obj; + doOperation(itemSyncKey.first, itemSyncKey.second); mService.stopSelf(msg.arg1); } @@ -400,9 +400,9 @@ public class OperationsService extends Service { /** * Performs the next operation in the queue */ - private void nextOperation(Account account, OCFile file) { + private void doOperation(Account account, String remotePath) { - String syncKey = buildRemoteName(account,file); + String syncKey = buildRemoteName(account,remotePath); synchronized(mPendingOperations) { mCurrentSyncOperation = mPendingOperations.get(syncKey); @@ -410,7 +410,6 @@ public class OperationsService extends Service { if (mCurrentSyncOperation != null) { - RemoteOperationResult operationResult = null; try { OwnCloudAccount ocAccount = new OwnCloudAccount(account, mService); @@ -421,47 +420,36 @@ public class OperationsService extends Service { mService.getContentResolver() ); - - /// perform the operation - if (mCurrentOperation instanceof SyncOperation) { - operationResult = ((SyncOperation)mCurrentOperation).execute(mOwnCloudClient, mStorageManager); - } else { - operationResult = mCurrentOperation.execute(mOwnCloudClient); - } + mCurrentSyncOperation.execute(mOwnCloudClient, mStorageManager); } catch (AccountsException e) { Log_OC.e(TAG, "Error while trying to get autorization", e); - operationResult = new RemoteOperationResult(e); } catch (IOException e) { Log_OC.e(TAG, "Error while trying to get autorization", e); - operationResult = new RemoteOperationResult(e); - } finally { synchronized(mPendingOperations) { mPendingOperations.remove(syncKey); } } - - /// TODO notify operation result if needed - } } - public void add(Account account, OCFile file, SynchronizeFolderOperation syncFolderOperation){ - String syncKey = buildRemoteName(account,file); + public void add(Account account, String remotePath, SynchronizeFolderOperation syncFolderOperation){ + String syncKey = buildRemoteName(account,remotePath); mPendingOperations.putIfAbsent(syncKey,syncFolderOperation); } + /** * Cancels a pending or current sync operation. * * @param account Owncloud account where the remote file is stored. - * @param file A file in the queue of pending downloads + * @param remotePath A remote file path */ - public void cancel(Account account, OCFile file) { + public void cancel(Account account, String remotePath) { SynchronizeFolderOperation syncOperation = null; synchronized (mPendingOperations) { - syncOperation = mPendingOperations.remove(buildRemoteName(account, file)); + syncOperation = mPendingOperations.remove(buildRemoteName(account, remotePath)); } if (syncOperation != null) { syncOperation.cancel(); @@ -472,10 +460,10 @@ public class OperationsService extends Service { * Builds a key from the account and file to download * * @param account Account where the file to download is stored - * @param file File to download + * @param path File path */ - private String buildRemoteName(Account account, OCFile file) { - return account.name + file.getRemotePath(); + private String buildRemoteName(Account account, String path) { + return account.name + path; } }