Skip to content

Commit

Permalink
Merge pull request #12303 from nextcloud/refactor/use-work-manager-fo…
Browse files Browse the repository at this point in the history
…r-upload

Use Only Work Manager For File Upload
  • Loading branch information
alperozturk96 authored Dec 21, 2023
2 parents c612d7a + f1bd5f1 commit 5fb9115
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,10 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
val file = getDummyFile("chunkedFile.txt")

FileUploader.uploadNewFile(
targetContext,
user,
file.absolutePath,
"/testFile.txt",
FileUploader.LOCAL_BEHAVIOUR_COPY,
null,
true,
UploadFileOperation.CREATED_BY_USER,
false,
Expand Down Expand Up @@ -258,12 +256,10 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
val file = getDummyFile("nonEmpty.txt")

FileUploader.uploadNewFile(
targetContext,
user,
file.absolutePath,
"/testFile.txt",
FileUploader.LOCAL_BEHAVIOUR_COPY,
null,
true,
UploadFileOperation.CREATED_BY_USER,
false,
Expand Down Expand Up @@ -369,12 +365,10 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
val file = getDummyFile("chunkedFile.txt")

FileUploader.uploadNewFile(
targetContext,
user,
file.absolutePath,
"/testFile.txt",
FileUploader.LOCAL_BEHAVIOUR_COPY,
null,
true,
UploadFileOperation.CREATED_BY_USER,
false,
Expand Down Expand Up @@ -476,12 +470,10 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
val file = getDummyFile("chunkedFile.txt")

FileUploader.uploadNewFile(
targetContext,
user,
file.absolutePath,
"/testFile.txt",
FileUploader.LOCAL_BEHAVIOUR_COPY,
null,
true,
UploadFileOperation.CREATED_BY_USER,
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import com.owncloud.android.files.services.FileUploader
import com.owncloud.android.files.services.NameCollisionPolicy
import com.owncloud.android.operations.UploadFileOperation
import com.owncloud.android.ui.helpers.FileOperationsHelper
import com.owncloud.android.utils.MimeType
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -184,16 +183,10 @@ class DocumentScanViewModel @Inject constructor(
uploadFolder + OCFile.PATH_SEPARATOR + File(it).name
}.toTypedArray()

val mimetypes = pageList.map {
MimeType.JPEG
}.toTypedArray()

FileUploader.uploadNewFile(
getApplication(),
currentAccountProvider.user,
pageList.toTypedArray(),
uploadPaths,
mimetypes,
FileUploader.LOCAL_BEHAVIOUR_DELETE,
true,
UploadFileOperation.CREATED_BY_USER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import com.owncloud.android.files.services.FileUploader
import com.owncloud.android.files.services.NameCollisionPolicy
import com.owncloud.android.operations.UploadFileOperation
import com.owncloud.android.ui.notifications.NotificationUtils
import com.owncloud.android.utils.MimeType
import com.owncloud.android.utils.theme.ViewThemeUtils
import java.io.File
import java.security.SecureRandom
Expand Down Expand Up @@ -124,12 +123,10 @@ class GeneratePdfFromImagesWork(
val uploadPath = uploadFolder + OCFile.PATH_SEPARATOR + File(pdfPath).name

FileUploader.uploadNewFile(
appContext,
user,
pdfPath,
uploadPath,
FileUploader.LOCAL_BEHAVIOUR_DELETE, // MIME type will be detected from file name
MimeType.PDF,
true,
UploadFileOperation.CREATED_BY_USER,
false,
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/com/nextcloud/client/jobs/FilesSyncWork.kt
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ class FilesSyncWork(
}
val localPaths = pathsAndMimes.map { it.first }.toTypedArray()
val remotePaths = pathsAndMimes.map { it.second }.toTypedArray()
val mimetypes = pathsAndMimes.map { it.third }.toTypedArray()

if (lightVersion) {
needsCharging = resources.getBoolean(R.bool.syncedFolder_light_on_charging)
Expand All @@ -177,12 +176,11 @@ class FilesSyncWork(
needsWifi = syncedFolder.isWifiOnly
uploadAction = syncedFolder.uploadAction
}

FileUploader.uploadNewFile(
context,
user,
localPaths,
remotePaths,
mimetypes,
uploadAction!!,
true, // create parent folder if not existent
UploadFileOperation.CREATED_AS_INSTANT_PICTURE,
Expand Down
Loading

0 comments on commit 5fb9115

Please sign in to comment.