X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/dbfbc10af43b10fc23e56fa62ef0cde6df71f0e4..aae90eb1aa42a11449e30330e3e23e1e9e5eebb6:/src/com/owncloud/android/files/services/FileDownloader.java diff --git a/src/com/owncloud/android/files/services/FileDownloader.java b/src/com/owncloud/android/files/services/FileDownloader.java index b525bc4a..2e34a8b6 100644 --- a/src/com/owncloud/android/files/services/FileDownloader.java +++ b/src/com/owncloud/android/files/services/FileDownloader.java @@ -34,19 +34,21 @@ import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.network.OnDatatransferProgressListener; -import com.owncloud.android.lib.common.OwnCloudClientFactory; +import com.owncloud.android.lib.common.OwnCloudAccount; import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.operations.DownloadFileOperation; +import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; +import com.owncloud.android.notifications.NotificationBuilderWithProgressBar; +import com.owncloud.android.notifications.NotificationDelayer; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.resources.files.FileUtils; +import com.owncloud.android.operations.DownloadFileOperation; import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.ui.preview.PreviewImageActivity; import com.owncloud.android.ui.preview.PreviewImageFragment; import com.owncloud.android.utils.ErrorMessageAdapter; import com.owncloud.android.utils.Log_OC; -import com.owncloud.android.utils.NotificationBuilderWithProgressBar; import android.accounts.Account; import android.accounts.AccountsException; @@ -346,8 +348,11 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis /// prepare client object to send the request to the ownCloud server if (mDownloadClient == null || !mLastAccount.equals(mCurrentDownload.getAccount())) { mLastAccount = mCurrentDownload.getAccount(); - mStorageManager = new FileDataStorageManager(mLastAccount, getContentResolver()); - mDownloadClient = OwnCloudClientFactory.createOwnCloudClient(mLastAccount, getApplicationContext()); + mStorageManager = + new FileDataStorageManager(mLastAccount, getContentResolver()); + OwnCloudAccount ocAccount = new OwnCloudAccount(mLastAccount, this); + mDownloadClient = OwnCloudClientManagerFactory.getDefaultSingleton(). + getClientFor(ocAccount, this); } /// perform the download @@ -465,9 +470,10 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis int tickerId = (downloadResult.isSuccess()) ? R.string.downloader_download_succeeded_ticker : R.string.downloader_download_failed_ticker; - boolean needsToUpdateCredentials = (downloadResult.getCode() == ResultCode.UNAUTHORIZED || - (downloadResult.isIdPRedirection() - && mDownloadClient.getCredentials() == null)); + boolean needsToUpdateCredentials = ( + downloadResult.getCode() == ResultCode.UNAUTHORIZED || + downloadResult.isIdPRedirection() + ); tickerId = (needsToUpdateCredentials) ? R.string.downloader_download_failed_credentials_error : tickerId; @@ -507,13 +513,10 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis // Remove success notification if (downloadResult.isSuccess()) { // Sleep 2 seconds, so show the notification before remove it - Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - public void run() { - mNotificationManager.cancel(R.string.downloader_download_succeeded_ticker); - } - }, 2000); - + NotificationDelayer.cancelWithDelay( + mNotificationManager, + R.string.downloader_download_succeeded_ticker, + 2000); } }