Skip to content

Commit

Permalink
Merge pull request #3704 from owncloud/new_arch/sync_file
Browse files Browse the repository at this point in the history
[New arch] Sync file
  • Loading branch information
abelgardep authored Jul 7, 2022
2 parents a078c95 + 22192f2 commit b401004
Show file tree
Hide file tree
Showing 59 changed files with 641 additions and 397 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.owncloud.android.db.UploadResult;
import com.owncloud.android.domain.camerauploads.model.UploadBehavior;
import com.owncloud.android.domain.files.model.OCFile;
import com.owncloud.android.usecases.UploadEnqueuedBy;
import com.owncloud.android.usecases.transfers.uploads.UploadEnqueuedBy;
import com.owncloud.android.utils.MimetypeIconUtil;
import timber.log.Timber;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ val remoteDataSourceModule = module {

factory<RemoteAuthenticationDataSource> { OCRemoteAuthenticationDataSource(get()) }
factory<RemoteCapabilitiesDataSource> { OCRemoteCapabilitiesDataSource(get(), get()) }
factory<RemoteFileDataSource> { OCRemoteFileDataSource(get(), get()) }
factory<RemoteFileDataSource> { OCRemoteFileDataSource(get()) }
factory<RemoteOAuthDataSource> { RemoteOAuthDataSourceImpl(get(), get()) }
factory<RemoteServerInfoDataSource> { OCRemoteServerInfoDataSource(get(), get()) }
factory<RemoteShareDataSource> { OCRemoteShareDataSource(get(), get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ import com.owncloud.android.domain.user.usecases.GetStoredQuotaUseCase
import com.owncloud.android.domain.user.usecases.GetUserAvatarAsyncUseCase
import com.owncloud.android.domain.user.usecases.GetUserInfoAsyncUseCase
import com.owncloud.android.domain.user.usecases.RefreshUserQuotaFromServerAsyncUseCase
import com.owncloud.android.usecases.CancelUploadForFileUseCase
import com.owncloud.android.usecases.UploadFilesFromSAFUseCase
import com.owncloud.android.usecases.UploadFilesFromSystemUseCase
import com.owncloud.android.usecases.transfers.CancelDownloadForFileUseCase
import com.owncloud.android.usecases.transfers.CancelDownloadsForAccountUseCase
import com.owncloud.android.usecases.transfers.DownloadFileUseCase
import com.owncloud.android.usecases.transfers.GetLiveDataForDownloadingFileUseCase
import com.owncloud.android.usecases.transfers.GetLiveDataForFinishedDownloadsFromAccountUseCase
import com.owncloud.android.usecases.synchronization.SynchronizeFileUseCase
import com.owncloud.android.usecases.transfers.uploads.CancelUploadForFileUseCase
import com.owncloud.android.usecases.transfers.uploads.UploadFilesFromSAFUseCase
import com.owncloud.android.usecases.transfers.uploads.UploadFilesFromSystemUseCase
import com.owncloud.android.usecases.transfers.downloads.CancelDownloadForFileUseCase
import com.owncloud.android.usecases.transfers.downloads.CancelDownloadsForAccountUseCase
import com.owncloud.android.usecases.transfers.downloads.DownloadFileUseCase
import com.owncloud.android.usecases.transfers.downloads.GetLiveDataForDownloadingFileUseCase
import com.owncloud.android.usecases.transfers.downloads.GetLiveDataForFinishedDownloadsFromAccountUseCase
import com.owncloud.android.usecases.transfers.uploads.UploadFileInConflictUseCase
import org.koin.dsl.module

val useCaseModule = module {
Expand Down Expand Up @@ -109,6 +111,7 @@ val useCaseModule = module {
factory { GetFilesSharedByLinkUseCase(get()) }
factory { GetFilesAvailableOfflineUseCase(get()) }
factory { GetSearchFolderContentUseCase(get()) }
factory { SynchronizeFileUseCase(get(), get(), get(), get()) }
factory { SortFilesUseCase() }

// Sharing
Expand All @@ -130,6 +133,7 @@ val useCaseModule = module {
factory { GetLiveDataForFinishedDownloadsFromAccountUseCase(get()) }
factory { UploadFilesFromSAFUseCase(get()) }
factory { UploadFilesFromSystemUseCase(get()) }
factory { UploadFileInConflictUseCase(get()) }
factory { CancelUploadForFileUseCase(get()) }

// User
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
package com.owncloud.android.dependecyinjection

import com.owncloud.android.MainApp
import com.owncloud.android.presentation.ui.security.passcode.PasscodeAction
import com.owncloud.android.presentation.ui.files.filelist.MainFileListViewModel
import com.owncloud.android.presentation.ui.files.operations.FileOperationViewModel
import com.owncloud.android.presentation.ui.files.operations.FileOperationsViewModel
import com.owncloud.android.presentation.ui.security.passcode.PasscodeAction
import com.owncloud.android.presentation.viewmodels.authentication.OCAuthenticationViewModel
import com.owncloud.android.presentation.viewmodels.capabilities.OCCapabilityViewModel
import com.owncloud.android.presentation.viewmodels.drawer.DrawerViewModel
import com.owncloud.android.presentation.viewmodels.files.FileDetailsViewModel
import com.owncloud.android.presentation.viewmodels.files.FilesViewModel
import com.owncloud.android.presentation.viewmodels.logging.LogListViewModel
import com.owncloud.android.presentation.viewmodels.migration.MigrationViewModel
import com.owncloud.android.presentation.viewmodels.oauth.OAuthViewModel
import com.owncloud.android.presentation.viewmodels.releasenotes.ReleaseNotesViewModel
import com.owncloud.android.presentation.viewmodels.security.BiometricViewModel
import com.owncloud.android.presentation.viewmodels.security.PassCodeViewModel
import com.owncloud.android.presentation.viewmodels.security.PatternViewModel
Expand All @@ -46,7 +46,6 @@ import com.owncloud.android.presentation.viewmodels.settings.SettingsSecurityVie
import com.owncloud.android.presentation.viewmodels.settings.SettingsVideoUploadsViewModel
import com.owncloud.android.presentation.viewmodels.settings.SettingsViewModel
import com.owncloud.android.presentation.viewmodels.sharing.OCShareViewModel
import com.owncloud.android.presentation.viewmodels.releasenotes.ReleaseNotesViewModel
import com.owncloud.android.ui.dialog.RemoveAccountDialogViewModel
import com.owncloud.android.ui.preview.PreviewImageViewModel
import org.koin.androidx.viewmodel.dsl.viewModel
Expand Down Expand Up @@ -83,10 +82,9 @@ val viewModelModule = module {
viewModel { PatternViewModel(get()) }
viewModel { BiometricViewModel(get(), get()) }
viewModel { ReleaseNotesViewModel(get(), get()) }
viewModel { FilesViewModel(get(), get(), get()) }

viewModel { PreviewImageViewModel(get(), get(), get()) }
viewModel { FileDetailsViewModel(get(), get(), get(), get(), get()) }
viewModel { FileOperationViewModel(get(), get(), get(), get(), get(), get()) }
viewModel { MainFileListViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get()) }
viewModel { FileOperationsViewModel(get(), get(), get(), get(), get(), get(), get(), get()) }
viewModel { MainFileListViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.owncloud.android.R
import com.owncloud.android.domain.exceptions.AccountNotNewException
import com.owncloud.android.domain.exceptions.AccountNotTheSameException
import com.owncloud.android.domain.exceptions.BadOcVersionException
import com.owncloud.android.domain.exceptions.ConflictException
import com.owncloud.android.domain.exceptions.CopyIntoDescendantException
import com.owncloud.android.domain.exceptions.FileAlreadyExistsException
import com.owncloud.android.domain.exceptions.FileNotFoundException
Expand Down Expand Up @@ -63,6 +64,7 @@ fun Throwable.parseError(
is ServerConnectionTimeoutException -> resources.getString(R.string.network_error_connect_timeout_exception)
is ServerNotReachableException -> resources.getString(R.string.network_host_not_available)
is ServiceUnavailableException -> resources.getString(R.string.service_unavailable)
is ConflictException -> resources.getString(R.string.conflict_title)
is SSLRecoverablePeerUnverifiedException -> resources.getString(R.string.ssl_certificate_not_trusted)
is BadOcVersionException -> resources.getString(R.string.auth_bad_oc_version_title)
is IncorrectAddressException -> resources.getString(R.string.auth_incorrect_address_title)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import com.owncloud.android.lib.resources.files.ReadRemoteFileOperation;
import com.owncloud.android.lib.resources.files.RemoteFile;
import com.owncloud.android.operations.common.SyncOperation;
import com.owncloud.android.usecases.UploadFileInConflictUseCase;
import com.owncloud.android.usecases.transfers.DownloadFileUseCase;
import com.owncloud.android.usecases.transfers.uploads.UploadFileInConflictUseCase;
import com.owncloud.android.usecases.transfers.downloads.DownloadFileUseCase;
import com.owncloud.android.utils.FileStorageUtils;
import kotlin.Lazy;
import org.jetbrains.annotations.NotNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCUpload;
import com.owncloud.android.datamodel.UploadsStorageManager;
import com.owncloud.android.domain.UseCaseResult;
import com.owncloud.android.domain.files.model.OCFile;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.OperationCancelledException;
Expand All @@ -40,11 +41,14 @@
import com.owncloud.android.lib.resources.files.RemoteFile;
import com.owncloud.android.lib.resources.files.services.implementation.OCFileService;
import com.owncloud.android.operations.common.SyncOperation;
import com.owncloud.android.presentation.ui.files.filelist.MainFileListViewModel;
import com.owncloud.android.presentation.ui.files.operations.FileOperation;
import com.owncloud.android.presentation.ui.files.operations.FileOperationViewModel;
import com.owncloud.android.presentation.viewmodels.files.FilesViewModel;
import com.owncloud.android.presentation.ui.files.operations.FileOperationsViewModel;
import com.owncloud.android.services.OperationsService;
import com.owncloud.android.usecases.synchronization.SynchronizeFileUseCase;
import com.owncloud.android.utils.FileStorageUtils;
import kotlin.Lazy;
import org.jetbrains.annotations.NotNull;
import timber.log.Timber;

import java.io.File;
Expand All @@ -56,6 +60,7 @@
import java.util.concurrent.atomic.AtomicBoolean;

import static org.koin.java.KoinJavaComponent.get;
import static org.koin.java.KoinJavaComponent.inject;

/**
* Operation performing the synchronization of the list of files contained
Expand Down Expand Up @@ -108,7 +113,7 @@ public class SynchronizeFolderOperation extends SyncOperation<ArrayList<RemoteFi
*/
private int mFailsInFileSyncsFound;

private List<SynchronizeFileOperation> mFilesToSyncContents;
private List<Pair<OCFile, Account>> mFilesToSyncContents;

private List<Intent> mFoldersToSyncContents;

Expand Down Expand Up @@ -200,8 +205,8 @@ public List<Pair<OCFile, Boolean>> getFoldersToVisit() {
protected RemoteOperationResult<ArrayList<RemoteFile>> run(OwnCloudClient client) {
final RemoteOperationResult<ArrayList<RemoteFile>> fetchFolderResult;

FilesViewModel filesViewModel = get(FilesViewModel.class);
filesViewModel.refreshFolder(mRemotePath);
MainFileListViewModel mainFileListViewModel = get(MainFileListViewModel.class);
mainFileListViewModel.refreshFolder(mRemotePath);

mFailsInFileSyncsFound = 0;
mConflictsFound = 0;
Expand Down Expand Up @@ -277,11 +282,11 @@ private boolean folderChanged(RemoteFile remoteFolder) {
}

private void removeLocalFolder() {
FileOperationViewModel fileOperationViewModel = get(FileOperationViewModel.class);
FileOperationsViewModel fileOperationsViewModel = get(FileOperationsViewModel.class);
ArrayList<OCFile> list = new ArrayList<>();
list.add(mLocalFolder);
FileOperation.RemoveOperation removeOperation = new FileOperation.RemoveOperation(list, false);
fileOperationViewModel.performOperation(removeOperation);
fileOperationsViewModel.performOperation(removeOperation);
}

/**
Expand Down Expand Up @@ -443,15 +448,7 @@ private boolean addToSyncContents(OCFile localFile, OCFile remoteFile) {

if (shouldSyncContents && !isBlockedForAutomatedSync(localFile)) {
/// synchronization for files
SynchronizeFileOperation operation = new SynchronizeFileOperation(
localFile,
remoteFile,
mAccount,
serverUnchanged,
mContext,
false
);
mFilesToSyncContents.add(operation);
mFilesToSyncContents.add(new Pair<>(localFile, mAccount));
}
}

Expand All @@ -466,24 +463,25 @@ private boolean addToSyncContents(OCFile localFile, OCFile remoteFile) {
* on.
*/
private void syncContents() throws OperationCancelledException {
@NotNull Lazy<SynchronizeFileUseCase> synchronizeFileUseCase = inject(SynchronizeFileUseCase.class);

Timber.v("Starting content synchronization... ");
RemoteOperationResult contentsResult;
for (SyncOperation op : mFilesToSyncContents) {
for (Pair<OCFile, Account> fileAndAccountPair : mFilesToSyncContents) {
if (mCancellationRequested.get()) {
throw new OperationCancelledException();
}
contentsResult = op.execute(getStorageManager(), mContext);
if (!contentsResult.isSuccess()) {
if (contentsResult.getCode() == ResultCode.SYNC_CONFLICT) {
SynchronizeFileUseCase.Params synchronizeFileUseCaseParams = new SynchronizeFileUseCase.Params(fileAndAccountPair.first,
fileAndAccountPair.second);
UseCaseResult<SynchronizeFileUseCase.SyncType> result = synchronizeFileUseCase.getValue().execute(synchronizeFileUseCaseParams);
if (!result.isSuccess()) {
if (result.getDataOrNull() instanceof SynchronizeFileUseCase.SyncType.ConflictDetected) {
mConflictsFound++;
} else {
mFailsInFileSyncsFound++;
if (contentsResult.getException() != null) {
Timber.e(contentsResult.getException(), "Error while synchronizing file : %s",
contentsResult.getLogMessage());
if (result.getThrowableOrNull() != null) {
Timber.e(result.getThrowableOrNull(), "Error while synchronizing file : %s", fileAndAccountPair.first);
} else {
Timber.e("Error while synchronizing file : %s", contentsResult.getLogMessage());
Timber.e("Error while synchronizing file : %s", fileAndAccountPair.first);
}
}
} // won't let these fails break the synchronization process
Expand Down
Loading

0 comments on commit b401004

Please sign in to comment.