From: David A. Velasco Date: Mon, 13 Jul 2015 12:16:18 +0000 (+0200) Subject: Extend SyncFolderOperation to check local changes of all files and trigger uploads X-Git-Tag: oc-android-1.9^2~37^2~24 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/ac685690a2bf019d2978082debe62ec6aea0a69f?ds=sidebyside Extend SyncFolderOperation to check local changes of all files and trigger uploads --- diff --git a/owncloud-android-library b/owncloud-android-library index ecc3415e..c726e76d 160000 --- a/owncloud-android-library +++ b/owncloud-android-library @@ -1 +1 @@ -Subproject commit ecc3415e3e3c13fa8f73fdd51a88c1ab7087b199 +Subproject commit c726e76dad56cc63caa6e8cf894da72c5b4d108f diff --git a/res/values/strings.xml b/res/values/strings.xml index 8f1aec21..4d720322 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -81,7 +81,7 @@ Created: Modified: Download - Refresh file + Synchronize File was renamed to %1$s during upload List Layout Share link diff --git a/src/com/owncloud/android/files/FileMenuFilter.java b/src/com/owncloud/android/files/FileMenuFilter.java index f7fee626..48027008 100644 --- a/src/com/owncloud/android/files/FileMenuFilter.java +++ b/src/com/owncloud/android/files/FileMenuFilter.java @@ -176,7 +176,7 @@ public class FileMenuFilter { } // SYNC FILE CONTENTS - if (mFile == null || mFile.isFolder() || !mFile.isDown() || downloading || uploading) { + if (mFile == null || (!mFile.isFolder() && !mFile.isDown()) || downloading || uploading) { toHide.add(R.id.action_sync_file); } else { toShow.add(R.id.action_sync_file); diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index 22370289..766f5795 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@ -205,9 +205,15 @@ public class FileOperationsHelper { } } - - public void syncFile(OCFile file) { - + /** + * Request the synchronization of a file or folder with the OC server, including its contents. + * + * @param file The file or folder to synchronize + * @param twoWays TMP parameter: when 'false', only download is tried; valid for folders only, single files + * are always synchronized in both ways. + */ + public void syncFile(OCFile file, boolean twoWays) { + if (!file.isFolder()){ Intent intent = new Intent(mFileActivity, OperationsService.class); intent.setAction(OperationsService.ACTION_SYNC_FILE); @@ -217,12 +223,20 @@ public class FileOperationsHelper { mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(intent); mFileActivity.showLoadingDialog(); + } else if (twoWays){ + Intent intent = new Intent(mFileActivity, OperationsService.class); + intent.setAction(OperationsService.ACTION_SYNC_FOLDER); + intent.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); + intent.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); + mFileActivity.startService(intent); + } else { Intent intent = new Intent(mFileActivity, OperationsService.class); intent.setAction(OperationsService.ACTION_SYNC_FOLDER); intent.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); intent.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); mFileActivity.startService(intent); + } } @@ -240,7 +254,7 @@ public class FileOperationsHelper { /// immediate content synchronization if (file.isFavorite()) { - syncFile(file); + syncFile(file, true); } } diff --git a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java index 78b6a7ba..75e193af 100644 --- a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -99,7 +99,7 @@ public class SynchronizeFolderOperation extends SyncOperation { private List mFilesToSyncContentsWithoutUpload; // this will go out when 'folder synchronization' replaces 'folder download'; step by step - private List mFavouriteFilesToSyncContents; + private List mFilesToSyncContents; // this will be used for every file when 'folder synchronization' replaces 'folder download' private final AtomicBoolean mCancellationRequested; @@ -121,7 +121,7 @@ public class SynchronizeFolderOperation extends SyncOperation { mRemoteFolderChanged = false; mFilesForDirectDownload = new Vector(); mFilesToSyncContentsWithoutUpload = new Vector(); - mFavouriteFilesToSyncContents = new Vector(); + mFilesToSyncContents = new Vector(); mCancellationRequested = new AtomicBoolean(false); } @@ -291,7 +291,7 @@ public class SynchronizeFolderOperation extends SyncOperation { List updatedFiles = new Vector(folderAndFiles.size() - 1); mFilesForDirectDownload.clear(); mFilesToSyncContentsWithoutUpload.clear(); - mFavouriteFilesToSyncContents.clear(); + mFilesToSyncContents.clear(); if (mCancellationRequested.get()) { throw new OperationCancelledException(); @@ -353,14 +353,15 @@ public class SynchronizeFolderOperation extends SyncOperation { /// classify file to sync/download contents later if (remoteFile.isFolder()) { /// to download children files recursively - synchronized(mCancellationRequested) { + synchronized (mCancellationRequested) { if (mCancellationRequested.get()) { throw new OperationCancelledException(); } startSyncFolderOperation(remoteFile.getRemotePath()); } - } else if (remoteFile.isFavorite()) { + //} else if (remoteFile.isFavorite()) { + } else { /// prepare content synchronization for kept-in-sync files SynchronizeFileOperation operation = new SynchronizeFileOperation( localFile, @@ -369,9 +370,9 @@ public class SynchronizeFolderOperation extends SyncOperation { true, mContext ); - mFavouriteFilesToSyncContents.add(operation); + mFilesToSyncContents.add(operation); - } else { + /*} else { /// prepare limited synchronization for regular files SynchronizeFileOperation operation = new SynchronizeFileOperation( localFile, @@ -381,7 +382,7 @@ public class SynchronizeFolderOperation extends SyncOperation { false, mContext ); - mFilesToSyncContentsWithoutUpload.add(operation); + mFilesToSyncContentsWithoutUpload.add(operation);*/ } updatedFiles.add(remoteFile); @@ -411,7 +412,20 @@ public class SynchronizeFolderOperation extends SyncOperation { /// prepare limited synchronization for regular files if (!child.isDown()) { mFilesForDirectDownload.add(child); + + } else { + /// this should result in direct upload of files that were locally modified + SynchronizeFileOperation operation = new SynchronizeFileOperation( + child, + child, // cheating with the remote file to get an upadte to server; to refactor + mAccount, + true, + mContext + ); + mFilesToSyncContents.add(operation); + } + } } } @@ -420,7 +434,7 @@ public class SynchronizeFolderOperation extends SyncOperation { private void syncContents(OwnCloudClient client) throws OperationCancelledException { startDirectDownloads(); startContentSynchronizations(mFilesToSyncContentsWithoutUpload, client); - startContentSynchronizations(mFavouriteFilesToSyncContents, client); + startContentSynchronizations(mFilesToSyncContents, client); } diff --git a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java index d4b1ffdd..bf8d7989 100644 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -252,7 +252,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener } case R.id.action_download_file: case R.id.action_sync_file: { - mContainerActivity.getFileOperationsHelper().syncFile(getFile()); + mContainerActivity.getFileOperationsHelper().syncFile(getFile(), true); return true; } case R.id.action_send_file: { @@ -297,7 +297,6 @@ public class FileDetailFragment extends FileFragment implements OnClickListener } } - /** * Check if the fragment was created with an empty layout. An empty fragment can't show file details, must be replaced. * diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index 02bd845d..e98f9e1c 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -363,9 +363,12 @@ public class OCFileListFragment extends ExtendedListFragment implements FileActi dialog.show(getFragmentManager(), ConfirmationDialogFragment.FTAG_CONFIRMATION); return true; } - case R.id.action_download_file: + case R.id.action_download_file: { + mContainerActivity.getFileOperationsHelper().syncFile(mTargetFile, false); + return true; + } case R.id.action_sync_file: { - mContainerActivity.getFileOperationsHelper().syncFile(mTargetFile); + mContainerActivity.getFileOperationsHelper().syncFile(mTargetFile, true); return true; } case R.id.action_cancel_download: diff --git a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java index b6f36823..0cf09226 100644 --- a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java @@ -311,7 +311,7 @@ public class PreviewImageFragment extends FileFragment { return true; } case R.id.action_sync_file: { - mContainerActivity.getFileOperationsHelper().syncFile(getFile()); + mContainerActivity.getFileOperationsHelper().syncFile(getFile(), true); return true; } case R.id.action_favorite_file:{ diff --git a/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java b/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java index 0dbb1a32..cc0f064f 100644 --- a/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java @@ -378,7 +378,7 @@ public class PreviewMediaFragment extends FileFragment implements return true; } case R.id.action_sync_file: { - mContainerActivity.getFileOperationsHelper().syncFile(getFile()); + mContainerActivity.getFileOperationsHelper().syncFile(getFile(), true); return true; } case R.id.action_favorite_file:{ diff --git a/src/com/owncloud/android/ui/preview/PreviewTextFragment.java b/src/com/owncloud/android/ui/preview/PreviewTextFragment.java index 6595bf72..82c2eee7 100644 --- a/src/com/owncloud/android/ui/preview/PreviewTextFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewTextFragment.java @@ -324,7 +324,7 @@ public class PreviewTextFragment extends FileFragment { return true; } case R.id.action_sync_file: { - mContainerActivity.getFileOperationsHelper().syncFile(getFile()); + mContainerActivity.getFileOperationsHelper().syncFile(getFile(), true); return true; }