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 395f9d37ad1..62ed2522e5d 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/UseCaseModule.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/UseCaseModule.kt @@ -5,7 +5,7 @@ * @author Abel García de Prada * @author Juan Carlos Garrote Gascón * - * Copyright (C) 2023 ownCloud GmbH. + * Copyright (C) 2024 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, @@ -87,6 +87,7 @@ import com.owncloud.android.domain.sharing.shares.usecases.GetShareAsLiveDataUse import com.owncloud.android.domain.sharing.shares.usecases.GetSharesAsLiveDataUseCase import com.owncloud.android.domain.sharing.shares.usecases.RefreshSharesFromServerAsyncUseCase import com.owncloud.android.domain.spaces.usecases.GetPersonalAndProjectSpacesForAccountUseCase +import com.owncloud.android.domain.spaces.usecases.GetPersonalAndSharesAndProjectSpacesForAccountUseCase import com.owncloud.android.domain.spaces.usecases.GetPersonalAndProjectSpacesWithSpecialsForAccountAsStreamUseCase import com.owncloud.android.domain.spaces.usecases.GetPersonalSpaceForAccountUseCase import com.owncloud.android.domain.spaces.usecases.GetProjectSpacesWithSpecialsForAccountAsStreamUseCase @@ -208,6 +209,7 @@ val useCaseModule = module { // Spaces factoryOf(::GetPersonalAndProjectSpacesForAccountUseCase) + factoryOf(::GetPersonalAndSharesAndProjectSpacesForAccountUseCase) factoryOf(::GetPersonalAndProjectSpacesWithSpecialsForAccountAsStreamUseCase) factoryOf(::GetPersonalSpaceForAccountUseCase) factoryOf(::GetProjectSpacesWithSpecialsForAccountAsStreamUseCase) diff --git a/owncloudApp/src/main/java/com/owncloud/android/workers/AccountDiscoveryWorker.kt b/owncloudApp/src/main/java/com/owncloud/android/workers/AccountDiscoveryWorker.kt index 4f04b576e61..605f837f48f 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/workers/AccountDiscoveryWorker.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/workers/AccountDiscoveryWorker.kt @@ -4,7 +4,7 @@ * @author Abel García de Prada * @author Juan Carlos Garrote Gascón * - * Copyright (C) 2023 ownCloud GmbH. + * Copyright (C) 2024 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, @@ -29,7 +29,8 @@ import com.owncloud.android.domain.capabilities.usecases.RefreshCapabilitiesFrom import com.owncloud.android.domain.files.model.OCFile import com.owncloud.android.domain.files.model.OCFile.Companion.ROOT_PATH import com.owncloud.android.domain.files.usecases.GetFileByRemotePathUseCase -import com.owncloud.android.domain.spaces.usecases.GetPersonalAndProjectSpacesForAccountUseCase +import com.owncloud.android.domain.spaces.model.OCSpace.Companion.SPACE_ID_SHARES +import com.owncloud.android.domain.spaces.usecases.GetPersonalAndSharesAndProjectSpacesForAccountUseCase import com.owncloud.android.domain.spaces.usecases.RefreshSpacesFromServerAsyncUseCase import com.owncloud.android.presentation.authentication.AccountUtils import com.owncloud.android.usecases.synchronization.SynchronizeFolderUseCase @@ -48,7 +49,7 @@ class AccountDiscoveryWorker( private val refreshCapabilitiesFromServerAsyncUseCase: RefreshCapabilitiesFromServerAsyncUseCase by inject() private val getStoredCapabilitiesUseCase: GetStoredCapabilitiesUseCase by inject() private val refreshSpacesFromServerAsyncUseCase: RefreshSpacesFromServerAsyncUseCase by inject() - private val getPersonalAndProjectSpacesForAccountUseCase: GetPersonalAndProjectSpacesForAccountUseCase by inject() + private val getPersonalAndSharesAndProjectSpacesForAccountUseCase: GetPersonalAndSharesAndProjectSpacesForAccountUseCase by inject() private val getFileByRemotePathUseCase: GetFileByRemotePathUseCase by inject() private val synchronizeFolderUseCase: SynchronizeFolderUseCase by inject() @@ -76,7 +77,7 @@ class AccountDiscoveryWorker( // 2.2 Account does support spaces refreshSpacesFromServerAsyncUseCase(RefreshSpacesFromServerAsyncUseCase.Params(accountName)) - val spaces = getPersonalAndProjectSpacesForAccountUseCase(GetPersonalAndProjectSpacesForAccountUseCase.Params(accountName)) + val spaces = getPersonalAndSharesAndProjectSpacesForAccountUseCase(GetPersonalAndSharesAndProjectSpacesForAccountUseCase.Params(accountName)) // First we discover the root of the personal space since it is the first thing seen after login val personalSpace = spaces.firstOrNull { it.isPersonal } @@ -88,7 +89,17 @@ class AccountDiscoveryWorker( } } - // Then we discover the root of the rest of spaces + // Then we discover the root of the shares space since it is accessible in just 1 click + val sharesSpace = spaces.firstOrNull { it.id == SPACE_ID_SHARES} + sharesSpace?.let { space -> + val rootFolderForSpace = + getFileByRemotePathUseCase(GetFileByRemotePathUseCase.Params(accountName, ROOT_PATH, space.root.id)).getDataOrNull() + rootFolderForSpace?.let { + discoverRootFolder(it) + } + } + + // And then we discover the root of the rest of spaces, which are accessible in 2 clicks val spacesWithoutPersonal = spaces.filterNot { it.isPersonal } spacesWithoutPersonal.forEach { space -> // Create the root file for each space diff --git a/owncloudData/src/main/java/com/owncloud/android/data/spaces/datasources/LocalSpacesDataSource.kt b/owncloudData/src/main/java/com/owncloud/android/data/spaces/datasources/LocalSpacesDataSource.kt index 5c238c88e06..5867ee9f55c 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/spaces/datasources/LocalSpacesDataSource.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/spaces/datasources/LocalSpacesDataSource.kt @@ -4,7 +4,7 @@ * @author Abel García de Prada * @author Juan Carlos Garrote Gascón * - * Copyright (C) 2023 ownCloud GmbH. + * Copyright (C) 2024 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, @@ -31,6 +31,7 @@ interface LocalSpacesDataSource { fun getSpacesFromEveryAccountAsStream(): Flow> fun getSpacesByDriveTypeWithSpecialsForAccountAsFlow(accountName: String, filterDriveTypes: Set): Flow> fun getPersonalAndProjectSpacesForAccount(accountName: String): List + fun getPersonalAndSharesAndProjectSpacesForAccount(accountName: String): List fun getSpaceWithSpecialsByIdForAccount(spaceId: String?, accountName: String): OCSpace fun getSpaceByIdForAccount(spaceId: String?, accountName: String): OCSpace? fun getWebDavUrlForSpace(spaceId: String?, accountName: String): String? diff --git a/owncloudData/src/main/java/com/owncloud/android/data/spaces/datasources/implementation/OCLocalSpacesDataSource.kt b/owncloudData/src/main/java/com/owncloud/android/data/spaces/datasources/implementation/OCLocalSpacesDataSource.kt index eaacf966810..851052a4f6b 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/spaces/datasources/implementation/OCLocalSpacesDataSource.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/spaces/datasources/implementation/OCLocalSpacesDataSource.kt @@ -4,7 +4,7 @@ * @author Abel García de Prada * @author Juan Carlos Garrote Gascón * - * Copyright (C) 2023 ownCloud GmbH. + * Copyright (C) 2024 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, @@ -102,6 +102,20 @@ class OCLocalSpacesDataSource( ).map { it.toModel() } } + override fun getPersonalAndSharesAndProjectSpacesForAccount(accountName: String): List { + val allSpaces = spacesDao.getSpacesByDriveTypeForAccount( + accountName = accountName, + filterDriveTypes = setOf(DRIVE_TYPE_PERSONAL, DRIVE_TYPE_PROJECT), + ).map { it.toModel() }.toMutableList() + spacesDao.getSpaceByIdForAccount( + spaceId = SPACE_ID_SHARES, + accountName = accountName + )?.let { + allSpaces.add(it.toModel()) + } + return allSpaces + } + override fun getSpaceWithSpecialsByIdForAccount(spaceId: String?, accountName: String): OCSpace { return spacesDao.getSpaceWithSpecialsByIdForAccount(spaceId, accountName).toModel() } diff --git a/owncloudData/src/main/java/com/owncloud/android/data/spaces/repository/OCSpacesRepository.kt b/owncloudData/src/main/java/com/owncloud/android/data/spaces/repository/OCSpacesRepository.kt index 0b7fd84e841..5c1a5ccfb23 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/spaces/repository/OCSpacesRepository.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/spaces/repository/OCSpacesRepository.kt @@ -4,7 +4,7 @@ * @author Abel García de Prada * @author Juan Carlos Garrote Gascón * - * Copyright (C) 2023 ownCloud GmbH. + * Copyright (C) 2024 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, @@ -48,6 +48,9 @@ class OCSpacesRepository( override fun getPersonalAndProjectSpacesForAccount(accountName: String) = localSpacesDataSource.getPersonalAndProjectSpacesForAccount(accountName) + override fun getPersonalAndSharesAndProjectSpacesForAccount(accountName: String) = + localSpacesDataSource.getPersonalAndSharesAndProjectSpacesForAccount(accountName) + override fun getSpaceWithSpecialsByIdForAccount(spaceId: String?, accountName: String) = localSpacesDataSource.getSpaceWithSpecialsByIdForAccount(spaceId, accountName) diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/spaces/SpacesRepository.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/spaces/SpacesRepository.kt index e6f1c1fbcf6..a9fe8469c2c 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/spaces/SpacesRepository.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/spaces/SpacesRepository.kt @@ -4,7 +4,7 @@ * @author Abel García de Prada * @author Juan Carlos Garrote Gascón * - * Copyright (C) 2023 ownCloud GmbH. + * Copyright (C) 2024 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, @@ -30,6 +30,7 @@ interface SpacesRepository { fun getSpacesByDriveTypeWithSpecialsForAccountAsFlow(accountName: String, filterDriveTypes: Set): Flow> fun getPersonalSpaceForAccount(accountName: String): OCSpace? fun getPersonalAndProjectSpacesForAccount(accountName: String): List + fun getPersonalAndSharesAndProjectSpacesForAccount(accountName: String): List fun getSpaceWithSpecialsByIdForAccount(spaceId: String?, accountName: String): OCSpace fun getSpaceByIdForAccount(spaceId: String?, accountName: String): OCSpace? fun getWebDavUrlForSpace(accountName: String, spaceId: String?): String? diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/spaces/usecases/GetPersonalAndSharesAndProjectSpacesForAccountUseCase.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/spaces/usecases/GetPersonalAndSharesAndProjectSpacesForAccountUseCase.kt new file mode 100644 index 00000000000..ba892927113 --- /dev/null +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/spaces/usecases/GetPersonalAndSharesAndProjectSpacesForAccountUseCase.kt @@ -0,0 +1,36 @@ +/** + * ownCloud Android client application + * + * @author Juan Carlos Garrote Gascón + * + * Copyright (C) 2024 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.spaces.usecases + +import com.owncloud.android.domain.BaseUseCase +import com.owncloud.android.domain.spaces.SpacesRepository +import com.owncloud.android.domain.spaces.model.OCSpace + +class GetPersonalAndSharesAndProjectSpacesForAccountUseCase( + private val spacesRepository: SpacesRepository +) : BaseUseCase, GetPersonalAndSharesAndProjectSpacesForAccountUseCase.Params>() { + + override fun run(params: Params) = spacesRepository.getPersonalAndSharesAndProjectSpacesForAccount(params.accountName) + + data class Params( + val accountName: String + ) +}