Skip to content

Commit

Permalink
QA corrections - Added default parameter lastUsage to null in OCFileR…
Browse files Browse the repository at this point in the history
…epository and added lastUsage functionality to preview file
  • Loading branch information
Aitorbp committed Nov 2, 2023
1 parent 6fd3e6c commit ae6a009
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,7 @@ class MainFileListFragment : Fragment(),
if (ocFile.isFolder) {
mainFileListViewModel.updateFolderToDisplay(ocFile)
} else { // Click on a file
fileOperationsViewModel.setLastUsageFile(ocFile)
fileActions?.onFileClicked(ocFile)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!!)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,17 @@ import com.owncloud.android.domain.files.model.OCFile

class RemoveFileUseCase(
private val fileRepository: FileRepository,
private val setLastUsageFileUseCase: SetLastUsageFileUseCase,
) : BaseUseCaseWithResult<Unit, RemoveFileUseCase.Params>() {

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(
Expand Down

0 comments on commit ae6a009

Please sign in to comment.