Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Technical] Use invoke operator to execute usecases #4179

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions owncloudApp/src/main/java/com/owncloud/android/MainApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class MainApp : Application() {

val getStoredCapabilitiesUseCase: GetStoredCapabilitiesUseCase by inject()
val capabilities = withContext(CoroutineScope(CoroutinesDispatcherProvider().io).coroutineContext) {
getStoredCapabilitiesUseCase.execute(
getStoredCapabilitiesUseCase(
GetStoredCapabilitiesUseCase.Params(
accountName = account.name
)
Expand All @@ -178,7 +178,7 @@ class MainApp : Application() {
if (spacesAllowed) {
val getPersonalSpaceForAccountUseCase: GetPersonalSpaceForAccountUseCase by inject()
personalSpace = withContext(CoroutineScope(CoroutinesDispatcherProvider().io).coroutineContext) {
getPersonalSpaceForAccountUseCase.execute(
getPersonalSpaceForAccountUseCase(
GetPersonalSpaceForAccountUseCase.Params(
accountName = account.name
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class FileDataStorageManager(
val getFileByRemotePathUseCase: GetFileByRemotePathUseCase by inject()

val result = withContext(CoroutineScope(CoroutinesDispatcherProvider().io).coroutineContext) {
getFileByRemotePathUseCase.execute(GetFileByRemotePathUseCase.Params(accountName, remotePath, spaceId))
getFileByRemotePathUseCase(GetFileByRemotePathUseCase.Params(accountName, remotePath, spaceId))
}.getDataOrNull()
result
}
Expand All @@ -65,7 +65,7 @@ class FileDataStorageManager(
val getPersonalRootFolderForAccountUseCase: GetPersonalRootFolderForAccountUseCase by inject()

val result = withContext(CoroutineScope(CoroutinesDispatcherProvider().io).coroutineContext) {
getPersonalRootFolderForAccountUseCase.execute(GetPersonalRootFolderForAccountUseCase.Params(account.name))
getPersonalRootFolderForAccountUseCase(GetPersonalRootFolderForAccountUseCase.Params(account.name))
}
result
}
Expand All @@ -74,7 +74,7 @@ class FileDataStorageManager(
val getSharesRootFolderForAccount: GetSharesRootFolderForAccount by inject()

val result = withContext(CoroutineScope(CoroutinesDispatcherProvider().io).coroutineContext) {
getSharesRootFolderForAccount.execute(GetSharesRootFolderForAccount.Params(account.name))
getSharesRootFolderForAccount(GetSharesRootFolderForAccount.Params(account.name))
}
result
}
Expand All @@ -84,7 +84,7 @@ class FileDataStorageManager(
val getFileByIdUseCase: GetFileByIdUseCase by inject()

val result = withContext(CoroutineScope(CoroutinesDispatcherProvider().io).coroutineContext) {
getFileByIdUseCase.execute(GetFileByIdUseCase.Params(id))
getFileByIdUseCase(GetFileByIdUseCase.Params(id))
}.getDataOrNull()
result
}
Expand All @@ -106,7 +106,7 @@ class FileDataStorageManager(

val result = withContext(CoroutineScope(CoroutinesDispatcherProvider().io).coroutineContext) {
// TODO: Remove !!
getFolderImagesUseCase.execute(GetFolderImagesUseCase.Params(folderId = folder!!.id!!))
getFolderImagesUseCase(GetFolderImagesUseCase.Params(folderId = folder!!.id!!))
}.getDataOrNull()
result ?: listOf()
}
Expand All @@ -116,7 +116,7 @@ class FileDataStorageManager(
val getFolderContentUseCase: GetFolderContentUseCase by inject()

val result = withContext(CoroutineScope(CoroutinesDispatcherProvider().io).coroutineContext) {
getFolderContentUseCase.execute(GetFolderContentUseCase.Params(parentId))
getFolderContentUseCase(GetFolderContentUseCase.Params(parentId))
}.getDataOrNull()
result ?: listOf()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private String getPreviewUrl(OCFile ocFile, Account account) {

if (ocFile.getSpaceId() != null) {
Lazy<GetWebDavUrlForSpaceUseCase> getWebDavUrlForSpaceUseCaseLazy = inject(GetWebDavUrlForSpaceUseCase.class);
baseUrl = getWebDavUrlForSpaceUseCaseLazy.getValue().execute(
baseUrl = getWebDavUrlForSpaceUseCaseLazy.getValue().invoke(
new GetWebDavUrlForSpaceUseCase.Params(ocFile.getOwner(), ocFile.getSpaceId())
);

Expand Down Expand Up @@ -317,7 +317,7 @@ private Bitmap doOCFileInBackground() {
}
if (status == HttpConstants.HTTP_OK || status == HttpConstants.HTTP_NOT_FOUND) {
@NotNull Lazy<DisableThumbnailsForFileUseCase> disableThumbnailsForFileUseCaseLazy = inject(DisableThumbnailsForFileUseCase.class);
disableThumbnailsForFileUseCaseLazy.getValue().execute(new DisableThumbnailsForFileUseCase.Params(file.getId()));
disableThumbnailsForFileUseCaseLazy.getValue().invoke(new DisableThumbnailsForFileUseCase.Params(file.getId()));
}
} catch (Exception e) {
Timber.e(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object ViewModelExt : KoinComponent {
return@launch
}

val useCaseResult = useCase.execute(useCaseParams)
val useCaseResult = useCase(useCaseParams)

Timber.d("Use case executed: ${useCase.javaClass.simpleName} with result: $useCaseResult")

Expand Down Expand Up @@ -101,7 +101,7 @@ object ViewModelExt : KoinComponent {
return@launch
}

val useCaseResult = useCase.execute(useCaseParams)
val useCaseResult = useCase(useCaseParams)

Timber.d("Use case executed: ${useCase.javaClass.simpleName} with result: $useCaseResult")

Expand Down Expand Up @@ -135,7 +135,7 @@ object ViewModelExt : KoinComponent {
return@launch
}

val useCaseResult = useCase.execute(useCaseParams)
val useCaseResult = useCase(useCaseParams)

Timber.d("Use case executed: ${useCase.javaClass.simpleName} with result: $useCaseResult")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SyncProfileOperation(
try {
CoroutineScope(Dispatchers.IO).launch {
val getUserInfoAsyncUseCase: GetUserInfoAsyncUseCase by inject()
val userInfoResult = getUserInfoAsyncUseCase.execute(GetUserInfoAsyncUseCase.Params(account.name))
val userInfoResult = getUserInfoAsyncUseCase(GetUserInfoAsyncUseCase.Params(account.name))
userInfoResult.getDataOrNull()?.let { userInfo ->
Timber.d("User info synchronized for account ${account.name}")

Expand All @@ -62,7 +62,7 @@ class SyncProfileOperation(

val refreshUserQuotaFromServerAsyncUseCase: RefreshUserQuotaFromServerAsyncUseCase by inject()
val userQuotaResult =
refreshUserQuotaFromServerAsyncUseCase.execute(
refreshUserQuotaFromServerAsyncUseCase(
RefreshUserQuotaFromServerAsyncUseCase.Params(
account.name
)
Expand All @@ -72,12 +72,12 @@ class SyncProfileOperation(

val getStoredCapabilitiesUseCase: GetStoredCapabilitiesUseCase by inject()

val storedCapabilities = getStoredCapabilitiesUseCase.execute(GetStoredCapabilitiesUseCase.Params(account.name))
val storedCapabilities = getStoredCapabilitiesUseCase(GetStoredCapabilitiesUseCase.Params(account.name))
val shouldFetchAvatar = storedCapabilities?.isFetchingAvatarAllowed() ?: true

if (shouldFetchAvatar) {
val getUserAvatarAsyncUseCase: GetUserAvatarAsyncUseCase by inject()
val userAvatarResult = getUserAvatarAsyncUseCase.execute(GetUserAvatarAsyncUseCase.Params(account.name))
val userAvatarResult = getUserAvatarAsyncUseCase(GetUserAvatarAsyncUseCase.Params(account.name))
AvatarManager().handleAvatarUseCaseResult(account, userAvatarResult)
if (userAvatarResult.isSuccess) {
Timber.d("Avatar synchronized for account ${account.name}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RemoveAccountDialogViewModel(

private fun initCameraUploadsConfiguration() {
viewModelScope.launch(coroutinesDispatcherProvider.io) {
cameraUploadsConfiguration = getCameraUploadsConfigurationUseCase.execute(Unit).getDataOrNull()
cameraUploadsConfiguration = getCameraUploadsConfigurationUseCase(Unit).getDataOrNull()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ private String refreshToken(
@NotNull Lazy<OIDCDiscoveryUseCase> oidcDiscoveryUseCase = inject(OIDCDiscoveryUseCase.class);
OIDCDiscoveryUseCase.Params oidcDiscoveryUseCaseParams = new OIDCDiscoveryUseCase.Params(baseUrl);
UseCaseResult<OIDCServerConfiguration> oidcServerConfigurationUseCaseResult =
oidcDiscoveryUseCase.getValue().execute(oidcDiscoveryUseCaseParams);
oidcDiscoveryUseCase.getValue().invoke(oidcDiscoveryUseCaseParams);

String tokenEndpoint;

Expand Down Expand Up @@ -380,7 +380,7 @@ private String refreshToken(
// Token exchange
@NotNull Lazy<RequestTokenUseCase> requestTokenUseCase = inject(RequestTokenUseCase.class);
RequestTokenUseCase.Params requestTokenParams = new RequestTokenUseCase.Params(oauthTokenRequest);
UseCaseResult<TokenResponse> tokenResponseResult = requestTokenUseCase.getValue().execute(requestTokenParams);
UseCaseResult<TokenResponse> tokenResponseResult = requestTokenUseCase.getValue().invoke(requestTokenParams);

TokenResponse safeTokenResponse = tokenResponseResult.getDataOrNull();
if (safeTokenResponse != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class AuthenticationViewModel(

// Authenticated WebFinger needed only for account creations. Logged accounts already know their instances.
if (updateAccountWithUsername == null) {
val ownCloudInstancesAvailable = getOwnCloudInstancesFromAuthenticatedWebFingerUseCase.execute(
val ownCloudInstancesAvailable = getOwnCloudInstancesFromAuthenticatedWebFingerUseCase(
GetOwnCloudInstancesFromAuthenticatedWebFingerUseCase.Params(
server = serverBaseUrl,
username = username,
Expand All @@ -164,7 +164,7 @@ class AuthenticationViewModel(
}
}

val useCaseResult = loginOAuthAsyncUseCase.execute(
val useCaseResult = loginOAuthAsyncUseCase(
LoginOAuthAsyncUseCase.Params(
serverInfo = serverInfo,
username = username,
Expand Down Expand Up @@ -260,14 +260,14 @@ class AuthenticationViewModel(
_accountDiscovery.postValue(Event(UIResult.Loading()))
viewModelScope.launch(coroutinesDispatcherProvider.io) {
// 1. Refresh capabilities for account
refreshCapabilitiesFromServerAsyncUseCase.execute(RefreshCapabilitiesFromServerAsyncUseCase.Params(accountName))
val capabilities = getStoredCapabilitiesUseCase.execute(GetStoredCapabilitiesUseCase.Params(accountName))
refreshCapabilitiesFromServerAsyncUseCase(RefreshCapabilitiesFromServerAsyncUseCase.Params(accountName))
val capabilities = getStoredCapabilitiesUseCase(GetStoredCapabilitiesUseCase.Params(accountName))

val spacesAvailableForAccount = capabilities?.isSpacesAllowed() == true

// 2 If Account does not support spaces we can skip this
if (spacesAvailableForAccount) {
refreshSpacesFromServerAsyncUseCase.execute(RefreshSpacesFromServerAsyncUseCase.Params(accountName))
refreshSpacesFromServerAsyncUseCase(RefreshSpacesFromServerAsyncUseCase.Params(accountName))
}
_accountDiscovery.postValue(Event(UIResult.Success()))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class AvatarManager : KoinComponent {

val shouldFetchAvatar = try {
val getStoredCapabilitiesUseCase: GetStoredCapabilitiesUseCase by inject()
val storedCapabilities = getStoredCapabilitiesUseCase.execute(GetStoredCapabilitiesUseCase.Params(account.name))
val storedCapabilities = getStoredCapabilitiesUseCase(GetStoredCapabilitiesUseCase.Params(account.name))
storedCapabilities?.isFetchingAvatarAllowed() ?: true
} catch (instanceCreationException: InstanceCreationException) {
Timber.e(instanceCreationException, "Koin may not be initialized at this point")
Expand All @@ -78,7 +78,7 @@ class AvatarManager : KoinComponent {
Timber.i("Avatar with imageKey $imageKey is not available in cache. Fetching from server...")
val getUserAvatarAsyncUseCase: GetUserAvatarAsyncUseCase by inject()
val useCaseResult =
getUserAvatarAsyncUseCase.execute(GetUserAvatarAsyncUseCase.Params(accountName = account.name))
getUserAvatarAsyncUseCase(GetUserAvatarAsyncUseCase.Params(accountName = account.name))
handleAvatarUseCaseResult(account, useCaseResult)?.let { return it }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CapabilityViewModel(
private val _capabilities = MediatorLiveData<Event<UIResult<OCCapability>>>()
val capabilities: LiveData<Event<UIResult<OCCapability>>> = _capabilities

private var capabilitiesLiveData: LiveData<OCCapability?> = getCapabilitiesAsLiveDataUseCase.execute(
private var capabilitiesLiveData: LiveData<OCCapability?> = getCapabilitiesAsLiveDataUseCase(
GetCapabilitiesAsLiveDataUseCase.Params(
accountName = accountName
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class DrawerViewModel(
val loggedAccounts = AccountUtils.getAccounts(context)
localStorageProvider.deleteUnusedUserDirs(loggedAccounts)

val userQuotas = getUserQuotasUseCase.execute(Unit)
val userQuotas = getUserQuotasUseCase(Unit)
val loggedAccountsNames = loggedAccounts.map { it.name }
val totalAccountsNames = userQuotas.map { it.accountName }
val removedAccountsNames = mutableListOf<String>()
Expand All @@ -91,7 +91,7 @@ class DrawerViewModel(
}
removedAccountsNames.forEach { removedAccountName ->
Timber.d("$removedAccountName is being removed")
removeAccountUseCase.execute(
removeAccountUseCase(
RemoveAccountUseCase.Params(accountName = removedAccountName)
)
localStorageProvider.removeLocalStorageForAccount(removedAccountName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ConflictsResolveViewModel(
) : ViewModel() {

val currentFile: StateFlow<OCFile?> =
getFileByIdAsStreamUseCase.execute(GetFileByIdAsStreamUseCase.Params(ocFile.id!!))
getFileByIdAsStreamUseCase(GetFileByIdAsStreamUseCase.Params(ocFile.id!!))
.stateIn(
viewModelScope,
started = SharingStarted.WhileSubscribed(),
Expand All @@ -53,7 +53,7 @@ class ConflictsResolveViewModel(
fun downloadFile() {
val fileToDownload = currentFile.value ?: return
viewModelScope.launch(coroutinesDispatcherProvider.io) {
downloadFileUseCase.execute(
downloadFileUseCase(
DownloadFileUseCase.Params(
accountName = fileToDownload.owner,
file = fileToDownload
Expand All @@ -65,7 +65,7 @@ class ConflictsResolveViewModel(
fun uploadFileInConflict() {
val fileToUpload = currentFile.value ?: return
viewModelScope.launch(coroutinesDispatcherProvider.io) {
uploadFileInConflictUseCase.execute(
uploadFileInConflictUseCase(
UploadFileInConflictUseCase.Params(
accountName = fileToUpload.owner,
localPath = fileToUpload.storagePath!!,
Expand All @@ -79,7 +79,7 @@ class ConflictsResolveViewModel(
fun uploadFileFromSystem() {
val fileToUpload = currentFile.value ?: return
viewModelScope.launch(coroutinesDispatcherProvider.io) {
uploadFilesFromSystemUseCase.execute(
uploadFilesFromSystemUseCase(
UploadFilesFromSystemUseCase.Params(
accountName = fileToUpload.owner,
listOfLocalPaths = listOf(fileToUpload.storagePath!!),
Expand Down
Loading