X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/2623e9c1957e95166e99adc81481f91136ac4453..2a95f59adc2bdd8f8a90cab8fd8d28f90bf9fc68:/src/com/owncloud/android/operations/DownloadFileOperation.java diff --git a/src/com/owncloud/android/operations/DownloadFileOperation.java b/src/com/owncloud/android/operations/DownloadFileOperation.java index 75bf9234..cb4355f5 100644 --- a/src/com/owncloud/android/operations/DownloadFileOperation.java +++ b/src/com/owncloud/android/operations/DownloadFileOperation.java @@ -2,9 +2,8 @@ * Copyright (C) 2012-2013 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -33,6 +32,7 @@ import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.http.HttpStatus; +import com.owncloud.android.Log_OC; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.operations.RemoteOperation; import com.owncloud.android.operations.RemoteOperationResult; @@ -104,7 +104,7 @@ public class DownloadFileOperation extends RemoteOperation { .getMimeTypeFromExtension( mFile.getRemotePath().substring(mFile.getRemotePath().lastIndexOf('.') + 1)); } catch (IndexOutOfBoundsException e) { - Log.e(TAG, "Trying to find out MIME type of a file without extension: " + mFile.getRemotePath()); + Log_OC.e(TAG, "Trying to find out MIME type of a file without extension: " + mFile.getRemotePath()); } } if (mimeType == null) { @@ -123,9 +123,17 @@ public class DownloadFileOperation extends RemoteOperation { public void addDatatransferProgressListener (OnDatatransferProgressListener listener) { - mDataTransferListeners.add(listener); + synchronized (mDataTransferListeners) { + mDataTransferListeners.add(listener); + } } + public void removeDatatransferProgressListener(OnDatatransferProgressListener listener) { + synchronized (mDataTransferListeners) { + mDataTransferListeners.remove(listener); + } + } + @Override protected RemoteOperationResult run(WebdavClient client) { RemoteOperationResult result = null; @@ -148,11 +156,11 @@ public class DownloadFileOperation extends RemoteOperation { result = new RemoteOperationResult(RemoteOperationResult.ResultCode.LOCAL_STORAGE_NOT_MOVED); else result = new RemoteOperationResult(isSuccess(status), status); - Log.i(TAG, "Download of " + mFile.getRemotePath() + " to " + getSavePath() + ": " + result.getLogMessage()); + Log_OC.i(TAG, "Download of " + mFile.getRemotePath() + " to " + getSavePath() + ": " + result.getLogMessage()); } catch (Exception e) { result = new RemoteOperationResult(e); - Log.e(TAG, "Download of " + mFile.getRemotePath() + " to " + getSavePath() + ": " + result.getLogMessage(), e); + Log_OC.e(TAG, "Download of " + mFile.getRemotePath() + " to " + getSavePath() + ": " + result.getLogMessage(), e); } return result; @@ -190,9 +198,11 @@ public class DownloadFileOperation extends RemoteOperation { } fos.write(bytes, 0, readResult); transferred += readResult; - it = mDataTransferListeners.iterator(); - while (it.hasNext()) { - it.next().onTransferProgress(readResult, transferred, mFile.getFileLength(), targetFile.getName()); + synchronized (mDataTransferListeners) { + it = mDataTransferListeners.iterator(); + while (it.hasNext()) { + it.next().onTransferProgress(readResult, transferred, mFile.getFileLength(), targetFile.getName()); + } } } savedFile = true; @@ -221,4 +231,5 @@ public class DownloadFileOperation extends RemoteOperation { mCancellationRequested.set(true); // atomic set; there is no need of synchronizing it } + }