From 163e9e7bbe56111d74d280dd7ea53fe339aa0cba Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Mon, 28 Mar 2016 15:14:03 +0200 Subject: [PATCH] Uploads delayed for Wifi processed as any other upload -> notifications sent, uploads view refreshed correctly --- .../android/files/services/FileUploader.java | 45 +------------------ .../operations/UploadFileOperation.java | 41 ++++++++++++++--- 2 files changed, 37 insertions(+), 49 deletions(-) diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index ad433b6f6a..524ce22cb6 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -51,7 +51,6 @@ import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.datamodel.UploadsStorageManager; import com.owncloud.android.datamodel.UploadsStorageManager.UploadStatus; import com.owncloud.android.db.OCUpload; -import com.owncloud.android.db.PreferenceReader; import com.owncloud.android.db.UploadResult; import com.owncloud.android.lib.common.OwnCloudAccount; import com.owncloud.android.lib.common.OwnCloudClient; @@ -67,7 +66,6 @@ import com.owncloud.android.notifications.NotificationDelayer; import com.owncloud.android.operations.UploadFileOperation; import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.activity.UploadListActivity; -import com.owncloud.android.utils.ConnectivityUtils; import com.owncloud.android.utils.ErrorMessageAdapter; import java.util.AbstractList; @@ -888,11 +886,6 @@ public class FileUploader extends Service return; } - /// Check that connectivity conditions are met and delayes the upload otherwise - if (delayForWifi()) { - return; - } - /// OK, let's upload mUploadsStorageManager.updateDatabaseUploadStart(mCurrentUpload); @@ -955,40 +948,6 @@ public class FileUploader extends Service } - /** - * Checks origin of current upload and network type to decide if should be delayed, according to - * current user preferences. - * - * @return 'True' if the upload was delayed until WiFi connectivity is available, 'false' otherwise. - */ - private boolean delayForWifi() { - - boolean delayInstantPicture = ( - mCurrentUpload.isInstantPicture() && - PreferenceReader.instantPictureUploadViaWiFiOnly(this) - ); - boolean delayInstantVideo = (mCurrentUpload.isInstantVideo() && - PreferenceReader.instantVideoUploadViaWiFiOnly(this) - ); - if ((delayInstantPicture || delayInstantVideo) && - !ConnectivityUtils.isAppConnectedViaWiFi(this)) { - - Log_OC.d(TAG, "Upload delayed until WiFi is available: " + mCurrentUpload.getRemotePath()); - mPendingUploads.removePayload( - mCurrentUpload.getAccount().name, - mCurrentUpload.getRemotePath() - ); - mUploadsStorageManager.updateDatabaseUploadResult( - new RemoteOperationResult(ResultCode.DELAYED_FOR_WIFI), - mCurrentUpload - ); - - return true; - } - return false; - } - - /** * Creates a status notification to show the upload progress * @@ -1006,8 +965,8 @@ public class FileUploader extends Service .setContentTitle(getString(R.string.uploader_upload_in_progress_ticker)) .setProgress(100, 0, false) .setContentText( - String.format(getString(R.string.uploader_upload_in_progress_content), 0, upload.getFileName - ())); + String.format(getString(R.string.uploader_upload_in_progress_content), 0, upload.getFileName()) + ); /// includes a pending intent in the notification showing the details Intent showUploadListIntent = new Intent(this, UploadListActivity.class); diff --git a/src/com/owncloud/android/operations/UploadFileOperation.java b/src/com/owncloud/android/operations/UploadFileOperation.java index 2e1fbc1e6b..f328586d3e 100644 --- a/src/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/com/owncloud/android/operations/UploadFileOperation.java @@ -27,6 +27,7 @@ import android.net.Uri; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.db.OCUpload; +import com.owncloud.android.db.PreferenceReader; import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.network.OnDatatransferProgressListener; @@ -42,6 +43,7 @@ import com.owncloud.android.lib.resources.files.ReadRemoteFileOperation; import com.owncloud.android.lib.resources.files.RemoteFile; import com.owncloud.android.lib.resources.files.UploadRemoteFileOperation; import com.owncloud.android.operations.common.SyncOperation; +import com.owncloud.android.utils.ConnectivityUtils; import com.owncloud.android.utils.FileStorageUtils; import com.owncloud.android.utils.MimetypeIconUtil; import com.owncloud.android.utils.UriUtils; @@ -338,13 +340,20 @@ public class UploadFileOperation extends SyncOperation { RemoteOperationResult result = null; File temporalFile = null, originalFile = new File(mOriginalStoragePath), expectedFile = null; - // check if the file continues existing before schedule the operation - if (!originalFile.exists()) { - Log_OC.d(TAG, mOriginalStoragePath.toString() + " not exists anymore"); - return new RemoteOperationResult(ResultCode.LOCAL_FILE_NOT_FOUND); - } - try { + + /// Check that connectivity conditions are met and delays the upload otherwise + if (delayForWifi()) { + Log_OC.d(TAG, "Upload delayed until WiFi is available: " + getRemotePath()); + return new RemoteOperationResult(ResultCode.DELAYED_FOR_WIFI); + } + + /// check if the file continues existing before schedule the operation + if (!originalFile.exists()) { + Log_OC.d(TAG, mOriginalStoragePath.toString() + " not exists anymore"); + return new RemoteOperationResult(ResultCode.LOCAL_FILE_NOT_FOUND); + } + /// check the existence of the parent folder for the file to upload String remoteParentPath = new File(getRemotePath()).getParent(); remoteParentPath = remoteParentPath.endsWith(OCFile.PATH_SEPARATOR) ? @@ -482,6 +491,26 @@ public class UploadFileOperation extends SyncOperation { } + /** + * Checks origin of current upload and network type to decide if should be delayed, according to + * current user preferences. + * + * @return 'True' if the upload was delayed until WiFi connectivity is available, 'false' otherwise. + */ + private boolean delayForWifi() { + boolean delayInstantPicture = ( + isInstantPicture() && PreferenceReader.instantPictureUploadViaWiFiOnly(mContext) + ); + boolean delayInstantVideo = ( + isInstantVideo() && PreferenceReader.instantVideoUploadViaWiFiOnly(mContext) + ); + return ( + (delayInstantPicture || delayInstantVideo) && + !ConnectivityUtils.isAppConnectedViaWiFi(mContext) + ); + } + + /** * Checks the existence of the folder where the current file will be uploaded both * in the remote server and in the local database.