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

[New Arch] UploadListFragment isolation #3718

Merged
merged 23 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
746fffc
Created new TransferListFragment
JuancaG05 Jul 19, 2022
d5bcae4
Added basic RecyclerView to TransferListFragment
JuancaG05 Jul 19, 2022
7d73782
Added new usecase to show all the transfers in the transfers screen
JuancaG05 Jul 19, 2022
413ba80
Adapted usecase, domain layer and data layer to return LiveData when …
JuancaG05 Jul 19, 2022
b52342b
Added values to some more elements of the transfer item view
JuancaG05 Jul 20, 2022
d9d073b
Added the different buttons of the transfer item view
JuancaG05 Jul 21, 2022
e6942c7
Fix KtLint errors
JuancaG05 Jul 21, 2022
d4d15a7
Added headers to transfers' RecyclerView
JuancaG05 Aug 1, 2022
90ce873
List of transfers ordered like this: current, queued, failed, uploaded
JuancaG05 Aug 2, 2022
1997dae
Fixed KtLint errors
JuancaG05 Aug 2, 2022
0de7456
Retry and clear buttons working
JuancaG05 Aug 2, 2022
1a285a7
Added DiffUtil to transfers list to make it smoother
JuancaG05 Aug 3, 2022
78d2727
Unify the way of performing the uploads usecases and fix some workaro…
JuancaG05 Aug 8, 2022
37936f3
Fix some KtLint errors
JuancaG05 Aug 9, 2022
ec2a34c
Fix retry uploads creating duplicated files
JuancaG05 Aug 9, 2022
978d2f1
Generate uploads thumbnails with Glide
JuancaG05 Aug 9, 2022
c7a1861
First version of progress bar in uploads screen
JuancaG05 Aug 9, 2022
b11b328
Progress bar in uploads screen with proper architecture
JuancaG05 Aug 10, 2022
d0791b8
Tiny visual improvements in transfers' RecyclerView
JuancaG05 Aug 10, 2022
d0bd780
Fix injection for share with ownCloud and tiny naming improvements
JuancaG05 Aug 12, 2022
c6a28b4
CR changes applied
JuancaG05 Aug 16, 2022
f276c40
Tiny renaming improvements
JuancaG05 Aug 16, 2022
fb84615
Fix KtLint report
JuancaG05 Aug 16, 2022
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
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