Skip to content

Commit

Permalink
CR corrections - Deleted code from previous database, id lastUsage is…
Browse files Browse the repository at this point in the history
… not nullable and moved setLastUsageFile to FileOperationsViewModel.
  • Loading branch information
Aitorbp committed Nov 2, 2023
1 parent ae6a009 commit 0f06c1d
Show file tree
Hide file tree
Showing 21 changed files with 37 additions and 38 deletions.
Empty file added changelog/unreleased/4187
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ val viewModelModule = module {
viewModelOf(::BiometricViewModel)
viewModelOf(::DrawerViewModel)
viewModelOf(::FileDetailsViewModel)
viewModelOf(::FileOperationsViewModel)
viewModelOf(::LogListViewModel)
viewModelOf(::OAuthViewModel)
viewModelOf(::PatternViewModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ class FileDetailsFragment : FileFragment() {

else -> fileDisplayActivity.openOCFile(fileWaitingToPreview)
}
fileDetailsViewModel.setLastUsageFile(fileWaitingToPreview)
fileOperationsViewModel.setLastUsageFile(fileWaitingToPreview)
}

override fun updateViewForSyncInProgress() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, " +
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ interface FileDao {
permissions = null,
treeEtag = "",
availableOfflineStatus = NOT_AVAILABLE_OFFLINE.ordinal,
lastUsage = null
)
)
}
Expand Down Expand Up @@ -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?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 0f06c1d

Please sign in to comment.