Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ import eu.opencloud.android.presentation.documentsprovider.cursors.SpaceCursor
import eu.opencloud.android.presentation.settings.security.SettingsSecurityFragment.Companion.PREFERENCE_LOCK_ACCESS_FROM_DOCUMENT_PROVIDER
import eu.opencloud.android.usecases.synchronization.SynchronizeFileUseCase
import eu.opencloud.android.usecases.synchronization.SynchronizeFolderUseCase
import eu.opencloud.android.usecases.transfers.downloads.DownloadFileUseCase
import eu.opencloud.android.usecases.transfers.uploads.UploadFilesFromSystemUseCase
import eu.opencloud.android.utils.FileStorageUtils
import eu.opencloud.android.utils.NotificationUtils
Expand Down Expand Up @@ -107,11 +106,8 @@ class DocumentsStorageProvider : DocumentsProvider() {
if (!uploadOnly) {
ocFile = getFileByIdOrException(documentId.toInt())

if (!ocFile.isAvailableLocally) {
val downloadFileUseCase: DownloadFileUseCase by inject()

downloadFileUseCase(DownloadFileUseCase.Params(accountName = ocFile.owner, file = ocFile))

if (!ocFile.isAvailableLocally || !isWrite) {
syncFileWithServer(ocFile)
do {
if (!waitOrGetCancelled(signal)) {
return null
Expand Down Expand Up @@ -150,23 +146,7 @@ class DocumentsStorageProvider : DocumentsProvider() {
uploadFilesUseCase(uploadFilesUseCaseParams)
}
} else {
Thread {
val synchronizeFileUseCase: SynchronizeFileUseCase by inject()
val result = synchronizeFileUseCase(
SynchronizeFileUseCase.Params(
fileToSynchronize = ocFile,
)
)
Timber.d("Synced ${ocFile.remotePath} from ${ocFile.owner} with result: $result")
if (result.getDataOrNull() is SynchronizeFileUseCase.SyncType.ConflictDetected) {
context?.let {
NotificationUtils.notifyConflict(
fileInConflict = ocFile,
context = it
)
}
}
}.start()
syncFileWithServer(ocFile)
}
}
} catch (e: IOException) {
Expand Down Expand Up @@ -488,6 +468,28 @@ class DocumentsStorageProvider : DocumentsProvider() {
return NONEXISTENT_DOCUMENT_ID
}

private fun syncFileWithServer(fileToSync: OCFile) {
Timber.d("Trying to sync a file ${fileToSync.id} with server")

val synchronizeFileUseCase : SynchronizeFileUseCase by inject()
val synchronizeFileUseCaseParam = SynchronizeFileUseCase.Params(
fileToSynchronize = fileToSync
)
CoroutineScope(Dispatchers.IO).launch {
val useCaseResult = synchronizeFileUseCase(synchronizeFileUseCaseParam)
Timber.d("${fileToSync.remotePath} from ${fileToSync.owner} was synced with server with result: $useCaseResult")

if (useCaseResult.getDataOrNull() is SynchronizeFileUseCase.SyncType.ConflictDetected) {
context?.let {
NotificationUtils.notifyConflict(
fileInConflict = fileToSync,
context = it
)
}
}
}
}

private fun syncDirectoryWithServer(parentDocumentId: String) {
Timber.d("Trying to sync $parentDocumentId with server")
val folderToSync = getFileByIdOrException(parentDocumentId.toInt())
Expand Down