Skip to content

Commit

Permalink
feat: new parameter isActionSetFolderAvailableOffline in SynchronizeF…
Browse files Browse the repository at this point in the history
…olderUseCase to added to the condition to syncs the content folder
  • Loading branch information
Aitorbp committed May 13, 2024
1 parent e8f1261 commit 35ce6ba
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,13 @@ class MainFileListFragment : Fragment(),
FileMenuOption.SET_AV_OFFLINE -> {
fileOperationsViewModel.performOperation(FileOperation.SetFilesAsAvailableOffline(listOf(file)))
if (file.isFolder) {
fileOperationsViewModel.performOperation(FileOperation.SynchronizeFolderOperation(file, file.owner))
fileOperationsViewModel.performOperation(
FileOperation.SynchronizeFolderOperation(
folderToSync = file,
accountName = file.owner,
isActionSetFolderAvailableOffline = true,
)
)
} else {
fileOperationsViewModel.performOperation(FileOperation.SynchronizeFileOperation(file, file.owner))
}
Expand Down Expand Up @@ -1129,7 +1135,13 @@ class MainFileListFragment : Fragment(),
R.id.action_set_available_offline -> {
fileOperationsViewModel.performOperation(FileOperation.SetFilesAsAvailableOffline(listOf(singleFile)))
if (singleFile.isFolder) {
fileOperationsViewModel.performOperation(FileOperation.SynchronizeFolderOperation(singleFile, singleFile.owner))
fileOperationsViewModel.performOperation(
FileOperation.SynchronizeFolderOperation(
folderToSync = singleFile,
accountName = singleFile.owner,
isActionSetFolderAvailableOffline = true,
)
)
} else {
fileOperationsViewModel.performOperation(FileOperation.SynchronizeFileOperation(singleFile, singleFile.owner))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
*
* @author Abel García de Prada
* @author Juan Carlos Garrote Gascón
* @author Aitor Ballesteros Pavón
*
* Copyright (C) 2023 ownCloud GmbH.
* Copyright (C) 2024 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
Expand Down Expand Up @@ -44,7 +45,7 @@ sealed interface FileOperation {
data class RemoveOperation(val listOfFilesToRemove: List<OCFile>, val removeOnlyLocalCopy: Boolean) : FileOperation
data class RenameOperation(val ocFileToRename: OCFile, val newName: String) : FileOperation
data class SynchronizeFileOperation(val fileToSync: OCFile, val accountName: String) : FileOperation
data class SynchronizeFolderOperation(val folderToSync: OCFile, val accountName: String) : FileOperation
data class SynchronizeFolderOperation(val folderToSync: OCFile, val accountName: String, val isActionSetFolderAvailableOffline: Boolean = false) : FileOperation
data class RefreshFolderOperation(val folderToRefresh: OCFile, val shouldSyncContents: Boolean) : FileOperation
data class CreateFileWithAppProviderOperation(val accountName: String, val parentContainerId: String, val filename: String) : FileOperation
data class SetFilesAsAvailableOffline(val filesToUpdate: List<OCFile>) : FileOperation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
*
* @author Abel García de Prada
* @author Juan Carlos Garrote Gascón
* @author Aitor Ballesteros Pavón
*
* Copyright (C) 2023 ownCloud GmbH.
* Copyright (C) 2024 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
Expand Down Expand Up @@ -258,7 +259,8 @@ class FileOperationsViewModel(
remotePath = fileOperation.folderToSync.remotePath,
accountName = fileOperation.folderToSync.owner,
spaceId = fileOperation.folderToSync.spaceId,
syncMode = SynchronizeFolderUseCase.SyncFolderMode.SYNC_FOLDER_RECURSIVELY
syncMode = SynchronizeFolderUseCase.SyncFolderMode.SYNC_FOLDER_RECURSIVELY,
isActionSetFolderAvailableOffline = fileOperation.isActionSetFolderAvailableOffline,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
* @author Bartek Przybylski
* @author David A. Velasco
* @author David González Verdugo
* Copyright (C) 2011 Bartek Przybylski
* Copyright (C) 2020 ownCloud GmbH.
* @author Aitor Ballesteros Pavón
*
* Copyright (C) 2024 ownCloud GmbH.
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
Expand Down Expand Up @@ -231,7 +232,8 @@ private void synchronizeFolder(OCFile folder) {
folder.getRemotePath(),
folder.getOwner(),
folder.getSpaceId(),
SynchronizeFolderUseCase.SyncFolderMode.REFRESH_FOLDER_RECURSIVELY);
SynchronizeFolderUseCase.SyncFolderMode.REFRESH_FOLDER_RECURSIVELY,
false);
UseCaseResult<Unit> useCaseResult;

useCaseResult = synchronizeFolderUseCase.getValue().invoke(params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
* @author David González Verdugo
* @author Shashvat Kedia
* @author David Crespo Rios
* Copyright (C) 2022 ownCloud GmbH.
* @author Aitor Ballesteros Pavón
*
* Copyright (C) 2024 ownCloud GmbH.
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
Expand Down Expand Up @@ -196,7 +198,8 @@ public void syncFile(OCFile file) {
file.getRemotePath(),
file.getOwner(),
file.getSpaceId(),
SynchronizeFolderUseCase.SyncFolderMode.SYNC_FOLDER_RECURSIVELY)
SynchronizeFolderUseCase.SyncFolderMode.SYNC_FOLDER_RECURSIVELY,
false)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* ownCloud Android client application
*
* @author Abel García de Prada
* @author Aitor Ballesteros Pavón
*
* Copyright (C) 2022 ownCloud GmbH.
* Copyright (C) 2024 ownCloud GmbH.
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
Expand Down Expand Up @@ -39,7 +40,8 @@ class SynchronizeFolderUseCase(
val folderContent = fileRepository.refreshFolder(
remotePath = remotePath,
accountName = accountName,
spaceId = params.spaceId
spaceId = params.spaceId,
isActionSetFolderAvailableOffline = params.isActionSetFolderAvailableOffline,
)

folderContent.forEach { ocFile ->
Expand Down Expand Up @@ -75,6 +77,7 @@ class SynchronizeFolderUseCase(
val accountName: String,
val spaceId: String? = null,
val syncMode: SyncFolderMode,
val isActionSetFolderAvailableOffline: Boolean = false,
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ class OCFileRepository(
remotePath: String,
accountName: String,
spaceId: String?,
isActionSetFolderAvailableOffline: Boolean,
): List<OCFile> {
val spaceWebDavUrl = localSpacesDataSource.getWebDavUrlForSpace(spaceId, accountName)

Expand Down Expand Up @@ -424,7 +425,10 @@ class OCFileRepository(
if (remoteFolder.isAvailableOffline) AVAILABLE_OFFLINE_PARENT else NOT_AVAILABLE_OFFLINE

})
} else if (localChildToSync.etag != remoteChild.etag || localChildToSync.localModificationTimestamp > remoteChild.lastSyncDateForData!!) {
} else if (localChildToSync.etag != remoteChild.etag ||
localChildToSync.localModificationTimestamp > remoteChild.lastSyncDateForData!! ||
isActionSetFolderAvailableOffline
) {
// File exists in the database, we need to check several stuff.
folderContentUpdated.add(
remoteChild.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ interface FileRepository {
// Returns files in conflict
fun moveFile(listOfFilesToMove: List<OCFile>, targetFolder: OCFile, replace: List<Boolean?> = emptyList(), isUserLogged: Boolean): List<OCFile>
fun readFile(remotePath: String, accountName: String, spaceId: String? = null): OCFile
fun refreshFolder(remotePath: String, accountName: String, spaceId: String? = null): List<OCFile>
fun refreshFolder(remotePath: String, accountName: String, spaceId: String? = null, isActionSetFolderAvailableOffline: Boolean = false): List<OCFile>
fun deleteFiles(listOfFilesToDelete: List<OCFile>, removeOnlyLocalCopy: Boolean)
fun renameFile(ocFile: OCFile, newName: String)
fun saveFile(file: OCFile)
Expand Down

0 comments on commit 35ce6ba

Please sign in to comment.