Skip to content

Commit

Permalink
Merge pull request #3718 from owncloud/new_arch/uploads_screen
Browse files Browse the repository at this point in the history
[New Arch] UploadListFragment isolation
  • Loading branch information
JuancaG05 authored Aug 16, 2022
2 parents a14fe20 + fb84615 commit 33e2311
Show file tree
Hide file tree
Showing 38 changed files with 1,080 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ import com.owncloud.android.domain.sharing.shares.usecases.EditPublicShareAsyncU
import com.owncloud.android.domain.sharing.shares.usecases.GetShareAsLiveDataUseCase
import com.owncloud.android.domain.sharing.shares.usecases.GetSharesAsLiveDataUseCase
import com.owncloud.android.domain.sharing.shares.usecases.RefreshSharesFromServerAsyncUseCase
import com.owncloud.android.domain.transfers.usecases.ClearFailedTransfersUseCase
import com.owncloud.android.domain.transfers.usecases.ClearSuccessfulTransfersUseCase
import com.owncloud.android.domain.transfers.usecases.DeleteTransferWithIdUseCase
import com.owncloud.android.domain.transfers.usecases.GetAllTransfersAsLiveDataUseCase
import com.owncloud.android.domain.user.usecases.GetStoredQuotaUseCase
import com.owncloud.android.domain.user.usecases.GetUserAvatarAsyncUseCase
import com.owncloud.android.domain.user.usecases.GetUserInfoAsyncUseCase
Expand All @@ -79,9 +83,14 @@ import com.owncloud.android.usecases.transfers.downloads.DownloadFileUseCase
import com.owncloud.android.usecases.transfers.downloads.GetLiveDataForDownloadingFileUseCase
import com.owncloud.android.usecases.transfers.downloads.GetLiveDataForFinishedDownloadsFromAccountUseCase
import com.owncloud.android.usecases.transfers.uploads.CancelUploadForFileUseCase
import com.owncloud.android.usecases.transfers.uploads.CancelUploadWithIdUseCase
import com.owncloud.android.usecases.transfers.uploads.RetryFailedUploadsUseCase
import com.owncloud.android.usecases.transfers.uploads.RetryUploadFromContentUriUseCase
import com.owncloud.android.usecases.transfers.uploads.RetryUploadFromSystemUseCase
import com.owncloud.android.usecases.transfers.uploads.UploadFileFromContentUriUseCase
import com.owncloud.android.usecases.transfers.uploads.UploadFileFromSystemUseCase
import com.owncloud.android.usecases.transfers.uploads.UploadFileInConflictUseCase
import com.owncloud.android.usecases.transfers.uploads.UploadFilesFromSAFUseCase
import com.owncloud.android.usecases.transfers.uploads.UploadFilesFromContentUriUseCase
import com.owncloud.android.usecases.transfers.uploads.UploadFilesFromSystemUseCase
import org.koin.dsl.module

Expand Down Expand Up @@ -143,11 +152,20 @@ val useCaseModule = module {
factory { DownloadFileUseCase(get()) }
factory { GetLiveDataForDownloadingFileUseCase(get()) }
factory { GetLiveDataForFinishedDownloadsFromAccountUseCase(get()) }
factory { UploadFilesFromSAFUseCase(get(), get()) }
factory { UploadFileFromSystemUseCase(get()) }
factory { UploadFileFromContentUriUseCase(get()) }
factory { UploadFilesFromContentUriUseCase(get(), get()) }
factory { UploadFilesFromSystemUseCase(get(), get()) }
factory { UploadFileInConflictUseCase(get(), get()) }
factory { CancelUploadForFileUseCase(get(), get()) }
factory { RetryUploadFromSystemUseCase(get(), get()) }
factory { RetryUploadFromSystemUseCase(get(), get(), get()) }
factory { RetryUploadFromContentUriUseCase(get(), get(), get()) }
factory { GetAllTransfersAsLiveDataUseCase(get()) }
factory { CancelUploadWithIdUseCase(get(), get()) }
factory { DeleteTransferWithIdUseCase(get()) }
factory { ClearFailedTransfersUseCase(get()) }
factory { RetryFailedUploadsUseCase(get(), get(), get(), get()) }
factory { ClearSuccessfulTransfersUseCase(get()) }

// User
factory { GetStoredQuotaUseCase(get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@ val viewModelModule = module {
viewModel { FileDetailsViewModel(get(), get(), get(), get(), get()) }
viewModel { FileOperationsViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) }
viewModel { MainFileListViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) }
viewModel { TransfersViewModel(get(), get(), get()) }
viewModel { TransfersViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* ownCloud Android client application
*
* @author Juan Carlos Garrote Gascón
*
* Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
*/

package com.owncloud.android.extensions

import androidx.annotation.StringRes
import com.owncloud.android.R
import com.owncloud.android.domain.transfers.model.OCTransfer
import com.owncloud.android.domain.transfers.model.TransferResult
import com.owncloud.android.domain.transfers.model.TransferStatus

@StringRes
fun OCTransfer.statusToStringRes(): Int {
return when (status) {
TransferStatus.TRANSFER_IN_PROGRESS -> R.string.uploader_upload_in_progress_ticker
TransferStatus.TRANSFER_SUCCEEDED -> R.string.uploads_view_upload_status_succeeded
TransferStatus.TRANSFER_QUEUED -> R.string.uploads_view_upload_status_queued
TransferStatus.TRANSFER_FAILED -> when (lastResult) {
TransferResult.CREDENTIAL_ERROR -> R.string.uploads_view_upload_status_failed_credentials_error
TransferResult.FOLDER_ERROR -> R.string.uploads_view_upload_status_failed_folder_error
TransferResult.FILE_NOT_FOUND -> R.string.uploads_view_upload_status_failed_localfile_error
TransferResult.FILE_ERROR -> R.string.uploads_view_upload_status_failed_file_error
TransferResult.PRIVILEGES_ERROR -> R.string.uploads_view_upload_status_failed_permission_error
TransferResult.NETWORK_CONNECTION -> R.string.uploads_view_upload_status_failed_connection_error
TransferResult.DELAYED_FOR_WIFI -> R.string.uploads_view_upload_status_waiting_for_wifi
TransferResult.CONFLICT_ERROR -> R.string.uploads_view_upload_status_conflict
TransferResult.SERVICE_INTERRUPTED -> R.string.uploads_view_upload_status_service_interrupted
TransferResult.SERVICE_UNAVAILABLE -> R.string.service_unavailable
TransferResult.QUOTA_EXCEEDED -> R.string.failed_upload_quota_exceeded_text
TransferResult.SSL_RECOVERABLE_PEER_UNVERIFIED -> R.string.ssl_certificate_not_trusted
TransferResult.UNKNOWN -> R.string.uploads_view_upload_status_unknown_fail
// Should not get here; cancelled uploads should be wiped out
TransferResult.CANCELLED -> R.string.uploads_view_upload_status_cancelled
// Should not get here; status should be UPLOAD_SUCCESS
TransferResult.UPLOADED -> R.string.uploads_view_upload_status_succeeded
// We don't know the specific forbidden error message because it is not being saved in transfers storage
TransferResult.SPECIFIC_FORBIDDEN -> R.string.uploader_upload_forbidden
// We don't know the specific unavailable service error message because it is not being saved in transfers storage
TransferResult.SPECIFIC_SERVICE_UNAVAILABLE -> R.string.service_unavailable
// We don't know the specific unsupported media type error message because it is not being saved in transfers storage
TransferResult.SPECIFIC_UNSUPPORTED_MEDIA_TYPE -> R.string.uploads_view_unsupported_media_type
// Should not get here; status should be not null
null -> R.string.uploads_view_upload_status_unknown_fail
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* ownCloud Android client application
*
* @author Abel García de Prada
* Copyright (C) 2021 ownCloud GmbH.
* @author Juan Carlos Garrote Gascón
*
* Copyright (C) 2022 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,
Expand All @@ -16,9 +18,11 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.owncloud.android.extensions

import android.accounts.Account
import androidx.lifecycle.LiveData
import androidx.work.WorkInfo
import androidx.work.WorkManager
import androidx.work.WorkQuery
Expand All @@ -35,6 +39,13 @@ val FINISHED_WORK_STATUS = listOf(WorkInfo.State.SUCCEEDED, WorkInfo.State.FAILE
fun WorkManager.getWorkInfoByTags(tags: List<String>): List<WorkInfo> =
this.getWorkInfos(buildWorkQuery(tags = tags)).get().filter { it.tags.containsAll(tags) }

/**
* Get a list of WorkInfo of running workers as LiveData that matches at least one of the tags.
*/
fun WorkManager.getRunningUploadsWorkInfosLiveData(tags: List<String>): LiveData<List<WorkInfo>> {
return getWorkInfosLiveData(buildWorkQuery(tags = tags, states = listOf(WorkInfo.State.RUNNING)))
}

/**
* Check if a download is pending. It could be enqueued, downloading or blocked.
* @param account - Owner of the file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
import android.accounts.Account;
import android.content.Context;

import androidx.work.WorkManager;
import com.owncloud.android.data.OwncloudDatabase;
import com.owncloud.android.data.transfers.datasources.implementation.OCLocalTransferDataSource;
import com.owncloud.android.data.transfers.repository.OCTransferRepository;
import com.owncloud.android.domain.files.model.OCFile;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
Expand Down Expand Up @@ -231,10 +227,8 @@ protected RemoteOperationResult run(OwnCloudClient client) {
* @param file OCFile object representing the file to upload
*/
private void requestForUpload(OCFile file) {
WorkManager workManager = WorkManager.getInstance(mContext);
// Workaround... should be removed as soon as possible
OCTransferRepository transferRepository = new OCTransferRepository(new OCLocalTransferDataSource(OwncloudDatabase.Companion.getDatabase(mContext).transferDao()));
UploadFileInConflictUseCase uploadFileInConflictUseCase = new UploadFileInConflictUseCase(workManager, transferRepository);
@NotNull Lazy<UploadFileInConflictUseCase> uploadFileInConflictUseCaseLazy = inject(UploadFileInConflictUseCase.class);
UploadFileInConflictUseCase uploadFileInConflictUseCase = uploadFileInConflictUseCaseLazy.getValue();
UploadFileInConflictUseCase.Params params = new UploadFileInConflictUseCase.Params(
file.getOwner(),
file.getStoragePath(),
Expand Down
Loading

0 comments on commit 33e2311

Please sign in to comment.