Skip to content

Commit

Permalink
Avoid uploading not recent pictures/videos
Browse files Browse the repository at this point in the history
  • Loading branch information
davigonz committed Nov 6, 2017
1 parent e2dfae5 commit 1c59549
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/com/owncloud/android/services/SyncCameraFolderJobService.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.datamodel.CameraUploadsSyncStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.db.OCCameraUploadSync;
import com.owncloud.android.db.PreferenceManager;
import com.owncloud.android.files.services.TransferRequester;
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
Expand Down Expand Up @@ -76,7 +77,8 @@ public class SyncCameraFolderJobService extends JobService implements OnRemoteOp
private static Set<String> sRecentlyUploadedFilePaths = new HashSet<>(MAX_RECENTS);

// DB connection
private CameraUploadsSyncStorageManager mCameraUploadsSyncStorageManager = null;
private CameraUploadsSyncStorageManager mCameraUploadsSyncStorageManager;
private OCCameraUploadSync mOOCCameraUploadSync;

@Override
public boolean onStartJob(JobParameters jobParameters) {
Expand Down Expand Up @@ -178,6 +180,8 @@ private void getPicturesVideosFromServer() {
// Called once for pictures (if enabled) and again for videos (if enabled)
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {

mOOCCameraUploadSync = mCameraUploadsSyncStorageManager.getCameraUploadSync(null,null,null);

//Get local folder images
String localCameraPath = mConfig.getSourcePath();

Expand All @@ -197,6 +201,7 @@ public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationRe
if (result.getCode() == RemoteOperationResult.ResultCode.FILE_NOT_FOUND) {

for (File localFile : localFiles) {

handleNewFile(localFile);
}
}
Expand All @@ -208,9 +213,6 @@ public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationRe
compareFiles(localFiles, FileStorageUtils.castObjectsIntoRemoteFiles(remoteObjects));
}

// We have to unbind the service to get remote images/videos and finish the job when
// requested operations finish

mPerformedOperationsCounter++;

// User only requested to upload pictures
Expand Down Expand Up @@ -308,6 +310,13 @@ private synchronized void handleNewFile(File localFile) {

String localPath = mConfig.getSourcePath() + File.separator + fileName;

// Check file timestamp
if (isImage && localFile.lastModified() <= mOOCCameraUploadSync.getPicturesLastSync() ||
isVideo && localFile.lastModified() <= mOOCCameraUploadSync.getVideosLastSync()) {
Log_OC.i(TAG, "File " + localPath + " too old, ignoring");
return;
}

// Check duplicated detection
if (sRecentlyUploadedFilePaths.contains(localPath)) {
Log_OC.i(TAG, "Duplicate detection of " + localPath + ", ignoring");
Expand Down

0 comments on commit 1c59549

Please sign in to comment.