cancelDownloadsForAccountUseCaseLazy = inject(CancelDownloadsForAccountUseCase.class);
+ CancelUploadsFromAccountUseCase cancelUploadsFromAccountUseCase = cancelUploadsFromAccountUseCaseLazy.getValue();
cancelUploadsFromAccountUseCase.execute(new CancelUploadsFromAccountUseCase.Params(account.name));
-
- CancelDownloadsForAccountUseCase cancelDownloadsForAccountUseCase =
- new CancelDownloadsForAccountUseCase(WorkManager.getInstance(getBaseContext()));
+ CancelDownloadsForAccountUseCase cancelDownloadsForAccountUseCase = cancelDownloadsForAccountUseCaseLazy.getValue();
cancelDownloadsForAccountUseCase.execute(new CancelDownloadsForAccountUseCase.Params(account));
}
diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java
index 3969893cd8c..625d50287e6 100755
--- a/owncloudApp/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java
+++ b/owncloudApp/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java
@@ -1,11 +1,13 @@
-/**
+/*
* ownCloud Android client application
*
* @author LukeOwncloud
* @author David A. Velasco
* @author masensio
* @author Christian Schabesberger
- * Copyright (C) 2020 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,
@@ -19,6 +21,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
+
package com.owncloud.android.ui.activity;
import android.accounts.Account;
@@ -30,27 +33,25 @@
import android.view.View;
import androidx.fragment.app.FragmentTransaction;
-import androidx.work.WorkManager;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils;
-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.datamodel.OCUpload;
import com.owncloud.android.datamodel.UploadsStorageManager;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.operations.CheckCurrentCredentialsOperation;
+import com.owncloud.android.presentation.ui.transfers.TransferListFragment;
import com.owncloud.android.ui.fragment.UploadListFragment;
import com.owncloud.android.usecases.transfers.uploads.RetryFailedUploadsForAccountUseCase;
-import com.owncloud.android.usecases.transfers.uploads.RetryUploadFromContentUriUseCase;
-import com.owncloud.android.usecases.transfers.uploads.RetryUploadFromSystemUseCase;
-import com.owncloud.android.usecases.transfers.uploads.UploadFilesFromSystemUseCase;
import com.owncloud.android.utils.MimetypeIconUtil;
+import kotlin.Lazy;
+import org.jetbrains.annotations.NotNull;
import timber.log.Timber;
import java.io.File;
+import static org.koin.java.KoinJavaComponent.inject;
+
/**
* Activity listing pending, active, and completed uploads. User can delete
* completed uploads from view. Content of this list of coming from
@@ -90,7 +91,8 @@ protected void onCreate(Bundle savedInstanceState) {
}
private void createUploadListFragment() {
- UploadListFragment uploadList = new UploadListFragment();
+ //UploadListFragment uploadList = new UploadListFragment();
+ TransferListFragment uploadList = new TransferListFragment();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.left_fragment_container, uploadList, TAG_UPLOAD_LIST_FRAGMENT);
transaction.commit();
@@ -148,13 +150,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (account == null) {
return;
}
- // Workaround... should be removed as soon as possible
- OCTransferRepository transferRepository = new OCTransferRepository(new OCLocalTransferDataSource(OwncloudDatabase.Companion.getDatabase(this).transferDao()));
- RetryUploadFromContentUriUseCase retryUploadFromContentUriUseCase = new RetryUploadFromContentUriUseCase(this, transferRepository);
- WorkManager workManager = WorkManager.getInstance(this);
- UploadFilesFromSystemUseCase uploadFilesFromSystemUseCase = new UploadFilesFromSystemUseCase(workManager, transferRepository);
- RetryUploadFromSystemUseCase retryUploadFromSystemUseCase = new RetryUploadFromSystemUseCase(uploadFilesFromSystemUseCase, transferRepository);
- RetryFailedUploadsForAccountUseCase retryFailedUploadsForAccountUseCase = new RetryFailedUploadsForAccountUseCase(this, retryUploadFromContentUriUseCase, retryUploadFromSystemUseCase, transferRepository);
+ @NotNull Lazy retryFailedUploadsForAccountUseCaseLazy = inject(RetryFailedUploadsForAccountUseCase.class);
+ RetryFailedUploadsForAccountUseCase retryFailedUploadsForAccountUseCase = retryFailedUploadsForAccountUseCaseLazy.getValue();
retryFailedUploadsForAccountUseCase.execute(new RetryFailedUploadsForAccountUseCase.Params(account.name));
}
}
@@ -176,13 +173,8 @@ public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationRe
} else {
// already updated -> just retry!
- // Workaround... should be removed as soon as possible
- OCTransferRepository transferRepository = new OCTransferRepository(new OCLocalTransferDataSource(OwncloudDatabase.Companion.getDatabase(this).transferDao()));
- RetryUploadFromContentUriUseCase retryUploadFromContentUriUseCase = new RetryUploadFromContentUriUseCase(this, transferRepository);
- WorkManager workManager = WorkManager.getInstance(this);
- UploadFilesFromSystemUseCase uploadFilesFromSystemUseCase = new UploadFilesFromSystemUseCase(workManager, transferRepository);
- RetryUploadFromSystemUseCase retryUploadFromSystemUseCase = new RetryUploadFromSystemUseCase(uploadFilesFromSystemUseCase, transferRepository);
- RetryFailedUploadsForAccountUseCase retryFailedUploadsForAccountUseCase = new RetryFailedUploadsForAccountUseCase(this, retryUploadFromContentUriUseCase, retryUploadFromSystemUseCase, transferRepository);
+ @NotNull Lazy retryFailedUploadsForAccountUseCaseLazy = inject(RetryFailedUploadsForAccountUseCase.class);
+ RetryFailedUploadsForAccountUseCase retryFailedUploadsForAccountUseCase = retryFailedUploadsForAccountUseCaseLazy.getValue();
retryFailedUploadsForAccountUseCase.execute(new RetryFailedUploadsForAccountUseCase.Params(account.name));
}
diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/adapter/ExpandableUploadListAdapter.java b/owncloudApp/src/main/java/com/owncloud/android/ui/adapter/ExpandableUploadListAdapter.java
index cc0878f7449..821a0eed983 100755
--- a/owncloudApp/src/main/java/com/owncloud/android/ui/adapter/ExpandableUploadListAdapter.java
+++ b/owncloudApp/src/main/java/com/owncloud/android/ui/adapter/ExpandableUploadListAdapter.java
@@ -40,19 +40,16 @@
import androidx.appcompat.widget.AppCompatButton;
import androidx.documentfile.provider.DocumentFile;
-import androidx.work.WorkManager;
import com.google.android.material.snackbar.Snackbar;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils;
-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.datamodel.OCUpload;
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
import com.owncloud.android.datamodel.UploadsStorageManager;
import com.owncloud.android.datamodel.UploadsStorageManager.UploadStatus;
import com.owncloud.android.db.UploadResult;
import com.owncloud.android.domain.files.model.OCFile;
+import com.owncloud.android.domain.transfers.TransferRepository;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
import com.owncloud.android.ui.activity.FileActivity;
@@ -61,10 +58,11 @@
import com.owncloud.android.usecases.transfers.uploads.CancelUploadWithIdUseCase;
import com.owncloud.android.usecases.transfers.uploads.RetryUploadFromContentUriUseCase;
import com.owncloud.android.usecases.transfers.uploads.RetryUploadFromSystemUseCase;
-import com.owncloud.android.usecases.transfers.uploads.UploadFilesFromSystemUseCase;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.MimetypeIconUtil;
import com.owncloud.android.utils.PreferenceUtils;
+import kotlin.Lazy;
+import org.jetbrains.annotations.NotNull;
import timber.log.Timber;
import java.io.File;
@@ -75,6 +73,7 @@
import java.util.Observer;
import static com.owncloud.android.db.PreferenceManager.PREF__CAMERA_UPLOADS_DEFAULT_PATH;
+import static org.koin.java.KoinJavaComponent.inject;
/**
* This Adapter populates a ListView with following types of uploads: pending,
@@ -312,8 +311,8 @@ private View getView(OCUpload[] uploadsItems, int position, View convertView, Vi
rightButton.setImageResource(R.drawable.ic_action_cancel_grey);
rightButton.setVisibility(View.VISIBLE);
rightButton.setOnClickListener(v -> {
- OCTransferRepository transferRepository = new OCTransferRepository(new OCLocalTransferDataSource(OwncloudDatabase.Companion.getDatabase(v.getContext()).transferDao()));
- CancelUploadWithIdUseCase cancelUploadWithIdUseCase = new CancelUploadWithIdUseCase(WorkManager.getInstance(parent.getContext()), transferRepository);
+ @NotNull Lazy cancelUploadWithIdUseCaseLazy = inject(CancelUploadWithIdUseCase.class);
+ CancelUploadWithIdUseCase cancelUploadWithIdUseCase = cancelUploadWithIdUseCaseLazy.getValue();
cancelUploadWithIdUseCase.execute(new CancelUploadWithIdUseCase.Params(upload.getUploadId()));
refreshView();
});
@@ -323,7 +322,8 @@ private View getView(OCUpload[] uploadsItems, int position, View convertView, Vi
rightButton.setImageResource(R.drawable.ic_action_delete_grey);
rightButton.setVisibility(View.VISIBLE);
rightButton.setOnClickListener(v -> {
- OCTransferRepository transferRepository = new OCTransferRepository(new OCLocalTransferDataSource(OwncloudDatabase.Companion.getDatabase(v.getContext()).transferDao()));
+ @NotNull Lazy transferRepositoryLazy = inject(TransferRepository.class);
+ TransferRepository transferRepository = transferRepositoryLazy.getValue();
transferRepository.removeTransferById(upload.getUploadId());
refreshView();
});
@@ -346,18 +346,14 @@ private View getView(OCUpload[] uploadsItems, int position, View convertView, Vi
public void onClick(View v) {
File file = new File(upload.getLocalPath());
if (file.exists()) {
- OCTransferRepository transferRepository = new OCTransferRepository(new OCLocalTransferDataSource(OwncloudDatabase.Companion.getDatabase(v.getContext()).transferDao()));
- WorkManager workManager = WorkManager.getInstance(v.getContext());
- UploadFilesFromSystemUseCase uploadFilesFromSystemUseCase = new UploadFilesFromSystemUseCase(workManager, transferRepository);
- RetryUploadFromSystemUseCase retryUploadFromSystemUseCase = new RetryUploadFromSystemUseCase(uploadFilesFromSystemUseCase, transferRepository);
+ @NotNull Lazy retryUploadFromSystemUseCaseLazy = inject(RetryUploadFromSystemUseCase.class);
+ RetryUploadFromSystemUseCase retryUploadFromSystemUseCase = retryUploadFromSystemUseCaseLazy.getValue();
RetryUploadFromSystemUseCase.Params useCaseParams = new RetryUploadFromSystemUseCase.Params(upload.getUploadId());
retryUploadFromSystemUseCase.execute(useCaseParams);
refreshView();
} else if (DocumentFile.isDocumentUri(v.getContext(), Uri.parse(upload.getLocalPath()))) {
- // Workaround... should be removed as soon as possible
- OCTransferRepository transferRepository = new OCTransferRepository(new OCLocalTransferDataSource(OwncloudDatabase.Companion.getDatabase(v.getContext()).transferDao()));
- RetryUploadFromContentUriUseCase retryUploadFromContentUriUseCase =
- new RetryUploadFromContentUriUseCase(v.getContext(), transferRepository);
+ @NotNull Lazy retryUploadFromContentUriUseCaseLazy = inject(RetryUploadFromContentUriUseCase.class);
+ RetryUploadFromContentUriUseCase retryUploadFromContentUriUseCase = retryUploadFromContentUriUseCaseLazy.getValue();
RetryUploadFromContentUriUseCase.Params useCaseParams = new RetryUploadFromContentUriUseCase.Params(
upload.getUploadId()
);
diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/asynctasks/CopyAndUploadContentUrisTask.java b/owncloudApp/src/main/java/com/owncloud/android/ui/asynctasks/CopyAndUploadContentUrisTask.java
index 12004270846..3cbbf35d161 100644
--- a/owncloudApp/src/main/java/com/owncloud/android/ui/asynctasks/CopyAndUploadContentUrisTask.java
+++ b/owncloudApp/src/main/java/com/owncloud/android/ui/asynctasks/CopyAndUploadContentUrisTask.java
@@ -28,16 +28,13 @@
import android.os.AsyncTask;
import android.widget.Toast;
-import androidx.work.WorkManager;
import com.owncloud.android.R;
-import com.owncloud.android.data.OwncloudDatabase;
-import com.owncloud.android.data.transfers.datasources.implementation.OCLocalTransferDataSource;
-import com.owncloud.android.data.transfers.db.TransferDao;
-import com.owncloud.android.data.transfers.repository.OCTransferRepository;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.usecases.transfers.uploads.UploadFilesFromSystemUseCase;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.UriUtils;
+import kotlin.Lazy;
+import org.jetbrains.annotations.NotNull;
import timber.log.Timber;
import java.io.File;
@@ -47,6 +44,8 @@
import java.lang.ref.WeakReference;
import java.util.ArrayList;
+import static org.koin.java.KoinJavaComponent.inject;
+
/**
* AsyncTask to copy a file from a uri in a temporal file
*/
@@ -162,10 +161,8 @@ protected ResultCode doInBackground(Object[] params) {
}
filesToUpload.add(fullTempPath);
- WorkManager workManager = WorkManager.getInstance(mAppContext);
- // Workaround... should be removed as soon as possible
- OCTransferRepository transferRepository = new OCTransferRepository(new OCLocalTransferDataSource(OwncloudDatabase.Companion.getDatabase(mAppContext).transferDao()));
- UploadFilesFromSystemUseCase uploadFilesFromSystemUseCase = new UploadFilesFromSystemUseCase(workManager, transferRepository);
+ @NotNull Lazy uploadFilesFromSystemUseCaseLazy = inject(UploadFilesFromSystemUseCase.class);
+ UploadFilesFromSystemUseCase uploadFilesFromSystemUseCase = uploadFilesFromSystemUseCaseLazy.getValue();
UploadFilesFromSystemUseCase.Params useCaseParams = new UploadFilesFromSystemUseCase.Params(
account.name,
filesToUpload,
diff --git a/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/UploadListFragment.java b/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/UploadListFragment.java
index 48b4ed47d5f..85f9159ceac 100755
--- a/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/UploadListFragment.java
+++ b/owncloudApp/src/main/java/com/owncloud/android/ui/fragment/UploadListFragment.java
@@ -26,22 +26,19 @@
import android.widget.ExpandableListView;
import android.widget.ListView;
-import androidx.work.WorkManager;
import com.owncloud.android.R;
-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.datamodel.OCUpload;
import com.owncloud.android.datamodel.UploadsStorageManager;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.adapter.ExpandableUploadListAdapter;
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.UploadFilesFromSystemUseCase;
+import kotlin.Lazy;
import kotlin.Unit;
+import org.jetbrains.annotations.NotNull;
import timber.log.Timber;
+import static org.koin.java.KoinJavaComponent.inject;
+
/**
* A Fragment that lists all files and folders in a given LOCAL path.
*
@@ -124,13 +121,8 @@ public void onClick(OptionsInUploadList option) {
switch (option) {
case RETRY_FAILED:
- // Workaround... should be removed as soon as possible
- OCTransferRepository transferRepository = new OCTransferRepository(new OCLocalTransferDataSource(OwncloudDatabase.Companion.getDatabase(requireContext()).transferDao()));
- RetryUploadFromContentUriUseCase retryUploadFromContentUriUseCase = new RetryUploadFromContentUriUseCase(requireContext(), transferRepository);
- WorkManager workManager = WorkManager.getInstance(requireContext());
- UploadFilesFromSystemUseCase uploadFilesFromSystemUseCase = new UploadFilesFromSystemUseCase(workManager, transferRepository);
- RetryUploadFromSystemUseCase retryUploadFromSystemUseCase = new RetryUploadFromSystemUseCase(uploadFilesFromSystemUseCase, transferRepository);
- RetryFailedUploadsUseCase retryFailedUploadsUseCase = new RetryFailedUploadsUseCase(requireContext(), retryUploadFromContentUriUseCase, retryUploadFromSystemUseCase, transferRepository);
+ @NotNull Lazy retryFailedUploadsUseCaseLazy = inject(RetryFailedUploadsUseCase.class);
+ RetryFailedUploadsUseCase retryFailedUploadsUseCase = retryFailedUploadsUseCaseLazy.getValue();
retryFailedUploadsUseCase.execute(Unit.INSTANCE);
break;
case CLEAR_FAILED:
diff --git a/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/RetryUploadFromContentUriUseCase.kt b/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/RetryUploadFromContentUriUseCase.kt
index 23a8f3b8f68..347f12734fd 100644
--- a/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/RetryUploadFromContentUriUseCase.kt
+++ b/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/RetryUploadFromContentUriUseCase.kt
@@ -21,15 +21,18 @@
package com.owncloud.android.usecases.transfers.uploads
-import android.content.Context
import androidx.core.net.toUri
+import androidx.work.WorkInfo
import androidx.work.WorkManager
import com.owncloud.android.domain.BaseUseCase
import com.owncloud.android.domain.camerauploads.model.UploadBehavior
import com.owncloud.android.domain.transfers.TransferRepository
+import com.owncloud.android.extensions.getWorkInfoByTags
+import com.owncloud.android.workers.UploadFileFromContentUriWorker
class RetryUploadFromContentUriUseCase(
- private val context: Context,
+ private val workManager: WorkManager,
+ private val uploadFileFromContentUriUseCase: UploadFileFromContentUriUseCase,
private val transferRepository: TransferRepository,
) : BaseUseCase() {
@@ -38,19 +41,30 @@ class RetryUploadFromContentUriUseCase(
uploadToRetry ?: return
- val workManager = WorkManager.getInstance(context)
- UploadFileFromContentUriUseCase(workManager).execute(
- UploadFileFromContentUriUseCase.Params(
- accountName = uploadToRetry.accountName,
- contentUri = uploadToRetry.localPath.toUri(),
- lastModifiedInSeconds = (uploadToRetry.transferEndTimestamp?.div(1000)).toString(),
- behavior = UploadBehavior.fromLegacyLocalBehavior(uploadToRetry.localBehaviour).name,
- uploadPath = uploadToRetry.remotePath,
- uploadIdInStorageManager = uploadToRetry.id!!,
- wifiOnly = false,
- chargingOnly = false
+ transferRepository.updateTransferStatusToEnqueuedById(params.uploadIdInStorageManager)
+
+ val workInfo = workManager.getWorkInfoByTags(
+ listOf(
+ params.uploadIdInStorageManager.toString(),
+ uploadToRetry.accountName,
+ UploadFileFromContentUriWorker::class.java.name
)
)
+
+ if (workInfo.firstOrNull()?.state == WorkInfo.State.FAILED) {
+ uploadFileFromContentUriUseCase.execute(
+ UploadFileFromContentUriUseCase.Params(
+ accountName = uploadToRetry.accountName,
+ contentUri = uploadToRetry.localPath.toUri(),
+ lastModifiedInSeconds = (uploadToRetry.transferEndTimestamp?.div(1000)).toString(),
+ behavior = UploadBehavior.fromLegacyLocalBehavior(uploadToRetry.localBehaviour).name,
+ uploadPath = uploadToRetry.remotePath,
+ uploadIdInStorageManager = params.uploadIdInStorageManager,
+ wifiOnly = false,
+ chargingOnly = false
+ )
+ )
+ }
}
data class Params(
diff --git a/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/RetryUploadFromSystemUseCase.kt b/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/RetryUploadFromSystemUseCase.kt
index e1e898a0326..88328876c2f 100644
--- a/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/RetryUploadFromSystemUseCase.kt
+++ b/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/RetryUploadFromSystemUseCase.kt
@@ -21,12 +21,17 @@
package com.owncloud.android.usecases.transfers.uploads
+import androidx.work.WorkInfo
+import androidx.work.WorkManager
import com.owncloud.android.domain.BaseUseCase
-import com.owncloud.android.domain.files.model.OCFile.Companion.PATH_SEPARATOR
+import com.owncloud.android.domain.camerauploads.model.UploadBehavior
import com.owncloud.android.domain.transfers.TransferRepository
+import com.owncloud.android.extensions.getWorkInfoByTags
+import com.owncloud.android.workers.UploadFileFromFileSystemWorker
class RetryUploadFromSystemUseCase(
- private val uploadFilesFromSystemUseCase: UploadFilesFromSystemUseCase,
+ private val workManager: WorkManager,
+ private val uploadFileFromSystemUseCase: UploadFileFromSystemUseCase,
private val transferRepository: TransferRepository,
) : BaseUseCase() {
@@ -35,13 +40,28 @@ class RetryUploadFromSystemUseCase(
uploadToRetry ?: return
- uploadFilesFromSystemUseCase.execute(
- UploadFilesFromSystemUseCase.Params(
- accountName = uploadToRetry.accountName,
- listOfLocalPaths = listOf(uploadToRetry.localPath),
- uploadFolderPath = uploadToRetry.remotePath.trimEnd(PATH_SEPARATOR),
+ transferRepository.updateTransferStatusToEnqueuedById(params.uploadIdInStorageManager)
+
+ val workInfo = workManager.getWorkInfoByTags(
+ listOf(
+ params.uploadIdInStorageManager.toString(),
+ uploadToRetry.accountName,
+ UploadFileFromFileSystemWorker::class.java.name
)
)
+
+ if (workInfo.firstOrNull()?.state == WorkInfo.State.FAILED) {
+ uploadFileFromSystemUseCase.execute(
+ UploadFileFromSystemUseCase.Params(
+ accountName = uploadToRetry.accountName,
+ localPath = uploadToRetry.localPath,
+ lastModifiedInSeconds = (uploadToRetry.transferEndTimestamp?.div(1000)).toString(),
+ behavior = UploadBehavior.fromLegacyLocalBehavior(uploadToRetry.localBehaviour).name,
+ uploadPath = uploadToRetry.remotePath,
+ uploadIdInStorageManager = params.uploadIdInStorageManager
+ )
+ )
+ }
}
data class Params(
diff --git a/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFileFromContentUriUseCase.kt b/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFileFromContentUriUseCase.kt
index bedafea4d4b..9c2f39d0bc7 100644
--- a/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFileFromContentUriUseCase.kt
+++ b/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFileFromContentUriUseCase.kt
@@ -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,
@@ -16,6 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
+
package com.owncloud.android.usecases.transfers.uploads
import android.net.Uri
@@ -33,19 +36,6 @@ class UploadFileFromContentUriUseCase(
) : BaseUseCase() {
override fun run(params: Params) {
- /**
- * There will be different ways to upload files.
- *
- * PLAIN, CHUNKS(not implemented yet), TUS(not implemented yet)
- *
- * We will choose the way to upload the file depending on capabilities and file size.
- * This check should be done in this use case.
- *
- */
- enqueuePlainUpload(params)
- }
-
- private fun enqueuePlainUpload(params: Params) {
val inputData = workDataOf(
UploadFileFromContentUriWorker.KEY_PARAM_ACCOUNT_NAME to params.accountName,
UploadFileFromContentUriWorker.KEY_PARAM_BEHAVIOR to params.behavior,
diff --git a/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFileFromSystemUseCase.kt b/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFileFromSystemUseCase.kt
new file mode 100644
index 00000000000..6560b44b713
--- /dev/null
+++ b/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFileFromSystemUseCase.kt
@@ -0,0 +1,69 @@
+/**
+ * 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 .
+ */
+
+package com.owncloud.android.usecases.transfers.uploads
+
+import androidx.work.Constraints
+import androidx.work.NetworkType
+import androidx.work.OneTimeWorkRequestBuilder
+import androidx.work.WorkManager
+import androidx.work.workDataOf
+import com.owncloud.android.domain.BaseUseCase
+import com.owncloud.android.workers.UploadFileFromFileSystemWorker
+import timber.log.Timber
+
+class UploadFileFromSystemUseCase(
+ private val workManager: WorkManager
+) : BaseUseCase() {
+
+ override fun run(params: Params) {
+ val inputData = workDataOf(
+ UploadFileFromFileSystemWorker.KEY_PARAM_ACCOUNT_NAME to params.accountName,
+ UploadFileFromFileSystemWorker.KEY_PARAM_BEHAVIOR to params.behavior,
+ UploadFileFromFileSystemWorker.KEY_PARAM_LOCAL_PATH to params.localPath,
+ UploadFileFromFileSystemWorker.KEY_PARAM_LAST_MODIFIED to params.lastModifiedInSeconds,
+ UploadFileFromFileSystemWorker.KEY_PARAM_UPLOAD_PATH to params.uploadPath,
+ UploadFileFromFileSystemWorker.KEY_PARAM_UPLOAD_ID to params.uploadIdInStorageManager
+ )
+
+ val constraints = Constraints.Builder()
+ .setRequiredNetworkType(NetworkType.CONNECTED)
+ .build()
+
+ val uploadFileFromSystemWorker = OneTimeWorkRequestBuilder()
+ .setInputData(inputData)
+ .setConstraints(constraints)
+ .addTag(params.accountName)
+ .addTag(params.uploadIdInStorageManager.toString())
+ .build()
+
+ workManager.enqueue(uploadFileFromSystemWorker)
+ Timber.i("Plain upload of ${params.localPath} has been enqueued.")
+ }
+
+ data class Params(
+ val accountName: String,
+ val localPath: String,
+ val lastModifiedInSeconds: String,
+ val behavior: String,
+ val uploadPath: String,
+ val uploadIdInStorageManager: Long,
+ )
+}
diff --git a/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFileInConflictUseCase.kt b/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFileInConflictUseCase.kt
index 2a4fc50f384..1503528270f 100644
--- a/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFileInConflictUseCase.kt
+++ b/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFileInConflictUseCase.kt
@@ -103,7 +103,7 @@ class UploadFileInConflictUseCase(
val inputData = workDataOf(
UploadFileFromFileSystemWorker.KEY_PARAM_ACCOUNT_NAME to accountName,
UploadFileFromFileSystemWorker.KEY_PARAM_BEHAVIOR to UploadBehavior.COPY.name,
- UploadFileFromFileSystemWorker.KEY_PARAM_CONTENT_URI to localPath,
+ UploadFileFromFileSystemWorker.KEY_PARAM_LOCAL_PATH to localPath,
UploadFileFromFileSystemWorker.KEY_PARAM_LAST_MODIFIED to lastModifiedInSeconds,
UploadFileFromFileSystemWorker.KEY_PARAM_UPLOAD_PATH to uploadPath,
UploadFileFromFileSystemWorker.KEY_PARAM_UPLOAD_ID to uploadIdInStorageManager,
diff --git a/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFilesFromSAFUseCase.kt b/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFilesFromContentUriUseCase.kt
similarity index 94%
rename from owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFilesFromSAFUseCase.kt
rename to owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFilesFromContentUriUseCase.kt
index cbf5d212a55..42234549956 100644
--- a/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFilesFromSAFUseCase.kt
+++ b/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFilesFromContentUriUseCase.kt
@@ -23,7 +23,6 @@ package com.owncloud.android.usecases.transfers.uploads
import android.net.Uri
import androidx.documentfile.provider.DocumentFile
-import androidx.work.WorkManager
import com.owncloud.android.MainApp
import com.owncloud.android.domain.BaseUseCase
import com.owncloud.android.domain.camerauploads.model.UploadBehavior
@@ -40,10 +39,10 @@ import java.io.File
*
* It stores the upload in the database and then enqueue a new worker to upload the single file
*/
-class UploadFilesFromSAFUseCase(
- private val workManager: WorkManager,
+class UploadFilesFromContentUriUseCase(
+ private val uploadFileFromContentUriUseCase: UploadFileFromContentUriUseCase,
private val transferRepository: TransferRepository,
-) : BaseUseCase() {
+) : BaseUseCase() {
override fun run(params: Params) {
params.listOfContentUris.forEach { contentUri ->
@@ -98,7 +97,6 @@ class UploadFilesFromSAFUseCase(
uploadIdInStorageManager: Long,
uploadPath: String,
) {
- val uploadFileFromContentUriUseCase = UploadFileFromContentUriUseCase(workManager)
val uploadFileParams = UploadFileFromContentUriUseCase.Params(
contentUri = contentUri,
uploadPath = uploadPath,
diff --git a/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFilesFromSystemUseCase.kt b/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFilesFromSystemUseCase.kt
index c9912a1d152..c8fa0abbfbf 100644
--- a/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFilesFromSystemUseCase.kt
+++ b/owncloudApp/src/main/java/com/owncloud/android/usecases/transfers/uploads/UploadFilesFromSystemUseCase.kt
@@ -21,17 +21,11 @@
package com.owncloud.android.usecases.transfers.uploads
-import androidx.work.Constraints
-import androidx.work.NetworkType
-import androidx.work.OneTimeWorkRequestBuilder
-import androidx.work.WorkManager
-import androidx.work.workDataOf
import com.owncloud.android.domain.BaseUseCase
import com.owncloud.android.domain.camerauploads.model.UploadBehavior
import com.owncloud.android.domain.transfers.TransferRepository
import com.owncloud.android.domain.transfers.model.OCTransfer
import com.owncloud.android.domain.transfers.model.TransferStatus
-import com.owncloud.android.workers.UploadFileFromFileSystemWorker
import timber.log.Timber
import java.io.File
@@ -48,7 +42,7 @@ import java.io.File
* It stores the upload in the database and then enqueue a new worker to upload the single file
*/
class UploadFilesFromSystemUseCase(
- private val workManager: WorkManager,
+ private val uploadFileFromSystemUseCase: UploadFileFromSystemUseCase,
private val transferRepository: TransferRepository,
) : BaseUseCase() {
@@ -105,27 +99,15 @@ class UploadFilesFromSystemUseCase(
uploadIdInStorageManager: Long,
uploadPath: String,
) {
- val inputData = workDataOf(
- UploadFileFromFileSystemWorker.KEY_PARAM_ACCOUNT_NAME to accountName,
- UploadFileFromFileSystemWorker.KEY_PARAM_BEHAVIOR to UploadBehavior.MOVE.name,
- UploadFileFromFileSystemWorker.KEY_PARAM_CONTENT_URI to localPath,
- UploadFileFromFileSystemWorker.KEY_PARAM_LAST_MODIFIED to lastModifiedInSeconds,
- UploadFileFromFileSystemWorker.KEY_PARAM_UPLOAD_PATH to uploadPath,
- UploadFileFromFileSystemWorker.KEY_PARAM_UPLOAD_ID to uploadIdInStorageManager
+ val uploadFileParams = UploadFileFromSystemUseCase.Params(
+ accountName = accountName,
+ localPath = localPath,
+ lastModifiedInSeconds = lastModifiedInSeconds,
+ behavior = UploadBehavior.MOVE.toString(),
+ uploadPath = uploadPath,
+ uploadIdInStorageManager = uploadIdInStorageManager
)
-
- val constraints = Constraints.Builder()
- .setRequiredNetworkType(NetworkType.CONNECTED)
- .build()
-
- val uploadFileFromContentUriWorker = OneTimeWorkRequestBuilder()
- .setInputData(inputData)
- .setConstraints(constraints)
- .addTag(accountName)
- .build()
-
- workManager.enqueue(uploadFileFromContentUriWorker)
- Timber.i("Plain upload of $localPath has been enqueued.")
+ uploadFileFromSystemUseCase.execute(uploadFileParams)
}
data class Params(
diff --git a/owncloudApp/src/main/java/com/owncloud/android/workers/UploadFileFromFileSystemWorker.kt b/owncloudApp/src/main/java/com/owncloud/android/workers/UploadFileFromFileSystemWorker.kt
index 30eec9b1f7d..9060ea52570 100644
--- a/owncloudApp/src/main/java/com/owncloud/android/workers/UploadFileFromFileSystemWorker.kt
+++ b/owncloudApp/src/main/java/com/owncloud/android/workers/UploadFileFromFileSystemWorker.kt
@@ -144,7 +144,7 @@ class UploadFileFromFileSystemWorker(
val paramUploadPath = workerParameters.inputData.getString(KEY_PARAM_UPLOAD_PATH)
val paramLastModified = workerParameters.inputData.getString(KEY_PARAM_LAST_MODIFIED)
val paramBehavior = workerParameters.inputData.getString(KEY_PARAM_BEHAVIOR)
- val paramFileSystemUri = workerParameters.inputData.getString(KEY_PARAM_CONTENT_URI)
+ val paramFileSystemUri = workerParameters.inputData.getString(KEY_PARAM_LOCAL_PATH)
val paramUploadId = workerParameters.inputData.getLong(KEY_PARAM_UPLOAD_ID, -1)
account = AccountUtils.getOwnCloudAccountByName(appContext, paramAccountName) ?: return false
@@ -353,7 +353,7 @@ class UploadFileFromFileSystemWorker(
companion object {
const val KEY_PARAM_ACCOUNT_NAME = "KEY_PARAM_ACCOUNT_NAME"
const val KEY_PARAM_BEHAVIOR = "KEY_PARAM_BEHAVIOR"
- const val KEY_PARAM_CONTENT_URI = "KEY_PARAM_CONTENT_URI"
+ const val KEY_PARAM_LOCAL_PATH = "KEY_PARAM_LOCAL_PATH"
const val KEY_PARAM_LAST_MODIFIED = "KEY_PARAM_LAST_MODIFIED"
const val KEY_PARAM_UPLOAD_PATH = "KEY_PARAM_UPLOAD_PATH"
const val KEY_PARAM_UPLOAD_ID = "KEY_PARAM_UPLOAD_ID"
diff --git a/owncloudApp/src/main/res/layout/fragment_transfer_list.xml b/owncloudApp/src/main/res/layout/fragment_transfer_list.xml
new file mode 100644
index 00000000000..ed329bbd67d
--- /dev/null
+++ b/owncloudApp/src/main/res/layout/fragment_transfer_list.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
diff --git a/owncloudApp/src/main/res/layout/upload_list_group.xml b/owncloudApp/src/main/res/layout/upload_list_group.xml
index 0f4f43cb456..9e6ed4b8063 100755
--- a/owncloudApp/src/main/res/layout/upload_list_group.xml
+++ b/owncloudApp/src/main/res/layout/upload_list_group.xml
@@ -41,9 +41,10 @@
android:layout_width="wrap_content"
android:layout_height="0dp"
android:visibility="gone"
+ android:layout_marginStart="13dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/uploadListGroupName"
- tools:text="@string/action_upload_clear"
+ android:text="@string/action_upload_clear"
tools:visibility="visible" />
diff --git a/owncloudApp/src/main/res/layout/upload_list_item.xml b/owncloudApp/src/main/res/layout/upload_list_item.xml
index 394f3c73abc..72f5803be2e 100755
--- a/owncloudApp/src/main/res/layout/upload_list_item.xml
+++ b/owncloudApp/src/main/res/layout/upload_list_item.xml
@@ -1,14 +1,13 @@
-
+ android:filterTouchesWhenObscured="true">
+ android:scaleType="centerCrop"
+ tools:src="@drawable/ic_menu_archive" />
@@ -41,7 +41,7 @@
android:ellipsize="middle"
android:singleLine="true"
android:textColor="@color/textColor"
- android:text="@string/placeholder_filename"
+ tools:text="@string/placeholder_filename"
android:textSize="16sp" />
@@ -92,7 +90,7 @@
android:layout_height="wrap_content"
android:textColor="@color/list_item_lastmod_and_filesize_text"
android:singleLine="true"
- android:text="@string/auth_username"
+ tools:text="@string/auth_username"
android:textSize="12dip" />
Current