X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/7d5c573766d7b8a5b8113479f29520628e0c7cb0..04d4be82cb10d54d506c79d737eaf7b87d382fea:/src/com/owncloud/android/utils/CopyTmpFileAsyncTask.java diff --git a/src/com/owncloud/android/utils/CopyTmpFileAsyncTask.java b/src/com/owncloud/android/utils/CopyTmpFileAsyncTask.java index 70bf2e9a..887a2f5b 100644 --- a/src/com/owncloud/android/utils/CopyTmpFileAsyncTask.java +++ b/src/com/owncloud/android/utils/CopyTmpFileAsyncTask.java @@ -1,6 +1,7 @@ /** * ownCloud Android client application * + * @author masensio * Copyright (C) 2015 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify @@ -18,14 +19,11 @@ */ package com.owncloud.android.utils; -import android.app.Activity; import android.content.ContentResolver; -import android.content.Context; import android.net.Uri; import android.os.AsyncTask; import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.ui.activity.FileActivity; import java.io.File; import java.io.FileOutputStream; @@ -39,35 +37,41 @@ public class CopyTmpFileAsyncTask extends AsyncTask { private final String TAG = CopyTmpFileAsyncTask.class.getSimpleName(); private final WeakReference mListener; - private String mAccountName; - private ContentResolver mContentResolver; private int mIndex; public int getIndex(){ return mIndex; } - public CopyTmpFileAsyncTask(Activity activity) { - mContentResolver = ((FileActivity) activity).getContentResolver(); - mAccountName = ((FileActivity) activity).getAccount().name; - mListener = new WeakReference((OnCopyTmpFileTaskListener)activity); + public CopyTmpFileAsyncTask(OnCopyTmpFileTaskListener listener) { + mListener = new WeakReference(listener); } + /** + * Params for execute: + * - Uri: uri of file + * - String: path for saving the file into the app + * - int: index of upload + * - String: accountName + * - ContentResolver: content resolver + */ @Override protected String doInBackground(Object[] params) { String result = null; - if (params.length == 3) { + if (params != null && params.length == 5) { Uri uri = (Uri) params[0]; String filePath = (String) params[1]; - mIndex = (int) params[2]; + mIndex = ((Integer) params[2]).intValue(); + String accountName = (String) params[3]; + ContentResolver contentResolver = (ContentResolver) params[4]; - String fullTempPath = FileStorageUtils.getTemporalPath(mAccountName) + filePath; + String fullTempPath = FileStorageUtils.getTemporalPath(accountName) + filePath; InputStream inputStream = null; FileOutputStream outputStream = null; try { - inputStream = mContentResolver.openInputStream(uri); + inputStream = contentResolver.openInputStream(uri); File cacheFile = new File(fullTempPath); File tempDir = cacheFile.getParentFile(); if (!tempDir.exists()) { @@ -112,7 +116,7 @@ public class CopyTmpFileAsyncTask extends AsyncTask { result = null; } } else { - Log_OC.e(TAG, "Error in parameters number"); + throw new IllegalArgumentException("Error in parameters number"); } return result; @@ -124,7 +128,7 @@ public class CopyTmpFileAsyncTask extends AsyncTask { OnCopyTmpFileTaskListener listener = mListener.get(); if (listener!= null) { - listener.OnCopyTmpFileTaskListener(result, mIndex); + listener.onTmpFileCopied(result, mIndex); } } @@ -133,6 +137,6 @@ public class CopyTmpFileAsyncTask extends AsyncTask { */ public interface OnCopyTmpFileTaskListener{ - void OnCopyTmpFileTaskListener(String result, int index); + void onTmpFileCopied(String result, int index); } }