From 96077816eaa132970e5ef518701a085c9ba55e6c Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Sun, 15 Oct 2023 13:44:33 +0100 Subject: [PATCH 01/11] Created new usecase for setting the new LastUsage parameter in ddbb and migrated ddbb to 42 --- .../com/owncloud/android/db/ProviderMeta.java | 1 + .../dependecyinjection/UseCaseModule.kt | 2 + .../dependecyinjection/ViewModelModule.kt | 4 +- .../files/details/FileDetailsFragment.kt | 1 + .../files/details/FileDetailsViewModel.kt | 10 + .../android/providers/FileContentProvider.kt | 3 + .../android/workers/DownloadFileWorker.kt | 1 + .../workers/UploadFileFromFileSystemWorker.kt | 1 + .../42.json | 1080 +++++++++++++++++ .../owncloud/android/data/OwncloudDatabase.kt | 2 + .../owncloud/android/data/ProviderMeta.java | 3 +- .../files/datasources/LocalFileDataSource.kt | 1 + .../implementation/OCLocalFileDataSource.kt | 6 + .../owncloud/android/data/files/db/FileDao.kt | 11 + .../android/data/files/db/OCFileEntity.kt | 3 + .../data/files/repository/OCFileRepository.kt | 4 + .../android/data/migrations/Migration_42.kt | 35 + .../android/domain/files/FileRepository.kt | 2 +- .../android/domain/files/model/OCFile.kt | 2 + .../domain/files/usecases/MoveFileUseCase.kt | 21 +- .../files/usecases/RemoveFileUseCase.kt | 28 +- .../files/usecases/RenameFileUseCase.kt | 19 +- .../files/usecases/SetLastUsageFileUseCase.kt | 37 + 23 files changed, 1264 insertions(+), 13 deletions(-) create mode 100644 owncloudData/schemas/com.owncloud.android.data.OwncloudDatabase/42.json create mode 100644 owncloudData/src/main/java/com/owncloud/android/data/migrations/Migration_42.kt create mode 100644 owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/SetLastUsageFileUseCase.kt diff --git a/owncloudApp/src/main/java/com/owncloud/android/db/ProviderMeta.java b/owncloudApp/src/main/java/com/owncloud/android/db/ProviderMeta.java index 017956186e7..b18c0eecf8e 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/db/ProviderMeta.java +++ b/owncloudApp/src/main/java/com/owncloud/android/db/ProviderMeta.java @@ -82,6 +82,7 @@ static public class ProviderTableMeta implements BaseColumns { public static final String FILE_ACCOUNT_OWNER = "file_owner"; public static final String FILE_LAST_SYNC_DATE = "last_sync_date";// _for_properties, but let's keep it as it is public static final String FILE_LAST_SYNC_DATE_FOR_DATA = "last_sync_date_for_data"; + public static final String FILE_LAST_USAGE = "last_usage"; public static final String FILE_KEEP_IN_SYNC = "keep_in_sync"; public static final String FILE_ETAG = "etag"; public static final String FILE_TREE_ETAG = "tree_etag"; diff --git a/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/UseCaseModule.kt b/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/UseCaseModule.kt index 91a43cb81a5..6cc9b553fb7 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/UseCaseModule.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/UseCaseModule.kt @@ -75,6 +75,7 @@ import com.owncloud.android.domain.files.usecases.SaveFileOrFolderUseCase import com.owncloud.android.domain.files.usecases.SortFilesUseCase import com.owncloud.android.domain.files.usecases.SortFilesWithSyncInfoUseCase import com.owncloud.android.domain.files.usecases.UpdateAlreadyDownloadedFilesPathUseCase +import com.owncloud.android.domain.files.usecases.SetLastUsageFileUseCase import com.owncloud.android.domain.server.usecases.GetServerInfoAsyncUseCase import com.owncloud.android.domain.sharing.sharees.GetShareesAsyncUseCase import com.owncloud.android.domain.sharing.shares.usecases.CreatePrivateShareAsyncUseCase @@ -178,6 +179,7 @@ val useCaseModule = module { factoryOf(::SynchronizeFileUseCase) factoryOf(::SynchronizeFolderUseCase) factoryOf(::ManageDeepLinkUseCase) + factoryOf(::SetLastUsageFileUseCase) // Open in web factoryOf(::CreateFileWithAppProviderUseCase) diff --git a/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt b/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt index 945d3dfb614..31be44622dc 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt @@ -84,6 +84,7 @@ val viewModelModule = module { viewModelOf(::SettingsSecurityViewModel) viewModelOf(::SettingsVideoUploadsViewModel) viewModelOf(::SettingsViewModel) + viewModelOf(::FileOperationsViewModel) viewModel { (accountName: String) -> CapabilityViewModel(accountName, get(), get(), get()) } viewModel { (action: PasscodeAction) -> PassCodeViewModel(get(), get(), action) } @@ -95,8 +96,7 @@ val viewModelModule = module { } viewModel { (ocFile: OCFile) -> ConflictsResolveViewModel(get(), get(), get(), get(), get(), ocFile) } viewModel { AuthenticationViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) } - viewModel { FileDetailsViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) } - viewModelOf(::FileOperationsViewModel) + viewModel { FileDetailsViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) } viewModel { MigrationViewModel(MainApp.dataFolder, get(), get(), get(), get(), get(), get(), get()) } viewModel { TransfersViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) } viewModel { ReceiveExternalFilesViewModel(get(), get(), get()) } diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsFragment.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsFragment.kt index 26b65e0ff14..3535ffa52b4 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsFragment.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsFragment.kt @@ -543,6 +543,7 @@ class FileDetailsFragment : FileFragment() { else -> fileDisplayActivity.openOCFile(fileWaitingToPreview) } + fileDetailsViewModel.setLastUsageFile(fileWaitingToPreview, fileWaitingToPreview.isAvailableLocally) } override fun updateViewForSyncInProgress() { diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsViewModel.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsViewModel.kt index 66b71ff76f7..bd7223e7fb5 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsViewModel.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsViewModel.kt @@ -41,6 +41,7 @@ import com.owncloud.android.domain.files.model.FileMenuOption import com.owncloud.android.domain.files.model.OCFile import com.owncloud.android.domain.files.model.OCFileWithSyncInfo import com.owncloud.android.domain.files.usecases.GetFileWithSyncInfoByIdUseCase +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.extensions.getRunningWorkInfosByTags @@ -71,6 +72,7 @@ class FileDetailsViewModel( private val cancelUploadForFileUseCase: CancelUploadForFileUseCase, private val filterFileMenuOptionsUseCase: FilterFileMenuOptionsUseCase, getFileWithSyncInfoByIdUseCase: GetFileWithSyncInfoByIdUseCase, + private val setLastUsageFileUseCase: SetLastUsageFileUseCase, val contextProvider: ContextProvider, private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider, private val workManager: WorkManager, @@ -201,6 +203,14 @@ class FileDetailsViewModel( } } + fun setLastUsageFile(file: OCFile, isAvailableLocally: Boolean ){ + setLastUsageFileUseCase(SetLastUsageFileUseCase.Params( + fileId = file.id!!, + lastUsage = System.currentTimeMillis(), + isAvailableLocally = isAvailableLocally, + isFolder = file.isFolder)) + } + enum class ActionsInDetailsView { NONE, SYNC, SYNC_AND_OPEN, SYNC_AND_OPEN_WITH, SYNC_AND_SEND; diff --git a/owncloudApp/src/main/java/com/owncloud/android/providers/FileContentProvider.kt b/owncloudApp/src/main/java/com/owncloud/android/providers/FileContentProvider.kt index 4c9dcfc40ac..e6818a35b19 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/providers/FileContentProvider.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/providers/FileContentProvider.kt @@ -1116,6 +1116,7 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi ProviderTableMeta.FILE_LAST_SYNC_DATE + " INTEGER, " + ProviderTableMeta.FILE_KEEP_IN_SYNC + " INTEGER, " + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " INTEGER, " + + ProviderTableMeta.FILE_LAST_USAGE + " INTEGER, " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " INTEGER, " + ProviderTableMeta.FILE_ETAG + " TEXT, " + ProviderTableMeta.FILE_TREE_ETAG + " TEXT, " + @@ -1382,6 +1383,8 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi fileProjectionMap[ProviderTableMeta.FILE_LAST_SYNC_DATE] = ProviderTableMeta.FILE_LAST_SYNC_DATE fileProjectionMap[ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA] = ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + fileProjectionMap[ProviderTableMeta.FILE_LAST_USAGE] = + ProviderTableMeta.FILE_LAST_USAGE fileProjectionMap[ProviderTableMeta.FILE_KEEP_IN_SYNC] = ProviderTableMeta.FILE_KEEP_IN_SYNC fileProjectionMap[ProviderTableMeta.FILE_ETAG] = ProviderTableMeta.FILE_ETAG fileProjectionMap[ProviderTableMeta.FILE_TREE_ETAG] = ProviderTableMeta.FILE_TREE_ETAG diff --git a/owncloudApp/src/main/java/com/owncloud/android/workers/DownloadFileWorker.kt b/owncloudApp/src/main/java/com/owncloud/android/workers/DownloadFileWorker.kt index 6cacd43bae7..45146e026ef 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/workers/DownloadFileWorker.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/workers/DownloadFileWorker.kt @@ -218,6 +218,7 @@ class DownloadFileWorker( length = (File(finalLocationForFile).length()) lastSyncDateForData = currentTime modifiedAtLastSyncForData = downloadRemoteFileOperation.modificationTimestamp + lastUsage = currentTime } saveFileOrFolderUseCase(SaveFileOrFolderUseCase.Params(ocFile)) cleanConflictUseCase( diff --git a/owncloudApp/src/main/java/com/owncloud/android/workers/UploadFileFromFileSystemWorker.kt b/owncloudApp/src/main/java/com/owncloud/android/workers/UploadFileFromFileSystemWorker.kt index c0b4180ea24..d1e7d7b2d90 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/workers/UploadFileFromFileSystemWorker.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/workers/UploadFileFromFileSystemWorker.kt @@ -335,6 +335,7 @@ class UploadFileFromFileSystemWorker( length = (File(ocTransfer.localPath).length()), lastSyncDateForData = currentTime, modifiedAtLastSyncForData = currentTime, + lastUsage = currentTime ) } else { // Uploading a file should remove any conflicts on the file. diff --git a/owncloudData/schemas/com.owncloud.android.data.OwncloudDatabase/42.json b/owncloudData/schemas/com.owncloud.android.data.OwncloudDatabase/42.json new file mode 100644 index 00000000000..50a17054400 --- /dev/null +++ b/owncloudData/schemas/com.owncloud.android.data.OwncloudDatabase/42.json @@ -0,0 +1,1080 @@ +{ + "formatVersion": 1, + "database": { + "version": 42, + "identityHash": "54a3dafa0982f984143a796eba480037", + "entities": [ + { + "tableName": "app_registry", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`account_name` TEXT NOT NULL, `mime_type` TEXT NOT NULL, `ext` TEXT, `app_providers` TEXT NOT NULL, `name` TEXT, `icon` TEXT, `description` TEXT, `allow_creation` INTEGER, `default_application` TEXT, PRIMARY KEY(`account_name`, `mime_type`))", + "fields": [ + { + "fieldPath": "accountName", + "columnName": "account_name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "mimeType", + "columnName": "mime_type", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "ext", + "columnName": "ext", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "appProviders", + "columnName": "app_providers", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "icon", + "columnName": "icon", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "description", + "columnName": "description", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "allowCreation", + "columnName": "allow_creation", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "defaultApplication", + "columnName": "default_application", + "affinity": "TEXT", + "notNull": false + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "account_name", + "mime_type" + ] + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "folder_backup", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`accountName` TEXT NOT NULL, `behavior` TEXT NOT NULL, `sourcePath` TEXT NOT NULL, `uploadPath` TEXT NOT NULL, `wifiOnly` INTEGER NOT NULL, `chargingOnly` INTEGER NOT NULL, `name` TEXT NOT NULL, `lastSyncTimestamp` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)", + "fields": [ + { + "fieldPath": "accountName", + "columnName": "accountName", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "behavior", + "columnName": "behavior", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "sourcePath", + "columnName": "sourcePath", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "uploadPath", + "columnName": "uploadPath", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "wifiOnly", + "columnName": "wifiOnly", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "chargingOnly", + "columnName": "chargingOnly", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "lastSyncTimestamp", + "columnName": "lastSyncTimestamp", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": true, + "columnNames": [ + "id" + ] + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "capabilities", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`account` TEXT, `version_major` INTEGER NOT NULL, `version_minor` INTEGER NOT NULL, `version_micro` INTEGER NOT NULL, `version_string` TEXT, `version_edition` TEXT, `core_pollinterval` INTEGER NOT NULL, `dav_chunking_version` TEXT NOT NULL, `sharing_api_enabled` INTEGER NOT NULL DEFAULT -1, `sharing_public_enabled` INTEGER NOT NULL DEFAULT -1, `sharing_public_password_enforced` INTEGER NOT NULL DEFAULT -1, `sharing_public_password_enforced_read_only` INTEGER NOT NULL DEFAULT -1, `sharing_public_password_enforced_read_write` INTEGER NOT NULL DEFAULT -1, `sharing_public_password_enforced_public_only` INTEGER NOT NULL DEFAULT -1, `sharing_public_expire_date_enabled` INTEGER NOT NULL DEFAULT -1, `sharing_public_expire_date_days` INTEGER NOT NULL, `sharing_public_expire_date_enforced` INTEGER NOT NULL DEFAULT -1, `sharing_public_upload` INTEGER NOT NULL DEFAULT -1, `sharing_public_multiple` INTEGER NOT NULL DEFAULT -1, `supports_upload_only` INTEGER NOT NULL DEFAULT -1, `sharing_resharing` INTEGER NOT NULL DEFAULT -1, `sharing_federation_outgoing` INTEGER NOT NULL DEFAULT -1, `sharing_federation_incoming` INTEGER NOT NULL DEFAULT -1, `sharing_user_profile_picture` INTEGER NOT NULL DEFAULT -1, `files_bigfilechunking` INTEGER NOT NULL DEFAULT -1, `files_undelete` INTEGER NOT NULL DEFAULT -1, `files_versioning` INTEGER NOT NULL DEFAULT -1, `files_private_links` INTEGER NOT NULL DEFAULT -1, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `app_providers_enabled` INTEGER, `app_providers_version` TEXT, `app_providers_appsUrl` TEXT, `app_providers_openUrl` TEXT, `app_providers_openWebUrl` TEXT, `app_providers_newUrl` TEXT, `spaces_enabled` INTEGER, `spaces_projects` INTEGER, `spaces_shareJail` INTEGER)", + "fields": [ + { + "fieldPath": "accountName", + "columnName": "account", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "versionMajor", + "columnName": "version_major", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "versionMinor", + "columnName": "version_minor", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "versionMicro", + "columnName": "version_micro", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "versionString", + "columnName": "version_string", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "versionEdition", + "columnName": "version_edition", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "corePollInterval", + "columnName": "core_pollinterval", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "davChunkingVersion", + "columnName": "dav_chunking_version", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "filesSharingApiEnabled", + "columnName": "sharing_api_enabled", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "-1" + }, + { + "fieldPath": "filesSharingPublicEnabled", + "columnName": "sharing_public_enabled", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "-1" + }, + { + "fieldPath": "filesSharingPublicPasswordEnforced", + "columnName": "sharing_public_password_enforced", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "-1" + }, + { + "fieldPath": "filesSharingPublicPasswordEnforcedReadOnly", + "columnName": "sharing_public_password_enforced_read_only", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "-1" + }, + { + "fieldPath": "filesSharingPublicPasswordEnforcedReadWrite", + "columnName": "sharing_public_password_enforced_read_write", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "-1" + }, + { + "fieldPath": "filesSharingPublicPasswordEnforcedUploadOnly", + "columnName": "sharing_public_password_enforced_public_only", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "-1" + }, + { + "fieldPath": "filesSharingPublicExpireDateEnabled", + "columnName": "sharing_public_expire_date_enabled", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "-1" + }, + { + "fieldPath": "filesSharingPublicExpireDateDays", + "columnName": "sharing_public_expire_date_days", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "filesSharingPublicExpireDateEnforced", + "columnName": "sharing_public_expire_date_enforced", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "-1" + }, + { + "fieldPath": "filesSharingPublicUpload", + "columnName": "sharing_public_upload", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "-1" + }, + { + "fieldPath": "filesSharingPublicMultiple", + "columnName": "sharing_public_multiple", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "-1" + }, + { + "fieldPath": "filesSharingPublicSupportsUploadOnly", + "columnName": "supports_upload_only", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "-1" + }, + { + "fieldPath": "filesSharingResharing", + "columnName": "sharing_resharing", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "-1" + }, + { + "fieldPath": "filesSharingFederationOutgoing", + "columnName": "sharing_federation_outgoing", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "-1" + }, + { + "fieldPath": "filesSharingFederationIncoming", + "columnName": "sharing_federation_incoming", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "-1" + }, + { + "fieldPath": "filesSharingUserProfilePicture", + "columnName": "sharing_user_profile_picture", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "-1" + }, + { + "fieldPath": "filesBigFileChunking", + "columnName": "files_bigfilechunking", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "-1" + }, + { + "fieldPath": "filesUndelete", + "columnName": "files_undelete", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "-1" + }, + { + "fieldPath": "filesVersioning", + "columnName": "files_versioning", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "-1" + }, + { + "fieldPath": "filesPrivateLinks", + "columnName": "files_private_links", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "-1" + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "appProviders.enabled", + "columnName": "app_providers_enabled", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "appProviders.version", + "columnName": "app_providers_version", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "appProviders.appsUrl", + "columnName": "app_providers_appsUrl", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "appProviders.openUrl", + "columnName": "app_providers_openUrl", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "appProviders.openWebUrl", + "columnName": "app_providers_openWebUrl", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "appProviders.newUrl", + "columnName": "app_providers_newUrl", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "spaces.enabled", + "columnName": "spaces_enabled", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "spaces.projects", + "columnName": "spaces_projects", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "spaces.shareJail", + "columnName": "spaces_shareJail", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "autoGenerate": true, + "columnNames": [ + "id" + ] + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "files", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`parentId` INTEGER, `owner` TEXT NOT NULL, `remotePath` TEXT NOT NULL, `remoteId` TEXT, `length` INTEGER NOT NULL, `creationTimestamp` INTEGER, `modificationTimestamp` INTEGER NOT NULL, `mimeType` TEXT NOT NULL, `etag` TEXT, `permissions` TEXT, `privateLink` TEXT, `storagePath` TEXT, `name` TEXT, `treeEtag` TEXT, `keepInSync` INTEGER, `lastSyncDateForData` INTEGER, `lastUsage` INTEGER, `fileShareViaLink` INTEGER, `needsToUpdateThumbnail` INTEGER NOT NULL, `modifiedAtLastSyncForData` INTEGER, `etagInConflict` TEXT, `fileIsDownloading` INTEGER, `sharedWithSharee` INTEGER, `sharedByLink` INTEGER NOT NULL, `spaceId` TEXT, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, FOREIGN KEY(`owner`, `spaceId`) REFERENCES `spaces`(`account_name`, `space_id`) ON UPDATE NO ACTION ON DELETE CASCADE )", + "fields": [ + { + "fieldPath": "parentId", + "columnName": "parentId", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "owner", + "columnName": "owner", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "remotePath", + "columnName": "remotePath", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "remoteId", + "columnName": "remoteId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "length", + "columnName": "length", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "creationTimestamp", + "columnName": "creationTimestamp", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "modificationTimestamp", + "columnName": "modificationTimestamp", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "mimeType", + "columnName": "mimeType", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "etag", + "columnName": "etag", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "permissions", + "columnName": "permissions", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "privateLink", + "columnName": "privateLink", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "storagePath", + "columnName": "storagePath", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "treeEtag", + "columnName": "treeEtag", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "availableOfflineStatus", + "columnName": "keepInSync", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "lastSyncDateForData", + "columnName": "lastSyncDateForData", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "lastUsage", + "columnName": "lastUsage", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "fileShareViaLink", + "columnName": "fileShareViaLink", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "needsToUpdateThumbnail", + "columnName": "needsToUpdateThumbnail", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "modifiedAtLastSyncForData", + "columnName": "modifiedAtLastSyncForData", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "etagInConflict", + "columnName": "etagInConflict", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "fileIsDownloading", + "columnName": "fileIsDownloading", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "sharedWithSharee", + "columnName": "sharedWithSharee", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "sharedByLink", + "columnName": "sharedByLink", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "spaceId", + "columnName": "spaceId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": true, + "columnNames": [ + "id" + ] + }, + "indices": [], + "foreignKeys": [ + { + "table": "spaces", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "owner", + "spaceId" + ], + "referencedColumns": [ + "account_name", + "space_id" + ] + } + ] + }, + { + "tableName": "files_sync", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`fileId` INTEGER NOT NULL, `uploadWorkerUuid` BLOB, `downloadWorkerUuid` BLOB, `isSynchronizing` INTEGER NOT NULL, PRIMARY KEY(`fileId`), FOREIGN KEY(`fileId`) REFERENCES `files`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )", + "fields": [ + { + "fieldPath": "fileId", + "columnName": "fileId", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "uploadWorkerUuid", + "columnName": "uploadWorkerUuid", + "affinity": "BLOB", + "notNull": false + }, + { + "fieldPath": "downloadWorkerUuid", + "columnName": "downloadWorkerUuid", + "affinity": "BLOB", + "notNull": false + }, + { + "fieldPath": "isSynchronizing", + "columnName": "isSynchronizing", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "fileId" + ] + }, + "indices": [], + "foreignKeys": [ + { + "table": "files", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "fileId" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, + { + "tableName": "ocshares", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`share_type` INTEGER NOT NULL, `share_with` TEXT, `path` TEXT NOT NULL, `permissions` INTEGER NOT NULL, `shared_date` INTEGER NOT NULL, `expiration_date` INTEGER NOT NULL, `token` TEXT, `shared_with_display_name` TEXT, `share_with_additional_info` TEXT, `is_directory` INTEGER NOT NULL, `id_remote_shared` TEXT NOT NULL, `owner_share` TEXT NOT NULL, `name` TEXT, `url` TEXT, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)", + "fields": [ + { + "fieldPath": "shareType", + "columnName": "share_type", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "shareWith", + "columnName": "share_with", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "path", + "columnName": "path", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "permissions", + "columnName": "permissions", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "sharedDate", + "columnName": "shared_date", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "expirationDate", + "columnName": "expiration_date", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "token", + "columnName": "token", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "sharedWithDisplayName", + "columnName": "shared_with_display_name", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "sharedWithAdditionalInfo", + "columnName": "share_with_additional_info", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "isFolder", + "columnName": "is_directory", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "remoteId", + "columnName": "id_remote_shared", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "accountOwner", + "columnName": "owner_share", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "shareLink", + "columnName": "url", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": true, + "columnNames": [ + "id" + ] + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "transfers", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`localPath` TEXT NOT NULL, `remotePath` TEXT NOT NULL, `accountName` TEXT NOT NULL, `fileSize` INTEGER NOT NULL, `status` INTEGER NOT NULL, `localBehaviour` INTEGER NOT NULL, `forceOverwrite` INTEGER NOT NULL, `transferEndTimestamp` INTEGER, `lastResult` INTEGER, `createdBy` INTEGER NOT NULL, `transferId` TEXT, `spaceId` TEXT, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)", + "fields": [ + { + "fieldPath": "localPath", + "columnName": "localPath", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "remotePath", + "columnName": "remotePath", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "accountName", + "columnName": "accountName", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "fileSize", + "columnName": "fileSize", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "status", + "columnName": "status", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "localBehaviour", + "columnName": "localBehaviour", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "forceOverwrite", + "columnName": "forceOverwrite", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "transferEndTimestamp", + "columnName": "transferEndTimestamp", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "lastResult", + "columnName": "lastResult", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "createdBy", + "columnName": "createdBy", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "transferId", + "columnName": "transferId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "spaceId", + "columnName": "spaceId", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": true, + "columnNames": [ + "id" + ] + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "spaces", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`account_name` TEXT NOT NULL, `drive_alias` TEXT NOT NULL, `drive_type` TEXT NOT NULL, `space_id` TEXT NOT NULL, `last_modified_date_time` TEXT, `name` TEXT NOT NULL, `owner_id` TEXT, `web_url` TEXT NOT NULL, `description` TEXT, `quota_remaining` INTEGER, `quota_state` TEXT, `quota_total` INTEGER, `quota_used` INTEGER, `root_etag` TEXT, `root_id` TEXT NOT NULL, `root_web_dav_url` TEXT NOT NULL, `root_deleted_state` TEXT, PRIMARY KEY(`account_name`, `space_id`))", + "fields": [ + { + "fieldPath": "accountName", + "columnName": "account_name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "driveAlias", + "columnName": "drive_alias", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "driveType", + "columnName": "drive_type", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "space_id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "lastModifiedDateTime", + "columnName": "last_modified_date_time", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "ownerId", + "columnName": "owner_id", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "webUrl", + "columnName": "web_url", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "description", + "columnName": "description", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "quota.remaining", + "columnName": "quota_remaining", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "quota.state", + "columnName": "quota_state", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "quota.total", + "columnName": "quota_total", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "quota.used", + "columnName": "quota_used", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "root.eTag", + "columnName": "root_etag", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "root.id", + "columnName": "root_id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "root.webDavUrl", + "columnName": "root_web_dav_url", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "root.deleteState", + "columnName": "root_deleted_state", + "affinity": "TEXT", + "notNull": false + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "account_name", + "space_id" + ] + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "spaces_special", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`spaces_special_account_name` TEXT NOT NULL, `spaces_special_space_id` TEXT NOT NULL, `spaces_special_etag` TEXT NOT NULL, `file_mime_type` TEXT NOT NULL, `special_id` TEXT NOT NULL, `last_modified_date_time` TEXT NOT NULL, `name` TEXT NOT NULL, `size` INTEGER NOT NULL, `special_folder_name` TEXT NOT NULL, `special_web_dav_url` TEXT NOT NULL, PRIMARY KEY(`spaces_special_space_id`, `special_id`), FOREIGN KEY(`spaces_special_account_name`, `spaces_special_space_id`) REFERENCES `spaces`(`account_name`, `space_id`) ON UPDATE NO ACTION ON DELETE CASCADE )", + "fields": [ + { + "fieldPath": "accountName", + "columnName": "spaces_special_account_name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "spaceId", + "columnName": "spaces_special_space_id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "eTag", + "columnName": "spaces_special_etag", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "fileMimeType", + "columnName": "file_mime_type", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "id", + "columnName": "special_id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "lastModifiedDateTime", + "columnName": "last_modified_date_time", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "size", + "columnName": "size", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "specialFolderName", + "columnName": "special_folder_name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "webDavUrl", + "columnName": "special_web_dav_url", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "spaces_special_space_id", + "special_id" + ] + }, + "indices": [], + "foreignKeys": [ + { + "table": "spaces", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "spaces_special_account_name", + "spaces_special_space_id" + ], + "referencedColumns": [ + "account_name", + "space_id" + ] + } + ] + }, + { + "tableName": "user_quotas", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`accountName` TEXT NOT NULL, `used` INTEGER NOT NULL, `available` INTEGER NOT NULL, PRIMARY KEY(`accountName`))", + "fields": [ + { + "fieldPath": "accountName", + "columnName": "accountName", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "used", + "columnName": "used", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "available", + "columnName": "available", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "accountName" + ] + }, + "indices": [], + "foreignKeys": [] + } + ], + "views": [], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '54a3dafa0982f984143a796eba480037')" + ] + } +} \ No newline at end of file diff --git a/owncloudData/src/main/java/com/owncloud/android/data/OwncloudDatabase.kt b/owncloudData/src/main/java/com/owncloud/android/data/OwncloudDatabase.kt index e03356aff9c..fe6ee9467e3 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/OwncloudDatabase.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/OwncloudDatabase.kt @@ -48,6 +48,7 @@ import com.owncloud.android.data.migrations.MIGRATION_33_34 import com.owncloud.android.data.migrations.MIGRATION_34_35 import com.owncloud.android.data.migrations.MIGRATION_35_36 import com.owncloud.android.data.migrations.MIGRATION_37_38 +import com.owncloud.android.data.migrations.MIGRATION_41_42 import com.owncloud.android.data.sharing.shares.db.OCShareDao import com.owncloud.android.data.sharing.shares.db.OCShareEntity import com.owncloud.android.data.spaces.db.SpaceSpecialEntity @@ -105,6 +106,7 @@ abstract class OwncloudDatabase : RoomDatabase() { MIGRATION_34_35, MIGRATION_35_36, MIGRATION_37_38, + MIGRATION_41_42 ) fun getDatabase( diff --git a/owncloudData/src/main/java/com/owncloud/android/data/ProviderMeta.java b/owncloudData/src/main/java/com/owncloud/android/data/ProviderMeta.java index 841060d083d..af8aeb2c5c7 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/ProviderMeta.java +++ b/owncloudData/src/main/java/com/owncloud/android/data/ProviderMeta.java @@ -31,7 +31,7 @@ public class ProviderMeta { public static final String DB_NAME = "filelist"; public static final String NEW_DB_NAME = "owncloud_database"; - public static final int DB_VERSION = 41; + public static final int DB_VERSION = 42; private ProviderMeta() { } @@ -109,6 +109,7 @@ static public class ProviderTableMeta implements BaseColumns { public static final String FILE_IS_DOWNLOADING = "is_downloading"; public static final String FILE_KEEP_IN_SYNC = "keep_in_sync"; public static final String FILE_LAST_SYNC_DATE_FOR_DATA = "last_sync_date_for_data"; + public static final String FILE_LAST_USAGE = "last_usage"; public static final String FILE_MODIFIED = "modified"; public static final String FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA = "modified_at_last_sync_for_data"; public static final String FILE_NAME = "filename"; diff --git a/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/LocalFileDataSource.kt b/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/LocalFileDataSource.kt index c83d83c35ec..98c26280797 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/LocalFileDataSource.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/LocalFileDataSource.kt @@ -60,4 +60,5 @@ interface LocalFileDataSource { fun saveUploadWorkerUuid(fileId: Long, workerUuid: UUID) fun saveDownloadWorkerUuid(fileId: Long, workerUuid: UUID) fun cleanWorkersUuid(fileId: Long) + fun updateFileWithLastUsage(id: Long, lastUsage: Long?) } diff --git a/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/implementation/OCLocalFileDataSource.kt b/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/implementation/OCLocalFileDataSource.kt index 648e69bdbe5..078e5557f9a 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/implementation/OCLocalFileDataSource.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/implementation/OCLocalFileDataSource.kt @@ -195,6 +195,10 @@ class OCLocalFileDataSource( fileDao.updateDownloadedFilesStorageDirectoryInStoragePath(oldDirectory, newDirectory) } + override fun updateFileWithLastUsage(id: Long, lastUsage: Long?) { + fileDao.updateFileWithLastUsage(id, lastUsage) + } + override fun saveUploadWorkerUuid(fileId: Long, workerUuid: UUID) { TODO("Not yet implemented") } @@ -230,6 +234,7 @@ class OCLocalFileDataSource( needsToUpdateThumbnail = needsToUpdateThumbnail, fileIsDownloading = fileIsDownloading, lastSyncDateForData = lastSyncDateForData, + lastUsage = lastUsage, modifiedAtLastSyncForData = modifiedAtLastSyncForData, etagInConflict = etagInConflict, treeEtag = treeEtag, @@ -257,6 +262,7 @@ class OCLocalFileDataSource( needsToUpdateThumbnail = needsToUpdateThumbnail, fileIsDownloading = fileIsDownloading, lastSyncDateForData = lastSyncDateForData, + lastUsage = lastUsage, modifiedAtLastSyncForData = modifiedAtLastSyncForData, etagInConflict = etagInConflict, treeEtag = treeEtag, diff --git a/owncloudData/src/main/java/com/owncloud/android/data/files/db/FileDao.kt b/owncloudData/src/main/java/com/owncloud/android/data/files/db/FileDao.kt index c1a80a87fd4..d0c1a9d1179 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/files/db/FileDao.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/files/db/FileDao.kt @@ -237,6 +237,7 @@ interface FileDao { treeEtag = localFile.treeEtag, etagInConflict = localFile.etagInConflict, availableOfflineStatus = localFile.availableOfflineStatus, + lastUsage = localFile.lastUsage ).apply { id = localFile.id }) @@ -279,6 +280,7 @@ interface FileDao { permissions = null, treeEtag = "", availableOfflineStatus = NOT_AVAILABLE_OFFLINE.ordinal, + lastUsage = 221 ) ) } @@ -356,6 +358,9 @@ interface FileDao { @Query(UPDATE_FILE_WITH_NEW_AVAILABLE_OFFLINE_STATUS) fun updateFileWithAvailableOfflineStatus(id: Long, availableOfflineStatus: Int) + @Query(UPDATE_FILE_WITH_LAST_USAGE) + fun updateFileWithLastUsage(id: Long, lastUsage: Long?) + @Transaction fun updateConflictStatusForFile(id: Long, eTagInConflict: String?) { val fileEntity = getFileById(id) @@ -470,6 +475,7 @@ interface FileDao { } companion object { + private const val SELECT_FILE_WITH_ID = """ SELECT * FROM ${ProviderMeta.ProviderTableMeta.FILES_TABLE_NAME} @@ -559,6 +565,11 @@ interface FileDao { WHERE id = :id """ + private const val UPDATE_FILE_WITH_LAST_USAGE = """ + UPDATE ${ProviderMeta.ProviderTableMeta.FILES_TABLE_NAME} + SET lastUsage = :lastUsage + WHERE id = :id + """ private const val DISABLE_THUMBNAILS_FOR_FILE = """ UPDATE ${ProviderMeta.ProviderTableMeta.FILES_TABLE_NAME} SET needsToUpdateThumbnail = false diff --git a/owncloudData/src/main/java/com/owncloud/android/data/files/db/OCFileEntity.kt b/owncloudData/src/main/java/com/owncloud/android/data/files/db/OCFileEntity.kt index 9ec3b0e8268..60ffeb611fa 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/files/db/OCFileEntity.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/files/db/OCFileEntity.kt @@ -33,6 +33,7 @@ import com.owncloud.android.data.ProviderMeta.ProviderTableMeta.FILE_ETAG_IN_CON import com.owncloud.android.data.ProviderMeta.ProviderTableMeta.FILE_IS_DOWNLOADING import com.owncloud.android.data.ProviderMeta.ProviderTableMeta.FILE_KEEP_IN_SYNC import com.owncloud.android.data.ProviderMeta.ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA +import com.owncloud.android.data.ProviderMeta.ProviderTableMeta.FILE_LAST_USAGE import com.owncloud.android.data.ProviderMeta.ProviderTableMeta.FILE_MODIFIED import com.owncloud.android.data.ProviderMeta.ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA import com.owncloud.android.data.ProviderMeta.ProviderTableMeta.FILE_NAME @@ -83,6 +84,7 @@ data class OCFileEntity( @ColumnInfo(name = "keepInSync") var availableOfflineStatus: Int? = null, val lastSyncDateForData: Long? = null, + val lastUsage: Long? = null, val fileShareViaLink: Int? = null, var needsToUpdateThumbnail: Boolean = false, val modifiedAtLastSyncForData: Long? = null, @@ -121,6 +123,7 @@ data class OCFileEntity( name = cursor.getString(cursor.getColumnIndexOrThrow(FILE_NAME)), treeEtag = cursor.getString(cursor.getColumnIndexOrThrow(FILE_TREE_ETAG)), lastSyncDateForData = cursor.getLong(cursor.getColumnIndexOrThrow(FILE_LAST_SYNC_DATE_FOR_DATA)), + lastUsage = cursor.getLong(cursor.getColumnIndexOrThrow(FILE_LAST_USAGE)), availableOfflineStatus = cursor.getInt(cursor.getColumnIndexOrThrow(FILE_KEEP_IN_SYNC)), fileShareViaLink = cursor.getInt(cursor.getColumnIndexOrThrow(FILE_SHARED_VIA_LINK)), needsToUpdateThumbnail = cursor.getInt(cursor.getColumnIndexOrThrow(FILE_UPDATE_THUMBNAIL)) == 1, 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 fbb94a734cb..d5b9154fd75 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 @@ -525,6 +525,10 @@ class OCFileRepository( localFileDataSource.updateAvailableOfflineStatusForFile(ocFile, newAvailableOfflineStatus) } + override fun updateFileWithLastUsage(id: Long, lastUsage: Long?) { + localFileDataSource.updateFileWithLastUsage(id, lastUsage) + } + override fun updateDownloadedFilesStorageDirectoryInStoragePath(oldDirectory: String, newDirectory: String) { localFileDataSource.updateDownloadedFilesStorageDirectoryInStoragePath(oldDirectory, newDirectory) } diff --git a/owncloudData/src/main/java/com/owncloud/android/data/migrations/Migration_42.kt b/owncloudData/src/main/java/com/owncloud/android/data/migrations/Migration_42.kt new file mode 100644 index 00000000000..c2e3d0c85b0 --- /dev/null +++ b/owncloudData/src/main/java/com/owncloud/android/data/migrations/Migration_42.kt @@ -0,0 +1,35 @@ +/** + * ownCloud Android client application + * + * @author Aitor Ballesteros Pavón + * + * Copyright (C) 2023 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, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.owncloud.android.data.migrations + +import androidx.room.migration.Migration +import androidx.sqlite.db.SupportSQLiteDatabase + +val MIGRATION_41_42 = object : Migration(41, 42) { + override fun migrate(database: SupportSQLiteDatabase) { + database.run { + execSQL("ALTER TABLE `files` ADD COLUMN `lastUsage` INTEGER") + + execSQL("UPDATE `files` SET `lastUsage` = " + + "CASE WHEN `storagePath` IS NOT NULL THEN ${System.currentTimeMillis()} ELSE NULL END") + } + } +} diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/FileRepository.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/FileRepository.kt index 16c6dc9b8ea..3141707d782 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/FileRepository.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/FileRepository.kt @@ -66,5 +66,5 @@ interface FileRepository { fun disableThumbnailsForFile(fileId: Long) fun updateFileWithNewAvailableOfflineStatus(ocFile: OCFile, newAvailableOfflineStatus: AvailableOfflineStatus) fun updateDownloadedFilesStorageDirectoryInStoragePath(oldDirectory: String, newDirectory: String) - + fun updateFileWithLastUsage(id: Long, lastUsage: Long?) } diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/model/OCFile.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/model/OCFile.kt index ea0b035fbaf..32c92a4d32e 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/model/OCFile.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/model/OCFile.kt @@ -50,6 +50,7 @@ data class OCFile( var treeEtag: String? = "", var availableOfflineStatus: AvailableOfflineStatus? = null, var lastSyncDateForData: Long? = 0, + var lastUsage: Long? = null, var needsToUpdateThumbnail: Boolean = false, var modifiedAtLastSyncForData: Long? = 0, var etagInConflict: String? = null, @@ -207,6 +208,7 @@ data class OCFile( treeEtag = sourceFile.treeEtag etagInConflict = sourceFile.etagInConflict availableOfflineStatus = sourceFile.availableOfflineStatus + lastUsage = sourceFile.lastUsage } /** diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/MoveFileUseCase.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/MoveFileUseCase.kt index bd1f26569d2..d9222d91362 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/MoveFileUseCase.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/MoveFileUseCase.kt @@ -35,18 +35,27 @@ import com.owncloud.android.domain.files.model.OCFile * or moving files to another space will throw an exception. */ class MoveFileUseCase( - private val fileRepository: FileRepository + private val fileRepository: FileRepository, + private val setLastUsageFileUseCase: SetLastUsageFileUseCase, ) : BaseUseCaseWithResult, MoveFileUseCase.Params>() { override fun run(params: Params): List { validateOrThrowException(params.listOfFilesToMove, params.targetFolder) - return fileRepository.moveFile( + val listOfFilesToMoveOriginal = params.listOfFilesToMove.map { it to it.isAvailableLocally } + + val listOfFilesToMove = fileRepository.moveFile( listOfFilesToMove = params.listOfFilesToMove, targetFolder = params.targetFolder, replace = params.replace, isUserLogged = params.isUserLogged, ) + + listOfFilesToMoveOriginal.forEach { (ocFile, isAvailableLocally) -> + setLastUsageFile(ocFile, isAvailableLocally) + } + + return listOfFilesToMove } @Throws( @@ -66,6 +75,14 @@ class MoveFileUseCase( } } + private fun setLastUsageFile(file: OCFile, isAvailableLocally: Boolean ){ + setLastUsageFileUseCase(SetLastUsageFileUseCase.Params( + fileId = file.id!!, + lastUsage = System.currentTimeMillis(), + isAvailableLocally = isAvailableLocally, + isFolder = file.isFolder)) + } + data class Params( val listOfFilesToMove: List, val targetFolder: OCFile, 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 de2ea9a63b2..af881559850 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 @@ -2,7 +2,9 @@ * ownCloud Android client application * * @author Abel García de Prada - * Copyright (C) 2021 ownCloud GmbH. + * @author Aitor Balleseteros Pavón + * + * Copyright (C) 2023 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, @@ -23,17 +25,35 @@ import com.owncloud.android.domain.files.FileRepository import com.owncloud.android.domain.files.model.OCFile class RemoveFileUseCase( - private val fileRepository: FileRepository + private val fileRepository: FileRepository, + private val setLastUsageFileUseCase: SetLastUsageFileUseCase, ) : BaseUseCaseWithResult() { override fun run(params: Params) { require(params.listOfFilesToDelete.isNotEmpty()) - return fileRepository.deleteFiles( + val listOfFilesToDeleteOriginal = params.listOfFilesToDelete.map { it to it.isAvailableLocally } + + val deleteFiles = fileRepository.deleteFiles( listOfFilesToDelete = params.listOfFilesToDelete, - removeOnlyLocalCopy = params.removeOnlyLocalCopy + 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( diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/RenameFileUseCase.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/RenameFileUseCase.kt index 226d99eaa10..8c54543afa1 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/RenameFileUseCase.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/RenameFileUseCase.kt @@ -2,7 +2,9 @@ * ownCloud Android client application * * @author Abel García de Prada - * Copyright (C) 2021 ownCloud GmbH. + * @author Aitor Ballesteros Pavón + * + * Copyright (C) 2023 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, @@ -24,18 +26,29 @@ import com.owncloud.android.domain.files.model.OCFile import com.owncloud.android.domain.validator.FileNameValidator class RenameFileUseCase( - private val fileRepository: FileRepository + private val fileRepository: FileRepository, + private val setLastUsageFileUseCase: SetLastUsageFileUseCase, ) : BaseUseCaseWithResult() { private val fileNameValidator = FileNameValidator() override fun run(params: Params) { fileNameValidator.validateOrThrowException(params.newName) + val isAvailableLocally = params.ocFileToRename.isAvailableLocally - return fileRepository.renameFile( + fileRepository.renameFile( ocFile = params.ocFileToRename, newName = params.newName, ) + setLastUsageFile(params.ocFileToRename, isAvailableLocally) + } + + private fun setLastUsageFile(file: OCFile, isAvailableLocally: Boolean ){ + setLastUsageFileUseCase(SetLastUsageFileUseCase.Params( + fileId = file.id!!, + lastUsage = System.currentTimeMillis(), + isAvailableLocally = isAvailableLocally, + isFolder = file.isFolder)) } data class Params( diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/SetLastUsageFileUseCase.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/SetLastUsageFileUseCase.kt new file mode 100644 index 00000000000..221dae081a9 --- /dev/null +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/SetLastUsageFileUseCase.kt @@ -0,0 +1,37 @@ +/** + * ownCloud Android client application + * + * @author Aitor Ballesteros Pavón + * + * Copyright (C) 2023 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, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.owncloud.android.domain.files.usecases + +import com.owncloud.android.domain.BaseUseCaseWithResult +import com.owncloud.android.domain.files.FileRepository + +class SetLastUsageFileUseCase( + private val fileRepository: FileRepository +) : BaseUseCaseWithResult() { + + override fun run(params: Params) { + if (params.isAvailableLocally && !params.isFolder) { + fileRepository.updateFileWithLastUsage(params.fileId, params.lastUsage) + } + } + + data class Params(val fileId: Long, val lastUsage: Long?, val isAvailableLocally: Boolean, val isFolder: Boolean) +} From 8cba2b7d27db8ca8f5f752b094766f39c57a0859 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Wed, 25 Oct 2023 08:21:29 +0100 Subject: [PATCH 02/11] Fix CR - Deleted double exclamation in file object and some refactoring code --- .../android/dependecyinjection/ViewModelModule.kt | 2 +- .../presentation/files/details/FileDetailsFragment.kt | 2 +- .../presentation/files/details/FileDetailsViewModel.kt | 10 ++++++---- .../data/files/datasources/LocalFileDataSource.kt | 2 +- .../implementation/OCLocalFileDataSource.kt | 2 +- .../java/com/owncloud/android/data/files/db/FileDao.kt | 6 +++--- .../android/data/files/repository/OCFileRepository.kt | 2 +- .../owncloud/android/domain/files/FileRepository.kt | 2 +- .../android/domain/files/usecases/MoveFileUseCase.kt | 6 ++++-- .../android/domain/files/usecases/RemoveFileUseCase.kt | 6 ++++-- .../android/domain/files/usecases/RenameFileUseCase.kt | 6 ++++-- .../domain/files/usecases/SetLastUsageFileUseCase.kt | 4 ++-- 12 files changed, 29 insertions(+), 21 deletions(-) diff --git a/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt b/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt index 31be44622dc..c7e3c39ac22 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt @@ -67,6 +67,7 @@ val viewModelModule = module { viewModelOf(::AccountsManagementViewModel) viewModelOf(::BiometricViewModel) viewModelOf(::DrawerViewModel) + viewModelOf(::FileDetailsViewModel) viewModelOf(::LogListViewModel) viewModelOf(::OAuthViewModel) viewModelOf(::PatternViewModel) @@ -96,7 +97,6 @@ val viewModelModule = module { } viewModel { (ocFile: OCFile) -> ConflictsResolveViewModel(get(), get(), get(), get(), get(), ocFile) } viewModel { AuthenticationViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) } - viewModel { FileDetailsViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) } viewModel { MigrationViewModel(MainApp.dataFolder, get(), get(), get(), get(), get(), get(), get()) } viewModel { TransfersViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) } viewModel { ReceiveExternalFilesViewModel(get(), get(), get()) } diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsFragment.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsFragment.kt index 3535ffa52b4..d78ed6846e5 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsFragment.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsFragment.kt @@ -543,7 +543,7 @@ class FileDetailsFragment : FileFragment() { else -> fileDisplayActivity.openOCFile(fileWaitingToPreview) } - fileDetailsViewModel.setLastUsageFile(fileWaitingToPreview, fileWaitingToPreview.isAvailableLocally) + fileDetailsViewModel.setLastUsageFile(fileWaitingToPreview) } override fun updateViewForSyncInProgress() { diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsViewModel.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsViewModel.kt index bd7223e7fb5..4c15f502917 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsViewModel.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsViewModel.kt @@ -203,12 +203,14 @@ class FileDetailsViewModel( } } - fun setLastUsageFile(file: OCFile, isAvailableLocally: Boolean ){ + fun setLastUsageFile(file: OCFile){ setLastUsageFileUseCase(SetLastUsageFileUseCase.Params( - fileId = file.id!!, + fileId = file.id, lastUsage = System.currentTimeMillis(), - isAvailableLocally = isAvailableLocally, - isFolder = file.isFolder)) + isAvailableLocally = file.isAvailableLocally, + isFolder = file.isFolder, + ) + ) } enum class ActionsInDetailsView { diff --git a/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/LocalFileDataSource.kt b/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/LocalFileDataSource.kt index 98c26280797..2d34bddb1c3 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/LocalFileDataSource.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/LocalFileDataSource.kt @@ -60,5 +60,5 @@ interface LocalFileDataSource { fun saveUploadWorkerUuid(fileId: Long, workerUuid: UUID) fun saveDownloadWorkerUuid(fileId: Long, workerUuid: UUID) fun cleanWorkersUuid(fileId: Long) - fun updateFileWithLastUsage(id: Long, lastUsage: Long?) + fun updateFileWithLastUsage(id: Long?, lastUsage: Long?) } diff --git a/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/implementation/OCLocalFileDataSource.kt b/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/implementation/OCLocalFileDataSource.kt index 078e5557f9a..fc5ff3902be 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/implementation/OCLocalFileDataSource.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/implementation/OCLocalFileDataSource.kt @@ -195,7 +195,7 @@ class OCLocalFileDataSource( fileDao.updateDownloadedFilesStorageDirectoryInStoragePath(oldDirectory, newDirectory) } - override fun updateFileWithLastUsage(id: Long, lastUsage: Long?) { + override fun updateFileWithLastUsage(id: Long?, lastUsage: Long?) { fileDao.updateFileWithLastUsage(id, lastUsage) } diff --git a/owncloudData/src/main/java/com/owncloud/android/data/files/db/FileDao.kt b/owncloudData/src/main/java/com/owncloud/android/data/files/db/FileDao.kt index d0c1a9d1179..40db5c514eb 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/files/db/FileDao.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/files/db/FileDao.kt @@ -237,7 +237,7 @@ interface FileDao { treeEtag = localFile.treeEtag, etagInConflict = localFile.etagInConflict, availableOfflineStatus = localFile.availableOfflineStatus, - lastUsage = localFile.lastUsage + lastUsage = localFile.lastUsage, ).apply { id = localFile.id }) @@ -280,7 +280,7 @@ interface FileDao { permissions = null, treeEtag = "", availableOfflineStatus = NOT_AVAILABLE_OFFLINE.ordinal, - lastUsage = 221 + lastUsage = null ) ) } @@ -359,7 +359,7 @@ interface FileDao { fun updateFileWithAvailableOfflineStatus(id: Long, availableOfflineStatus: Int) @Query(UPDATE_FILE_WITH_LAST_USAGE) - fun updateFileWithLastUsage(id: Long, lastUsage: Long?) + fun updateFileWithLastUsage(id: Long?, lastUsage: Long?) @Transaction fun updateConflictStatusForFile(id: Long, eTagInConflict: String?) { 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 d5b9154fd75..37ce33b3c5b 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 @@ -525,7 +525,7 @@ class OCFileRepository( localFileDataSource.updateAvailableOfflineStatusForFile(ocFile, newAvailableOfflineStatus) } - override fun updateFileWithLastUsage(id: Long, lastUsage: Long?) { + override fun updateFileWithLastUsage(id: Long?, lastUsage: Long?) { localFileDataSource.updateFileWithLastUsage(id, lastUsage) } diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/FileRepository.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/FileRepository.kt index 3141707d782..89f32bd5472 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/FileRepository.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/FileRepository.kt @@ -66,5 +66,5 @@ interface FileRepository { fun disableThumbnailsForFile(fileId: Long) fun updateFileWithNewAvailableOfflineStatus(ocFile: OCFile, newAvailableOfflineStatus: AvailableOfflineStatus) fun updateDownloadedFilesStorageDirectoryInStoragePath(oldDirectory: String, newDirectory: String) - fun updateFileWithLastUsage(id: Long, lastUsage: Long?) + fun updateFileWithLastUsage(id: Long?, lastUsage: Long?) } diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/MoveFileUseCase.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/MoveFileUseCase.kt index d9222d91362..566bb55721a 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/MoveFileUseCase.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/MoveFileUseCase.kt @@ -77,10 +77,12 @@ class MoveFileUseCase( private fun setLastUsageFile(file: OCFile, isAvailableLocally: Boolean ){ setLastUsageFileUseCase(SetLastUsageFileUseCase.Params( - fileId = file.id!!, + fileId = file.id, lastUsage = System.currentTimeMillis(), isAvailableLocally = isAvailableLocally, - isFolder = file.isFolder)) + isFolder = file.isFolder, + ) + ) } data class Params( 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 af881559850..b377075650d 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 @@ -50,10 +50,12 @@ class RemoveFileUseCase( private fun setLastUsageFile(file: OCFile, isAvailableLocally: Boolean ){ setLastUsageFileUseCase(SetLastUsageFileUseCase.Params( - fileId = file.id!!, + fileId = file.id, lastUsage = null, isAvailableLocally = isAvailableLocally, - isFolder = file.isFolder)) + isFolder = file.isFolder, + ) + ) } data class Params( diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/RenameFileUseCase.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/RenameFileUseCase.kt index 8c54543afa1..121c2bc6852 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/RenameFileUseCase.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/RenameFileUseCase.kt @@ -45,10 +45,12 @@ class RenameFileUseCase( private fun setLastUsageFile(file: OCFile, isAvailableLocally: Boolean ){ setLastUsageFileUseCase(SetLastUsageFileUseCase.Params( - fileId = file.id!!, + fileId = file.id, lastUsage = System.currentTimeMillis(), isAvailableLocally = isAvailableLocally, - isFolder = file.isFolder)) + isFolder = file.isFolder, + ) + ) } data class Params( diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/SetLastUsageFileUseCase.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/SetLastUsageFileUseCase.kt index 221dae081a9..db35aadcda3 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/SetLastUsageFileUseCase.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/SetLastUsageFileUseCase.kt @@ -24,7 +24,7 @@ import com.owncloud.android.domain.BaseUseCaseWithResult import com.owncloud.android.domain.files.FileRepository class SetLastUsageFileUseCase( - private val fileRepository: FileRepository + private val fileRepository: FileRepository, ) : BaseUseCaseWithResult() { override fun run(params: Params) { @@ -33,5 +33,5 @@ class SetLastUsageFileUseCase( } } - data class Params(val fileId: Long, val lastUsage: Long?, val isAvailableLocally: Boolean, val isFolder: Boolean) + data class Params(val fileId: Long?, val lastUsage: Long?, val isAvailableLocally: Boolean, val isFolder: Boolean) } From 7d09f7482bbcd0507ff91a279fb67e2f4e538476 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Wed, 25 Oct 2023 09:43:34 +0100 Subject: [PATCH 03/11] Bitrise corrections --- .../domain/files/usecases/MoveFileUseCase.kt | 13 +++++++------ .../domain/files/usecases/RemoveFileUseCase.kt | 7 ++++--- .../domain/files/usecases/RenameFileUseCase.kt | 13 +++++++------ 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/MoveFileUseCase.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/MoveFileUseCase.kt index 566bb55721a..68bfc5e303c 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/MoveFileUseCase.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/MoveFileUseCase.kt @@ -75,12 +75,13 @@ class MoveFileUseCase( } } - private fun setLastUsageFile(file: OCFile, isAvailableLocally: Boolean ){ - setLastUsageFileUseCase(SetLastUsageFileUseCase.Params( - fileId = file.id, - lastUsage = System.currentTimeMillis(), - isAvailableLocally = isAvailableLocally, - isFolder = file.isFolder, + private fun setLastUsageFile(file: OCFile, isAvailableLocally: Boolean) { + setLastUsageFileUseCase( + SetLastUsageFileUseCase.Params( + fileId = file.id, + lastUsage = System.currentTimeMillis(), + isAvailableLocally = isAvailableLocally, + isFolder = file.isFolder, ) ) } 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 b377075650d..f431568a72b 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 @@ -48,14 +48,15 @@ class RemoveFileUseCase( return deleteFiles } - private fun setLastUsageFile(file: OCFile, isAvailableLocally: Boolean ){ - setLastUsageFileUseCase(SetLastUsageFileUseCase.Params( + private fun setLastUsageFile(file: OCFile, isAvailableLocally: Boolean) { + setLastUsageFileUseCase( + SetLastUsageFileUseCase.Params( fileId = file.id, lastUsage = null, isAvailableLocally = isAvailableLocally, isFolder = file.isFolder, - ) ) + ) } data class Params( diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/RenameFileUseCase.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/RenameFileUseCase.kt index 121c2bc6852..0be7fc5ef03 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/RenameFileUseCase.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/RenameFileUseCase.kt @@ -43,12 +43,13 @@ class RenameFileUseCase( setLastUsageFile(params.ocFileToRename, isAvailableLocally) } - private fun setLastUsageFile(file: OCFile, isAvailableLocally: Boolean ){ - setLastUsageFileUseCase(SetLastUsageFileUseCase.Params( - fileId = file.id, - lastUsage = System.currentTimeMillis(), - isAvailableLocally = isAvailableLocally, - isFolder = file.isFolder, + private fun setLastUsageFile(file: OCFile, isAvailableLocally: Boolean) { + setLastUsageFileUseCase( + SetLastUsageFileUseCase.Params( + fileId = file.id, + lastUsage = System.currentTimeMillis(), + isAvailableLocally = isAvailableLocally, + isFolder = file.isFolder, ) ) } From 634be2e8b386065f0cf12dd28817c42e60a7afe1 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Wed, 25 Oct 2023 09:49:55 +0100 Subject: [PATCH 04/11] Bitrise corrections 2 --- .../files/details/FileDetailsViewModel.kt | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsViewModel.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsViewModel.kt index 4c15f502917..b3401ac910a 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsViewModel.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsViewModel.kt @@ -182,18 +182,20 @@ class FileDetailsViewModel( val shareWithUsersAllowed = contextProvider.getBoolean(R.bool.share_with_users_feature) val sendAllowed = contextProvider.getString(R.string.send_files_to_other_apps).equals("on", ignoreCase = true) viewModelScope.launch(coroutinesDispatcherProvider.io) { - val result = filterFileMenuOptionsUseCase(FilterFileMenuOptionsUseCase.Params( - files = listOf(file), - accountName = getAccount().name, - isAnyFileVideoPreviewing = false, - displaySelectAll = false, - displaySelectInverse = false, - onlyAvailableOfflineFiles = false, - onlySharedByLinkFiles = false, - shareViaLinkAllowed = shareViaLinkAllowed, - shareWithUsersAllowed = shareWithUsersAllowed, - sendAllowed = sendAllowed, - )) + val result = filterFileMenuOptionsUseCase( + FilterFileMenuOptionsUseCase.Params( + files = listOf(file), + accountName = getAccount().name, + isAnyFileVideoPreviewing = false, + displaySelectAll = false, + displaySelectInverse = false, + onlyAvailableOfflineFiles = false, + onlySharedByLinkFiles = false, + shareViaLinkAllowed = shareViaLinkAllowed, + shareWithUsersAllowed = shareWithUsersAllowed, + sendAllowed = sendAllowed, + ) + ) result.apply { remove(FileMenuOption.DETAILS) remove(FileMenuOption.MOVE) @@ -203,12 +205,13 @@ class FileDetailsViewModel( } } - fun setLastUsageFile(file: OCFile){ - setLastUsageFileUseCase(SetLastUsageFileUseCase.Params( - fileId = file.id, - lastUsage = System.currentTimeMillis(), - isAvailableLocally = file.isAvailableLocally, - isFolder = file.isFolder, + fun setLastUsageFile(file: OCFile) { + setLastUsageFileUseCase( + SetLastUsageFileUseCase.Params( + fileId = file.id, + lastUsage = System.currentTimeMillis(), + isAvailableLocally = file.isAvailableLocally, + isFolder = file.isFolder, ) ) } From 35a29465ff732d844ac22b2bce7ca2c737c6c35f Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Wed, 25 Oct 2023 10:08:00 +0100 Subject: [PATCH 05/11] Bitrise corrections - changes in unit tests --- .../com/owncloud/android/domain/files/model/OCFileTest.kt | 4 ++++ .../android/domain/files/usecases/MoveFileUseCaseTest.kt | 4 +++- .../android/domain/files/usecases/RemoveFileUseCaseTest.kt | 4 +++- .../android/domain/files/usecases/RenameFileUseCaseTest.kt | 4 +++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/owncloudDomain/src/test/java/com/owncloud/android/domain/files/model/OCFileTest.kt b/owncloudDomain/src/test/java/com/owncloud/android/domain/files/model/OCFileTest.kt index bb421c0f5c6..ccfd34d964d 100644 --- a/owncloudDomain/src/test/java/com/owncloud/android/domain/files/model/OCFileTest.kt +++ b/owncloudDomain/src/test/java/com/owncloud/android/domain/files/model/OCFileTest.kt @@ -47,6 +47,7 @@ class OCFileTest { OC_FILE.treeEtag, OC_FILE.availableOfflineStatus, OC_FILE.lastSyncDateForData, + OC_FILE.lastUsage, OC_FILE.needsToUpdateThumbnail, OC_FILE.modifiedAtLastSyncForData, OC_FILE.etagInConflict, @@ -72,6 +73,7 @@ class OCFileTest { treeEtag = OC_FILE.treeEtag, availableOfflineStatus = OC_FILE.availableOfflineStatus, lastSyncDateForData = OC_FILE.lastSyncDateForData, + lastUsage = OC_FILE.lastUsage, needsToUpdateThumbnail = OC_FILE.needsToUpdateThumbnail, modifiedAtLastSyncForData = OC_FILE.modifiedAtLastSyncForData, etagInConflict = OC_FILE.etagInConflict, @@ -103,6 +105,7 @@ class OCFileTest { OC_FILE.treeEtag, OC_FILE.availableOfflineStatus, OC_FILE.lastSyncDateForData, + OC_FILE.lastUsage, OC_FILE.needsToUpdateThumbnail, OC_FILE.modifiedAtLastSyncForData, OC_FILE.etagInConflict, @@ -128,6 +131,7 @@ class OCFileTest { treeEtag = OC_FILE.treeEtag, availableOfflineStatus = OC_FILE.availableOfflineStatus, lastSyncDateForData = OC_FILE.lastSyncDateForData, + lastUsage = OC_FILE.lastUsage, needsToUpdateThumbnail = OC_FILE.needsToUpdateThumbnail, modifiedAtLastSyncForData = OC_FILE.modifiedAtLastSyncForData, etagInConflict = OC_FILE.etagInConflict, diff --git a/owncloudDomain/src/test/java/com/owncloud/android/domain/files/usecases/MoveFileUseCaseTest.kt b/owncloudDomain/src/test/java/com/owncloud/android/domain/files/usecases/MoveFileUseCaseTest.kt index cb595dfc255..fc2faeeda08 100644 --- a/owncloudDomain/src/test/java/com/owncloud/android/domain/files/usecases/MoveFileUseCaseTest.kt +++ b/owncloudDomain/src/test/java/com/owncloud/android/domain/files/usecases/MoveFileUseCaseTest.kt @@ -25,6 +25,7 @@ import com.owncloud.android.domain.files.FileRepository import com.owncloud.android.testutil.OC_FILE import com.owncloud.android.testutil.OC_FOLDER import io.mockk.every +import io.mockk.mockk import io.mockk.spyk import io.mockk.verify import org.junit.Assert @@ -33,7 +34,8 @@ import org.junit.Test class MoveFileUseCaseTest { private val repository: FileRepository = spyk() - private val useCase = MoveFileUseCase(repository) + private val setLastUsageFileUseCase: SetLastUsageFileUseCase = mockk(relaxed = true) + private val useCase = MoveFileUseCase(repository, setLastUsageFileUseCase) private val useCaseParams = MoveFileUseCase.Params( listOfFilesToMove = listOf(OC_FILE.copy(remotePath = "/video.mp4", parentId = 123)), targetFolder = OC_FOLDER.copy(id = 100), diff --git a/owncloudDomain/src/test/java/com/owncloud/android/domain/files/usecases/RemoveFileUseCaseTest.kt b/owncloudDomain/src/test/java/com/owncloud/android/domain/files/usecases/RemoveFileUseCaseTest.kt index a19e2a5b713..dd9913161b0 100644 --- a/owncloudDomain/src/test/java/com/owncloud/android/domain/files/usecases/RemoveFileUseCaseTest.kt +++ b/owncloudDomain/src/test/java/com/owncloud/android/domain/files/usecases/RemoveFileUseCaseTest.kt @@ -23,6 +23,7 @@ import com.owncloud.android.domain.files.FileRepository import com.owncloud.android.testutil.OC_FILE import com.owncloud.android.testutil.OC_FOLDER import io.mockk.every +import io.mockk.mockk import io.mockk.spyk import io.mockk.verify import org.junit.Assert.assertEquals @@ -31,7 +32,8 @@ import org.junit.Test class RemoveFileUseCaseTest { private val repository: FileRepository = spyk() - private val useCase = RemoveFileUseCase(repository) + private val setLastUsageFileUseCase: SetLastUsageFileUseCase = mockk(relaxed = true) + private val useCase = RemoveFileUseCase(repository, setLastUsageFileUseCase) private val useCaseParams = RemoveFileUseCase.Params(listOf(OC_FILE, OC_FOLDER), removeOnlyLocalCopy = true) @Test diff --git a/owncloudDomain/src/test/java/com/owncloud/android/domain/files/usecases/RenameFileUseCaseTest.kt b/owncloudDomain/src/test/java/com/owncloud/android/domain/files/usecases/RenameFileUseCaseTest.kt index 5a42f58cfc9..d5579ca8676 100644 --- a/owncloudDomain/src/test/java/com/owncloud/android/domain/files/usecases/RenameFileUseCaseTest.kt +++ b/owncloudDomain/src/test/java/com/owncloud/android/domain/files/usecases/RenameFileUseCaseTest.kt @@ -22,6 +22,7 @@ import com.owncloud.android.domain.exceptions.UnauthorizedException import com.owncloud.android.domain.files.FileRepository import com.owncloud.android.testutil.OC_FILE import io.mockk.every +import io.mockk.mockk import io.mockk.spyk import io.mockk.verify import org.junit.Assert.assertEquals @@ -30,7 +31,8 @@ import org.junit.Test class RenameFileUseCaseTest { private val repository: FileRepository = spyk() - private val useCase = RenameFileUseCase(repository) + private val setLastUsageFileUseCase: SetLastUsageFileUseCase = mockk(relaxed = true) + private val useCase = RenameFileUseCase(repository, setLastUsageFileUseCase) private val useCaseParams = RenameFileUseCase.Params(OC_FILE, "Video.mp4") @Test From b8ddd37514ae327484e95d1d5d853a9a926bb674 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Sun, 29 Oct 2023 10:34:14 +0000 Subject: [PATCH 06/11] QA corrections - Added default parameter lastUsage to null in OCFileRepository and added lastUsage functionality to preview file --- .../files/filelist/MainFileListFragment.kt | 1 + .../operations/FileOperationsViewModel.kt | 16 ++++++++++++++ .../data/files/repository/OCFileRepository.kt | 2 +- .../files/usecases/RemoveFileUseCase.kt | 22 +------------------ 4 files changed, 19 insertions(+), 22 deletions(-) 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( From 150e0f6f66131e8811f0cf441867e11d99d05305 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Mon, 30 Oct 2023 08:11:37 +0000 Subject: [PATCH 07/11] CR corrections - Deleted code from previous database, id lastUsage is not nullable and moved setLastUsageFile to FileOperationsViewModel. --- changelog/unreleased/4187 | 0 .../com/owncloud/android/db/ProviderMeta.java | 1 - .../dependecyinjection/ViewModelModule.kt | 1 + .../files/details/FileDetailsFragment.kt | 2 +- .../files/details/FileDetailsViewModel.kt | 12 ---------- .../operations/FileOperationsViewModel.kt | 2 +- .../android/providers/FileContentProvider.kt | 3 --- .../workers/UploadFileFromFileSystemWorker.kt | 1 - .../owncloud/android/data/ProviderMeta.java | 1 - .../files/datasources/LocalFileDataSource.kt | 2 +- .../implementation/OCLocalFileDataSource.kt | 4 ++-- .../owncloud/android/data/files/db/FileDao.kt | 3 +-- .../android/data/files/db/OCFileEntity.kt | 2 -- .../data/files/repository/OCFileRepository.kt | 4 ++-- .../android/data/migrations/Migration_42.kt | 3 +-- .../datasources/OCLocalFileDataSourceTest.kt | 22 +++++++++++++++++++ .../android/domain/files/FileRepository.kt | 2 +- .../domain/files/usecases/MoveFileUseCase.kt | 2 +- .../files/usecases/RenameFileUseCase.kt | 2 +- .../files/usecases/SetLastUsageFileUseCase.kt | 2 +- .../files/usecases/RemoveFileUseCaseTest.kt | 4 +--- 21 files changed, 37 insertions(+), 38 deletions(-) create mode 100644 changelog/unreleased/4187 diff --git a/changelog/unreleased/4187 b/changelog/unreleased/4187 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/owncloudApp/src/main/java/com/owncloud/android/db/ProviderMeta.java b/owncloudApp/src/main/java/com/owncloud/android/db/ProviderMeta.java index b18c0eecf8e..017956186e7 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/db/ProviderMeta.java +++ b/owncloudApp/src/main/java/com/owncloud/android/db/ProviderMeta.java @@ -82,7 +82,6 @@ static public class ProviderTableMeta implements BaseColumns { public static final String FILE_ACCOUNT_OWNER = "file_owner"; public static final String FILE_LAST_SYNC_DATE = "last_sync_date";// _for_properties, but let's keep it as it is public static final String FILE_LAST_SYNC_DATE_FOR_DATA = "last_sync_date_for_data"; - public static final String FILE_LAST_USAGE = "last_usage"; public static final String FILE_KEEP_IN_SYNC = "keep_in_sync"; public static final String FILE_ETAG = "etag"; public static final String FILE_TREE_ETAG = "tree_etag"; diff --git a/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt b/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt index c7e3c39ac22..f6b2f6177d4 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/ViewModelModule.kt @@ -68,6 +68,7 @@ val viewModelModule = module { viewModelOf(::BiometricViewModel) viewModelOf(::DrawerViewModel) viewModelOf(::FileDetailsViewModel) + viewModelOf(::FileOperationsViewModel) viewModelOf(::LogListViewModel) viewModelOf(::OAuthViewModel) viewModelOf(::PatternViewModel) diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsFragment.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsFragment.kt index d78ed6846e5..c7789ed2316 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsFragment.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsFragment.kt @@ -543,7 +543,7 @@ class FileDetailsFragment : FileFragment() { else -> fileDisplayActivity.openOCFile(fileWaitingToPreview) } - fileDetailsViewModel.setLastUsageFile(fileWaitingToPreview) + fileOperationsViewModel.setLastUsageFile(fileWaitingToPreview) } override fun updateViewForSyncInProgress() { diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsViewModel.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsViewModel.kt index b3401ac910a..bd4312f5fd3 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsViewModel.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsViewModel.kt @@ -41,7 +41,6 @@ import com.owncloud.android.domain.files.model.FileMenuOption import com.owncloud.android.domain.files.model.OCFile import com.owncloud.android.domain.files.model.OCFileWithSyncInfo import com.owncloud.android.domain.files.usecases.GetFileWithSyncInfoByIdUseCase -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.extensions.getRunningWorkInfosByTags @@ -72,7 +71,6 @@ class FileDetailsViewModel( private val cancelUploadForFileUseCase: CancelUploadForFileUseCase, private val filterFileMenuOptionsUseCase: FilterFileMenuOptionsUseCase, getFileWithSyncInfoByIdUseCase: GetFileWithSyncInfoByIdUseCase, - private val setLastUsageFileUseCase: SetLastUsageFileUseCase, val contextProvider: ContextProvider, private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider, private val workManager: WorkManager, @@ -205,16 +203,6 @@ class FileDetailsViewModel( } } - fun setLastUsageFile(file: OCFile) { - setLastUsageFileUseCase( - SetLastUsageFileUseCase.Params( - fileId = file.id, - lastUsage = System.currentTimeMillis(), - isAvailableLocally = file.isAvailableLocally, - isFolder = file.isFolder, - ) - ) - } enum class ActionsInDetailsView { NONE, SYNC, SYNC_AND_OPEN, SYNC_AND_OPEN_WITH, SYNC_AND_SEND; 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 caff13fac84..5cda58aa704 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 @@ -127,7 +127,7 @@ class FileOperationsViewModel( viewModelScope.launch(coroutinesDispatcherProvider.io) { setLastUsageFileUseCase( SetLastUsageFileUseCase.Params( - fileId = file.id, + fileId = file.id!!, lastUsage = System.currentTimeMillis(), isAvailableLocally = file.isAvailableLocally, isFolder = file.isFolder, diff --git a/owncloudApp/src/main/java/com/owncloud/android/providers/FileContentProvider.kt b/owncloudApp/src/main/java/com/owncloud/android/providers/FileContentProvider.kt index e6818a35b19..4c9dcfc40ac 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/providers/FileContentProvider.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/providers/FileContentProvider.kt @@ -1116,7 +1116,6 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi ProviderTableMeta.FILE_LAST_SYNC_DATE + " INTEGER, " + ProviderTableMeta.FILE_KEEP_IN_SYNC + " INTEGER, " + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " INTEGER, " + - ProviderTableMeta.FILE_LAST_USAGE + " INTEGER, " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " INTEGER, " + ProviderTableMeta.FILE_ETAG + " TEXT, " + ProviderTableMeta.FILE_TREE_ETAG + " TEXT, " + @@ -1383,8 +1382,6 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi fileProjectionMap[ProviderTableMeta.FILE_LAST_SYNC_DATE] = ProviderTableMeta.FILE_LAST_SYNC_DATE fileProjectionMap[ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA] = ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA - fileProjectionMap[ProviderTableMeta.FILE_LAST_USAGE] = - ProviderTableMeta.FILE_LAST_USAGE fileProjectionMap[ProviderTableMeta.FILE_KEEP_IN_SYNC] = ProviderTableMeta.FILE_KEEP_IN_SYNC fileProjectionMap[ProviderTableMeta.FILE_ETAG] = ProviderTableMeta.FILE_ETAG fileProjectionMap[ProviderTableMeta.FILE_TREE_ETAG] = ProviderTableMeta.FILE_TREE_ETAG diff --git a/owncloudApp/src/main/java/com/owncloud/android/workers/UploadFileFromFileSystemWorker.kt b/owncloudApp/src/main/java/com/owncloud/android/workers/UploadFileFromFileSystemWorker.kt index d1e7d7b2d90..c0b4180ea24 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/workers/UploadFileFromFileSystemWorker.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/workers/UploadFileFromFileSystemWorker.kt @@ -335,7 +335,6 @@ class UploadFileFromFileSystemWorker( length = (File(ocTransfer.localPath).length()), lastSyncDateForData = currentTime, modifiedAtLastSyncForData = currentTime, - lastUsage = currentTime ) } else { // Uploading a file should remove any conflicts on the file. diff --git a/owncloudData/src/main/java/com/owncloud/android/data/ProviderMeta.java b/owncloudData/src/main/java/com/owncloud/android/data/ProviderMeta.java index af8aeb2c5c7..c42a9d9e69b 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/ProviderMeta.java +++ b/owncloudData/src/main/java/com/owncloud/android/data/ProviderMeta.java @@ -109,7 +109,6 @@ static public class ProviderTableMeta implements BaseColumns { public static final String FILE_IS_DOWNLOADING = "is_downloading"; public static final String FILE_KEEP_IN_SYNC = "keep_in_sync"; public static final String FILE_LAST_SYNC_DATE_FOR_DATA = "last_sync_date_for_data"; - public static final String FILE_LAST_USAGE = "last_usage"; public static final String FILE_MODIFIED = "modified"; public static final String FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA = "modified_at_last_sync_for_data"; public static final String FILE_NAME = "filename"; diff --git a/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/LocalFileDataSource.kt b/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/LocalFileDataSource.kt index 2d34bddb1c3..cc1386695cf 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/LocalFileDataSource.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/LocalFileDataSource.kt @@ -60,5 +60,5 @@ interface LocalFileDataSource { fun saveUploadWorkerUuid(fileId: Long, workerUuid: UUID) fun saveDownloadWorkerUuid(fileId: Long, workerUuid: UUID) fun cleanWorkersUuid(fileId: Long) - fun updateFileWithLastUsage(id: Long?, lastUsage: Long?) + fun updateFileWithLastUsage(fileId: Long, lastUsage: Long?) } diff --git a/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/implementation/OCLocalFileDataSource.kt b/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/implementation/OCLocalFileDataSource.kt index fc5ff3902be..7e4ef55e15d 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/implementation/OCLocalFileDataSource.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/files/datasources/implementation/OCLocalFileDataSource.kt @@ -195,8 +195,8 @@ class OCLocalFileDataSource( fileDao.updateDownloadedFilesStorageDirectoryInStoragePath(oldDirectory, newDirectory) } - override fun updateFileWithLastUsage(id: Long?, lastUsage: Long?) { - fileDao.updateFileWithLastUsage(id, lastUsage) + override fun updateFileWithLastUsage(fileId: Long, lastUsage: Long?) { + fileDao.updateFileWithLastUsage(fileId, lastUsage) } override fun saveUploadWorkerUuid(fileId: Long, workerUuid: UUID) { diff --git a/owncloudData/src/main/java/com/owncloud/android/data/files/db/FileDao.kt b/owncloudData/src/main/java/com/owncloud/android/data/files/db/FileDao.kt index 40db5c514eb..3b3cb7fe327 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/files/db/FileDao.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/files/db/FileDao.kt @@ -280,7 +280,6 @@ interface FileDao { permissions = null, treeEtag = "", availableOfflineStatus = NOT_AVAILABLE_OFFLINE.ordinal, - lastUsage = null ) ) } @@ -359,7 +358,7 @@ interface FileDao { fun updateFileWithAvailableOfflineStatus(id: Long, availableOfflineStatus: Int) @Query(UPDATE_FILE_WITH_LAST_USAGE) - fun updateFileWithLastUsage(id: Long?, lastUsage: Long?) + fun updateFileWithLastUsage(id: Long, lastUsage: Long?) @Transaction fun updateConflictStatusForFile(id: Long, eTagInConflict: String?) { diff --git a/owncloudData/src/main/java/com/owncloud/android/data/files/db/OCFileEntity.kt b/owncloudData/src/main/java/com/owncloud/android/data/files/db/OCFileEntity.kt index 60ffeb611fa..ebb922c5d8b 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/files/db/OCFileEntity.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/files/db/OCFileEntity.kt @@ -33,7 +33,6 @@ import com.owncloud.android.data.ProviderMeta.ProviderTableMeta.FILE_ETAG_IN_CON import com.owncloud.android.data.ProviderMeta.ProviderTableMeta.FILE_IS_DOWNLOADING import com.owncloud.android.data.ProviderMeta.ProviderTableMeta.FILE_KEEP_IN_SYNC import com.owncloud.android.data.ProviderMeta.ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA -import com.owncloud.android.data.ProviderMeta.ProviderTableMeta.FILE_LAST_USAGE import com.owncloud.android.data.ProviderMeta.ProviderTableMeta.FILE_MODIFIED import com.owncloud.android.data.ProviderMeta.ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA import com.owncloud.android.data.ProviderMeta.ProviderTableMeta.FILE_NAME @@ -123,7 +122,6 @@ data class OCFileEntity( name = cursor.getString(cursor.getColumnIndexOrThrow(FILE_NAME)), treeEtag = cursor.getString(cursor.getColumnIndexOrThrow(FILE_TREE_ETAG)), lastSyncDateForData = cursor.getLong(cursor.getColumnIndexOrThrow(FILE_LAST_SYNC_DATE_FOR_DATA)), - lastUsage = cursor.getLong(cursor.getColumnIndexOrThrow(FILE_LAST_USAGE)), availableOfflineStatus = cursor.getInt(cursor.getColumnIndexOrThrow(FILE_KEEP_IN_SYNC)), fileShareViaLink = cursor.getInt(cursor.getColumnIndexOrThrow(FILE_SHARED_VIA_LINK)), needsToUpdateThumbnail = cursor.getInt(cursor.getColumnIndexOrThrow(FILE_UPDATE_THUMBNAIL)) == 1, 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 96f2225a2b2..8b4097ac598 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 @@ -525,8 +525,8 @@ class OCFileRepository( localFileDataSource.updateAvailableOfflineStatusForFile(ocFile, newAvailableOfflineStatus) } - override fun updateFileWithLastUsage(id: Long?, lastUsage: Long?) { - localFileDataSource.updateFileWithLastUsage(id, lastUsage) + override fun updateFileWithLastUsage(fileId: Long, lastUsage: Long?) { + localFileDataSource.updateFileWithLastUsage(fileId, lastUsage) } override fun updateDownloadedFilesStorageDirectoryInStoragePath(oldDirectory: String, newDirectory: String) { diff --git a/owncloudData/src/main/java/com/owncloud/android/data/migrations/Migration_42.kt b/owncloudData/src/main/java/com/owncloud/android/data/migrations/Migration_42.kt index c2e3d0c85b0..66a72aeca71 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/migrations/Migration_42.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/migrations/Migration_42.kt @@ -28,8 +28,7 @@ val MIGRATION_41_42 = object : Migration(41, 42) { database.run { execSQL("ALTER TABLE `files` ADD COLUMN `lastUsage` INTEGER") - execSQL("UPDATE `files` SET `lastUsage` = " + - "CASE WHEN `storagePath` IS NOT NULL THEN ${System.currentTimeMillis()} ELSE NULL END") + execSQL("UPDATE `files` SET `lastUsage` = CASE WHEN `storagePath` IS NOT NULL THEN ${System.currentTimeMillis()} ELSE NULL END") } } } diff --git a/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCLocalFileDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCLocalFileDataSourceTest.kt index 2d20f53449b..43e1e8a95a6 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCLocalFileDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCLocalFileDataSourceTest.kt @@ -683,6 +683,28 @@ class OCLocalFileDataSourceTest { } + @Test + fun `updateFileWithLastUsage should change last usage parameter with current time for a file`() { + + val currentTime = System.currentTimeMillis() + + every { dao.updateFileWithLastUsage(OC_FILE.id!!, currentTime) } returns Unit + + localDataSource.updateFileWithLastUsage(OC_FILE.id!!, currentTime) + + verify(exactly = 1) { dao.updateFileWithLastUsage(OC_FILE.id!!, currentTime) } + } + + @Test + fun `updateFileWithLastUsage should change last usage parameter with null for a file`() { + + every { dao.updateFileWithLastUsage(any(), null) } returns Unit + + localDataSource.updateFileWithLastUsage(OC_FILE.id!!, null) + + verify(exactly = 1) { dao.updateFileWithLastUsage(OC_FILE.id!!, null) } + } + companion object { private val DUMMY_FILE_ENTITY: OCFileEntity = OC_FILE.toEntity() } diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/FileRepository.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/FileRepository.kt index 89f32bd5472..d765588cfc3 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/FileRepository.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/FileRepository.kt @@ -66,5 +66,5 @@ interface FileRepository { fun disableThumbnailsForFile(fileId: Long) fun updateFileWithNewAvailableOfflineStatus(ocFile: OCFile, newAvailableOfflineStatus: AvailableOfflineStatus) fun updateDownloadedFilesStorageDirectoryInStoragePath(oldDirectory: String, newDirectory: String) - fun updateFileWithLastUsage(id: Long?, lastUsage: Long?) + fun updateFileWithLastUsage(fileId: Long, lastUsage: Long?) } diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/MoveFileUseCase.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/MoveFileUseCase.kt index 68bfc5e303c..b5edb931197 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/MoveFileUseCase.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/MoveFileUseCase.kt @@ -78,7 +78,7 @@ class MoveFileUseCase( private fun setLastUsageFile(file: OCFile, isAvailableLocally: Boolean) { setLastUsageFileUseCase( SetLastUsageFileUseCase.Params( - fileId = file.id, + fileId = file.id!!, lastUsage = System.currentTimeMillis(), isAvailableLocally = isAvailableLocally, isFolder = file.isFolder, diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/RenameFileUseCase.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/RenameFileUseCase.kt index 0be7fc5ef03..03d8ba14a5d 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/RenameFileUseCase.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/RenameFileUseCase.kt @@ -46,7 +46,7 @@ class RenameFileUseCase( private fun setLastUsageFile(file: OCFile, isAvailableLocally: Boolean) { setLastUsageFileUseCase( SetLastUsageFileUseCase.Params( - fileId = file.id, + fileId = file.id!!, lastUsage = System.currentTimeMillis(), isAvailableLocally = isAvailableLocally, isFolder = file.isFolder, diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/SetLastUsageFileUseCase.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/SetLastUsageFileUseCase.kt index db35aadcda3..eaac63336bd 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/SetLastUsageFileUseCase.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/SetLastUsageFileUseCase.kt @@ -33,5 +33,5 @@ class SetLastUsageFileUseCase( } } - data class Params(val fileId: Long?, val lastUsage: Long?, val isAvailableLocally: Boolean, val isFolder: Boolean) + data class Params(val fileId: Long, val lastUsage: Long?, val isAvailableLocally: Boolean, val isFolder: Boolean) } diff --git a/owncloudDomain/src/test/java/com/owncloud/android/domain/files/usecases/RemoveFileUseCaseTest.kt b/owncloudDomain/src/test/java/com/owncloud/android/domain/files/usecases/RemoveFileUseCaseTest.kt index dd9913161b0..a19e2a5b713 100644 --- a/owncloudDomain/src/test/java/com/owncloud/android/domain/files/usecases/RemoveFileUseCaseTest.kt +++ b/owncloudDomain/src/test/java/com/owncloud/android/domain/files/usecases/RemoveFileUseCaseTest.kt @@ -23,7 +23,6 @@ import com.owncloud.android.domain.files.FileRepository import com.owncloud.android.testutil.OC_FILE import com.owncloud.android.testutil.OC_FOLDER import io.mockk.every -import io.mockk.mockk import io.mockk.spyk import io.mockk.verify import org.junit.Assert.assertEquals @@ -32,8 +31,7 @@ import org.junit.Test class RemoveFileUseCaseTest { private val repository: FileRepository = spyk() - private val setLastUsageFileUseCase: SetLastUsageFileUseCase = mockk(relaxed = true) - private val useCase = RemoveFileUseCase(repository, setLastUsageFileUseCase) + private val useCase = RemoveFileUseCase(repository) private val useCaseParams = RemoveFileUseCase.Params(listOf(OC_FILE, OC_FOLDER), removeOnlyLocalCopy = true) @Test From b44713e4c9fbdef5b9868bb388a8f2a37038292f Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Mon, 30 Oct 2023 13:27:07 +0000 Subject: [PATCH 08/11] Some fixes from CR --- .../presentation/files/filelist/MainFileListFragment.kt | 1 - .../owncloud/android/ui/activity/FileDisplayActivity.kt | 1 + .../data/file/datasources/OCLocalFileDataSourceTest.kt | 2 +- .../domain/files/usecases/SetLastUsageFileUseCase.kt | 7 ++++++- 4 files changed, 8 insertions(+), 3 deletions(-) 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 4cb811fff0e..aa996518464 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,7 +1133,6 @@ 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/ui/activity/FileDisplayActivity.kt b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt index a403d3b15a6..09281d59b5b 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt @@ -1731,6 +1731,7 @@ class FileDisplayActivity : FileActivity(), startSyncThenOpen(file) } } + fileOperationsViewModel.setLastUsageFile(file) } override fun onShareFileClicked(file: OCFile) { diff --git a/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCLocalFileDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCLocalFileDataSourceTest.kt index 43e1e8a95a6..5b90d8e4be0 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCLocalFileDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCLocalFileDataSourceTest.kt @@ -698,7 +698,7 @@ class OCLocalFileDataSourceTest { @Test fun `updateFileWithLastUsage should change last usage parameter with null for a file`() { - every { dao.updateFileWithLastUsage(any(), null) } returns Unit + every { dao.updateFileWithLastUsage(OC_FILE.id!!, null) } returns Unit localDataSource.updateFileWithLastUsage(OC_FILE.id!!, null) diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/SetLastUsageFileUseCase.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/SetLastUsageFileUseCase.kt index eaac63336bd..4b165b9c15d 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/SetLastUsageFileUseCase.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/files/usecases/SetLastUsageFileUseCase.kt @@ -33,5 +33,10 @@ class SetLastUsageFileUseCase( } } - data class Params(val fileId: Long, val lastUsage: Long?, val isAvailableLocally: Boolean, val isFolder: Boolean) + data class Params( + val fileId: Long, + val lastUsage: Long?, + val isAvailableLocally: Boolean, + val isFolder: Boolean, + ) } From 4817908bc2061ac5481d3923f68c3b81d20d8647 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Thu, 2 Nov 2023 11:27:28 +0000 Subject: [PATCH 09/11] Added functionality lastUsage in Open in web and Open with --- .../android/presentation/files/details/FileDetailsFragment.kt | 2 ++ .../android/presentation/files/filelist/MainFileListFragment.kt | 1 + .../com/owncloud/android/ui/activity/FileDisplayActivity.kt | 1 + 3 files changed, 4 insertions(+) diff --git a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsFragment.kt b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsFragment.kt index c7789ed2316..c32ec1d407e 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsFragment.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/presentation/files/details/FileDetailsFragment.kt @@ -228,6 +228,7 @@ class FileDetailsFragment : FileFragment() { openInWebProviders.forEach { (openInWebProviderName, menuItemId) -> if (menuItemId == item.itemId) { fileDetailsViewModel.openInWeb(safeFile.file.remoteId!!, openInWebProviderName) + fileOperationsViewModel.setLastUsageFile(safeFile.file) return true } } @@ -244,6 +245,7 @@ class FileDetailsFragment : FileFragment() { fileDetailsViewModel.updateActionInDetailsView(SYNC_AND_OPEN_WITH) } else { // Already downloaded -> Open it requireActivity().openOCFile(safeFile.file) + fileOperationsViewModel.setLastUsageFile(safeFile.file) } true } 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..c0126845de2 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 @@ -525,6 +525,7 @@ class MainFileListFragment : Fragment(), itemIcon = ResourcesCompat.getDrawable(resources, R.drawable.ic_open_in_web, null) setOnClickListener { mainFileListViewModel.openInWeb(file.remoteId!!, appRegistryProvider.name) + fileOperationsViewModel.setLastUsageFile(file) } } fileOptionsBottomSheetSingleFileLayout!!.addView(appProviderItemView, 1) diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt index 09281d59b5b..10365cf30d7 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt @@ -899,6 +899,7 @@ class FileDisplayActivity : FileActivity(), override fun openFile(file: OCFile) { if (file.isAvailableLocally) { fileOperationsHelper.openFile(file) + fileOperationsViewModel.setLastUsageFile(file) } else { startDownloadForOpening(file) } From b96907b63a0159c9c69ad13d293d972e1f9c3c0c Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Thu, 2 Nov 2023 12:06:58 +0000 Subject: [PATCH 10/11] Added calens --- changelog/unreleased/4187 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/changelog/unreleased/4187 b/changelog/unreleased/4187 index e69de29bb2d..eff45a4bab5 100644 --- a/changelog/unreleased/4187 +++ b/changelog/unreleased/4187 @@ -0,0 +1,6 @@ +Enhancement: New field "last usage" in database + +To know the last usage of a file, a new field has been created in the database to handle this specific information. + +https://github.com/owncloud/android/issues/4173 +https://github.com/owncloud/android/pull/4187 From d83e9c629d488a89caa64221df416fe2edfab704 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Thu, 2 Nov 2023 12:08:24 +0000 Subject: [PATCH 11/11] Calens changelog updated --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96c4d6ac271..38f811d9121 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Summary * Enhancement - Unit tests for datasources classes - Part 3: [#4072](https://github.com/owncloud/android/issues/4072) * Enhancement - "Apply to all" when many name conflicts arise: [#4078](https://github.com/owncloud/android/issues/4078) * Enhancement - "Share to" in oCIS accounts allows upload to any space: [#4088](https://github.com/owncloud/android/issues/4088) +* Enhancement - New field "last usage" in database: [#4173](https://github.com/owncloud/android/issues/4173) * Enhancement - Use invoke operator to execute usecases: [#4179](https://github.com/owncloud/android/pull/4179) * Enhancement - Deep link open app correctly: [#4181](https://github.com/owncloud/android/issues/4181) @@ -61,6 +62,14 @@ Details https://github.com/owncloud/android/issues/4088 https://github.com/owncloud/android/pull/4160 +* Enhancement - New field "last usage" in database: [#4173](https://github.com/owncloud/android/issues/4173) + + To know the last usage of a file, a new field has been created in the database to handle this + specific information. + + https://github.com/owncloud/android/issues/4173 + https://github.com/owncloud/android/pull/4187 + * Enhancement - Use invoke operator to execute usecases: [#4179](https://github.com/owncloud/android/pull/4179) Removes all the "execute" verbosity for use cases by using the "invoke" operator instead.