Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1afb977c authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

Replace instanciation of UploadFileOperation by SyncRequest instanciation

- Update ObserverService: replace new UploadFileOperation(...) by new SyncedRequest(...)
- Update ObserverService: Remove loop over SyncedFolder to check isScanRemote as SyncedFileState.isMediaType() give the same
- Update SynchronizerService to instanciate UploadFileOperation from SyncRequest of Upload Type
parent 20469cc6
Loading
Loading
Loading
Loading
+4 −19
Original line number Diff line number Diff line
@@ -695,22 +695,8 @@ public class ObserverService extends Service implements OnRemoteOperationListene

                    //If no etag is stored in sfs, the file hasn't been sync up to server. then do upload
                    if ( syncedFileState.getLocalLastModified() < localFile.lastModified() || !syncedFileState.isLastEtagStored()){
                        Log.d(TAG+"_handleLocalFiles()", syncedFileState.getName()+" file has been modified or never sync" );
                        boolean checkEtag = false;

                        //Look for folder to know if the folder can be scan remotly.
                        for(int folderIndex =-1, size = mSyncedFolders.size();++folderIndex < size;) {

                            final SyncedFolder syncedFolder = mSyncedFolders.get(folderIndex);
                            if (syncedFolder.getId() == syncedFileState.getSyncedFolderId()) {
                                //Parent folder has been found
                                checkEtag = syncedFolder.isScanRemote();
                                break;
                            }
                        }
                        Log.i(TAG, "Add upload operation for file "+syncedFileState.getId());
                        UploadFileOperation uploadFileOperation = new UploadFileOperation(syncedFileState, checkEtag );
                        this.syncRequests.put(syncedFileState.getId(), uploadFileOperation);
                        Log.i(TAG, "Add upload request for file "+syncedFileState.getId());
                        this.syncRequests.put(syncedFileState.getId(), new SyncRequest(syncedFileState, SyncRequest.Type.UPLOAD));
                    }
                    // No need to reloop on it.
                    syncedFileListIterator.remove();
@@ -736,9 +722,8 @@ public class ObserverService extends Service implements OnRemoteOperationListene
                    if (storedId > 0){
                        newSyncedFileState.setId( storedId );
                        Log.i(TAG, "Add upload operation for new file "+storedId);
                        //create UploadOperation and add it into bundle
                        UploadFileOperation uploadOperation = new UploadFileOperation(newSyncedFileState, syncedFolder.isScanRemote());
                        this.syncRequests.put(storedId, uploadOperation);

                        this.syncRequests.put(storedId, new SyncRequest(newSyncedFileState, SyncRequest.Type.UPLOAD));
                    } else {
                        Log.w(TAG, "The new file to synced cannot be store in DB. Ignore it");
                    }
+7 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import java.util.concurrent.ConcurrentLinkedDeque;

import foundation.e.drive.database.DbHelper;
import foundation.e.drive.models.SyncRequest;
import foundation.e.drive.models.SyncedFileState;
import foundation.e.drive.operations.DownloadFileOperation;
import foundation.e.drive.operations.RemoveFileOperation;
import foundation.e.drive.operations.UploadFileOperation;
@@ -211,7 +212,8 @@ public class SynchronizationService extends Service implements OnRemoteOperation
        RemoteOperation operation;
        switch (request.getOperationType()){
            case UPLOAD:
                operation = new UploadFileOperation();
                final SyncedFileState sfs = request.getSyncedFileState();
                operation = new UploadFileOperation(sfs, sfs.isMediaType());
                break;
            case DOWNLOAD:
                operation = new DownloadFileOperation();
@@ -219,7 +221,11 @@ public class SynchronizationService extends Service implements OnRemoteOperation
            case REMOTE_DELETE:
                operation = new RemoveFileOperation();
                break;
            default:
                operation = null;
                break;
        }
        return operation;
    }