import com.owncloud.android.authenticator.AccountAuthenticator;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.files.PhotoTakenBroadcastReceiver;
+import com.owncloud.android.files.InstantUploadBroadcastReceiver;
import com.owncloud.android.operations.ChunkedUploadFileOperation;
import com.owncloud.android.operations.RemoteOperationResult;
import com.owncloud.android.operations.UploadFileOperation;
import com.owncloud.android.utils.OwnCloudVersion;
-import eu.alefzero.webdav.ChunkFromFileChannelRequestEntity;
import eu.alefzero.webdav.OnDatatransferProgressListener;
import com.owncloud.android.network.OwnCloudClientUtils;
import android.util.Log;
import android.widget.RemoteViews;
-import com.owncloud.android.AccountUtils;
import com.owncloud.android.R;
import eu.alefzero.webdav.WebdavClient;
private static final String TAG = FileUploader.class.getSimpleName();
- private NotificationManager mNotificationManager;
private Looper mServiceLooper;
private ServiceHandler mServiceHandler;
+
private AbstractList<Account> mAccounts = new Vector<Account>();
- private AbstractList<UploadFileOperation> mUploads = new Vector<UploadFileOperation>();
+ private AbstractList<UploadFileOperation> mUploads = new Vector<UploadFileOperation>();
+ private int mCurrentIndexUpload;
+
+ private NotificationManager mNotificationManager;
private Notification mNotification;
+ private RemoteViews mDefaultNotificationContentView;
private long mTotalDataToSend, mSendData;
- private int mTotalFilesToSend;
- private int mCurrentIndexUpload, mPreviousPercent;
+ private int mTotalFilesToSend, mPreviousPercent;
private int mSuccessCounter;
- private RemoteViews mDefaultNotificationContentView;
+
/**
* Static map with the files being download and the path to the temporal file were are download
* @return 'True' if the ownCloud server with version supports chunked uploads.
*/
private static boolean chunkedUploadIsSupported(OwnCloudVersion version) {
- //return (version != null && version.compareTo(OwnCloudVersion.owncloud_v4_5) >= 0); // TODO uncomment when feature is full in server
- return false;
+ return (version != null && version.compareTo(OwnCloudVersion.owncloud_v4_5) >= 0); // TODO uncomment when feature is full in server
+ //return false;
}
- @Override
- public IBinder onBind(Intent arg0) {
- return null;
- }
-
- private final class ServiceHandler extends Handler {
- public ServiceHandler(Looper looper) {
- super(looper);
- }
-
- @Override
- public void handleMessage(Message msg) {
- uploadFile();
- stopSelf(msg.arg1);
- }
- }
-
+ /**
+ * Service initialization
+ */
@Override
public void onCreate() {
super.onCreate();
mServiceHandler = new ServiceHandler(mServiceLooper);
}
+
+ /**
+ * Entry point to add one or several files to the queue of uploads.
+ *
+ * New uploads are added calling to startService(), resulting in a call to this method. This ensures the service will keep on working
+ * although the caller activity goes away.
+ */
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (!intent.hasExtra(KEY_ACCOUNT) && !intent.hasExtra(KEY_UPLOAD_TYPE)) {
/**
+ * Provides a binder object that clients can use to perform operations on the queue of uploads, excepting the addition of new files.
+ *
+ * Implemented to perform cancellation, pause and resume of existing uploads.
+ */
+ @Override
+ public IBinder onBind(Intent arg0) {
+ return null;
+ }
+
+
+ /**
+ * Upload worker. Performs the pending uploads in the order they were requested.
+ *
+ * Created with the Looper of a new thread, started in {@link FileUploader#onCreate()}.
+ */
+ private final class ServiceHandler extends Handler {
+ public ServiceHandler(Looper looper) {
+ super(looper);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ uploadFile();
+ stopSelf(msg.arg1);
+ }
+ }
+
+
+
+
+ /**
* Core upload method: sends the file(s) to upload
*/
public void uploadFile() {
*/
private boolean createRemoteFolderForInstantUploads(WebdavClient client, FileDataStorageManager storageManager) {
boolean result = true;
- OCFile instantUploadDir = storageManager.getFileByPath(PhotoTakenBroadcastReceiver.INSTANT_UPLOAD_DIR);
+ OCFile instantUploadDir = storageManager.getFileByPath(InstantUploadBroadcastReceiver.INSTANT_UPLOAD_DIR);
if (instantUploadDir == null) {
- result = client.createDirectory(PhotoTakenBroadcastReceiver.INSTANT_UPLOAD_DIR); // fail could just mean that it already exists, but local database is not synchronized; the upload will be started anyway
- OCFile newDir = new OCFile(PhotoTakenBroadcastReceiver.INSTANT_UPLOAD_DIR);
+ result = client.createDirectory(InstantUploadBroadcastReceiver.INSTANT_UPLOAD_DIR); // fail could just mean that it already exists, but local database is not synchronized; the upload will be started anyway
+ OCFile newDir = new OCFile(InstantUploadBroadcastReceiver.INSTANT_UPLOAD_DIR);
newDir.setMimetype("DIR");
newDir.setParentId(storageManager.getFileByPath(OCFile.PATH_SEPARATOR).getFileId());
storageManager.saveFile(newDir);
* Callback method to update the progress bar in the status notification.
*/
@Override
- public void transferProgress(long progressRate) {
+ public void onTransferProgress(long progressRate) {
mSendData += progressRate;
int percent = (int)(100*((double)mSendData)/((double)mTotalDataToSend));
if (percent != mPreviousPercent) {
}
mPreviousPercent = percent;
}
+
+ @Override
+ public void onTransferProgress(long progressRate, long totalTransferredSoFar, long totalToTransfer, String fileName) {
+ // TODO Maybe replace the other transferProgress with this
+ }
+
+
}