From 9dada5316bb8dad2f9f4df150e531feeb739eb24 Mon Sep 17 00:00:00 2001 From: davigonz Date: Wed, 6 Dec 2017 13:39:56 +0100 Subject: [PATCH] Fixing bug 3 [WIP] --- .../files/services/CameraUploadsHandler.java | 39 +++++++++---- .../services/CameraUploadsSyncJobService.java | 57 ++++++++++--------- src/com/owncloud/android/utils/Extras.java | 9 ++- 3 files changed, 65 insertions(+), 40 deletions(-) diff --git a/src/com/owncloud/android/files/services/CameraUploadsHandler.java b/src/com/owncloud/android/files/services/CameraUploadsHandler.java index bd1c82483df..7013bd69f04 100644 --- a/src/com/owncloud/android/files/services/CameraUploadsHandler.java +++ b/src/com/owncloud/android/files/services/CameraUploadsHandler.java @@ -42,11 +42,11 @@ public class CameraUploadsHandler { private static IndexedForest mPendingCameraUploads = new IndexedForest<>(); private static final long MILLISECONDS_INTERVAL_CAMERA_UPLOAD = 900000; - private CameraUploadsConfiguration mCameraUploadsConfiguration; // Camera uploads configuration, set by the user + private CameraUploadsConfiguration mCameraUploadsConfig; // Camera uploads configuration, set by the user private Context mContext; public CameraUploadsHandler(CameraUploadsConfiguration cameraUploadsConfiguration, Context context) { - mCameraUploadsConfiguration = cameraUploadsConfiguration; + mCameraUploadsConfig = cameraUploadsConfiguration; mContext = context; } @@ -56,7 +56,7 @@ public CameraUploadsHandler(CameraUploadsConfiguration cameraUploadsConfiguratio public void scheduleCameraUploadsSyncJob() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && - (mCameraUploadsConfiguration.isEnabledForPictures() || mCameraUploadsConfiguration. + (mCameraUploadsConfig.isEnabledForPictures() || mCameraUploadsConfig. isEnabledForVideos())) { // Initialize synchronization timestamps for pictures/videos, if needed @@ -66,8 +66,8 @@ public void scheduleCameraUploadsSyncJob() { CameraUploadsSyncJobService.class); JobInfo.Builder builder; - int jobId = mPendingCameraUploads.buildKey(mCameraUploadsConfiguration.getUploadAccountName(), - mCameraUploadsConfiguration.getSourcePath()).hashCode(); + int jobId = mPendingCameraUploads.buildKey(mCameraUploadsConfig.getUploadAccountName(), + mCameraUploadsConfig.getSourcePath()).hashCode(); builder = new JobInfo.Builder(jobId, serviceComponent); @@ -79,7 +79,24 @@ public void scheduleCameraUploadsSyncJob() { // Extra data PersistableBundle extras = new PersistableBundle(); - extras.putInt(Extras.EXTRA_SYNC_CAMERA_FOLDER_JOB_ID, jobId); + extras.putInt(Extras.EXTRA_CAMERA_UPLOADS_SYNC_JOB_ID, jobId); + + extras.putString(Extras.EXTRA_ACCOUNT_NAME, mCameraUploadsConfig.getUploadAccountName()); + + if (mCameraUploadsConfig.isEnabledForPictures()) { + extras.putString(Extras.EXTRA_CAMERA_UPLOADS_PICTURES_PATH, mCameraUploadsConfig. + getUploadPathForPictures()); + } + + if (mCameraUploadsConfig.isEnabledForVideos()) { + extras.putString(Extras.EXTRA_CAMERA_UPLOADS_VIDEOS_PATH, mCameraUploadsConfig. + getUploadPathForVideos()); + } + + extras.putString(Extras.EXTRA_CAMERA_UPLOADS_SOURCE_PATH, mCameraUploadsConfig.getSourcePath()); + + extras.putInt(Extras.EXTRA_CAMERA_UPLOADS_BEHAVIOR_AFTER_UPLOAD, mCameraUploadsConfig. + getBehaviourAfterUpload()); builder.setExtras(extras); @@ -101,7 +118,7 @@ public void scheduleCameraUploadsSyncJob() { private void initializeCameraUploadSync() { // Set synchronization timestamps not needed - if (!mCameraUploadsConfiguration.isEnabledForPictures() && !mCameraUploadsConfiguration.isEnabledForVideos()) { + if (!mCameraUploadsConfig.isEnabledForPictures() && !mCameraUploadsConfig.isEnabledForVideos()) { return; } @@ -116,8 +133,8 @@ private void initializeCameraUploadSync() { if (ocCameraUploadSync == null) { // No synchronization timestamp for pictures/videos yet - long firstPicturesTimeStamp = mCameraUploadsConfiguration.isEnabledForPictures() ? timeStamp : 0; - long firstVideosTimeStamp = mCameraUploadsConfiguration.isEnabledForVideos() ? timeStamp : 0; + long firstPicturesTimeStamp = mCameraUploadsConfig.isEnabledForPictures() ? timeStamp : 0; + long firstVideosTimeStamp = mCameraUploadsConfig.isEnabledForVideos() ? timeStamp : 0; // Initialize synchronization timestamp for pictures or videos in database OCCameraUploadSync firstOcCameraUploadSync = new OCCameraUploadSync(firstPicturesTimeStamp, @@ -136,13 +153,13 @@ private void initializeCameraUploadSync() { return; } - if (ocCameraUploadSync.getPicturesLastSync() == 0 && mCameraUploadsConfiguration.isEnabledForPictures()) { + if (ocCameraUploadSync.getPicturesLastSync() == 0 && mCameraUploadsConfig.isEnabledForPictures()) { // Pictures synchronization timestamp not initialized yet, initialize it ocCameraUploadSync.setPicturesLastSync(timeStamp); } - if (ocCameraUploadSync.getVideosLastSync() == 0 && mCameraUploadsConfiguration.isEnabledForVideos()) { + if (ocCameraUploadSync.getVideosLastSync() == 0 && mCameraUploadsConfig.isEnabledForVideos()) { // Videos synchronization timestamp not initialized yet, initialize it ocCameraUploadSync.setVideosLastSync(timeStamp); diff --git a/src/com/owncloud/android/files/services/CameraUploadsSyncJobService.java b/src/com/owncloud/android/files/services/CameraUploadsSyncJobService.java index 18959a0a384..1e5b8a7b5d7 100644 --- a/src/com/owncloud/android/files/services/CameraUploadsSyncJobService.java +++ b/src/com/owncloud/android/files/services/CameraUploadsSyncJobService.java @@ -31,7 +31,6 @@ import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.datamodel.CameraUploadsSyncStorageManager; import com.owncloud.android.db.OCCameraUploadSync; -import com.owncloud.android.db.PreferenceManager; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.operations.UploadFileOperation; import com.owncloud.android.utils.Extras; @@ -63,10 +62,13 @@ private static class CameraUploadsSyncJobTask extends AsyncTask