diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/filelist/MainFileListFragment.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/filelist/MainFileListFragment.kt index aa996518464..4cb811fff0e 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/filelist/MainFileListFragment.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/filelist/MainFileListFragment.kt @@ -1133,6 +1133,7 @@ class MainFileListFragment : Fragment(), if (ocFile.isFolder) { mainFileListViewModel.updateFolderToDisplay(ocFile) } else { // Click on a file + fileOperationsViewModel.setLastUsageFile(ocFile) fileActions?.onFileClicked(ocFile) } } diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/operations/FileOperationsViewModel.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/operations/FileOperationsViewModel.kt index 835db8c9b77..caff13fac84 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/operations/FileOperationsViewModel.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/operations/FileOperationsViewModel.kt @@ -40,6 +40,7 @@ import com.owncloud.android.domain.files.usecases.ManageDeepLinkUseCase import com.owncloud.android.domain.files.usecases.MoveFileUseCase import com.owncloud.android.domain.files.usecases.RemoveFileUseCase import com.owncloud.android.domain.files.usecases.RenameFileUseCase +import com.owncloud.android.domain.files.usecases.SetLastUsageFileUseCase import com.owncloud.android.domain.utils.Event import com.owncloud.android.extensions.ViewModelExt.runUseCaseWithResult import com.owncloud.android.presentation.common.UIResult @@ -66,6 +67,7 @@ class FileOperationsViewModel( private val setFilesAsAvailableOfflineUseCase: SetFilesAsAvailableOfflineUseCase, private val unsetFilesAsAvailableOfflineUseCase: UnsetFilesAsAvailableOfflineUseCase, private val manageDeepLinkUseCase: ManageDeepLinkUseCase, + private val setLastUsageFileUseCase: SetLastUsageFileUseCase, private val contextProvider: ContextProvider, private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider, ) : ViewModel() { @@ -121,6 +123,20 @@ class FileOperationsViewModel( } } + fun setLastUsageFile(file: OCFile) { + viewModelScope.launch(coroutinesDispatcherProvider.io) { + setLastUsageFileUseCase( + SetLastUsageFileUseCase.Params( + fileId = file.id, + lastUsage = System.currentTimeMillis(), + isAvailableLocally = file.isAvailableLocally, + isFolder = file.isFolder, + ) + ) + } + } + + private fun createFolderOperation(fileOperation: FileOperation.CreateFolder) { runOperation( liveData = _createFolder, diff --git a/owncloudData/src/main/java/com/owncloud/android/data/files/repository/OCFileRepository.kt b/owncloudData/src/main/java/com/owncloud/android/data/files/repository/OCFileRepository.kt index 37ce33b3c5b..96f2225a2b2 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/files/repository/OCFileRepository.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/files/repository/OCFileRepository.kt @@ -564,7 +564,7 @@ class OCFileRepository( private fun deleteLocalFile(ocFile: OCFile, onlyFromLocalStorage: Boolean) { localStorageProvider.deleteLocalFile(ocFile) if (onlyFromLocalStorage) { - localFileDataSource.saveFile(ocFile.copy(storagePath = null, etagInConflict = null)) + localFileDataSource.saveFile(ocFile.copy(storagePath = null, etagInConflict = null, lastUsage = null)) } else { localFileDataSource.deleteFile(ocFile.id!!) } diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/RemoveFileUseCase.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/RemoveFileUseCase.kt index f431568a72b..d40b6560708 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/RemoveFileUseCase.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/RemoveFileUseCase.kt @@ -26,37 +26,17 @@ import com.owncloud.android.domain.files.model.OCFile class RemoveFileUseCase( private val fileRepository: FileRepository, - private val setLastUsageFileUseCase: SetLastUsageFileUseCase, ) : BaseUseCaseWithResult() { override fun run(params: Params) { require(params.listOfFilesToDelete.isNotEmpty()) - val listOfFilesToDeleteOriginal = params.listOfFilesToDelete.map { it to it.isAvailableLocally } - - val deleteFiles = fileRepository.deleteFiles( + return fileRepository.deleteFiles( listOfFilesToDelete = params.listOfFilesToDelete, removeOnlyLocalCopy = params.removeOnlyLocalCopy, ) - if (params.removeOnlyLocalCopy) { - listOfFilesToDeleteOriginal.forEach { (ocFile, isAvailableLocally) -> - setLastUsageFile(ocFile, isAvailableLocally) - } - } - return deleteFiles - } - - private fun setLastUsageFile(file: OCFile, isAvailableLocally: Boolean) { - setLastUsageFileUseCase( - SetLastUsageFileUseCase.Params( - fileId = file.id, - lastUsage = null, - isAvailableLocally = isAvailableLocally, - isFolder = file.isFolder, - ) - ) } data class Params(