|
2 | 2 | * Nextcloud - Android Client |
3 | 3 | * |
4 | 4 | * SPDX-FileCopyrightText: 2020 Chris Narkiewicz <hello@ezaquarii.com> |
| 5 | + * SPDX-FileCopyrightText: 2026 TSI-mc <surinder.kumar@t-systems.com> |
5 | 6 | * SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only |
6 | 7 | */ |
7 | 8 | package com.nextcloud.client.jobs |
@@ -32,6 +33,7 @@ import com.nextcloud.client.jobs.download.FileDownloadWorker |
32 | 33 | import com.nextcloud.client.jobs.folderDownload.FolderDownloadWorker |
33 | 34 | import com.nextcloud.client.jobs.metadata.MetadataWorker |
34 | 35 | import com.nextcloud.client.jobs.offlineOperations.OfflineOperationsWorker |
| 36 | +import com.nextcloud.client.jobs.upload.AlbumFileUploadWorker |
35 | 37 | import com.nextcloud.client.jobs.upload.FileUploadHelper |
36 | 38 | import com.nextcloud.client.jobs.upload.FileUploadWorker |
37 | 39 | import com.nextcloud.client.preferences.AppPreferences |
@@ -86,6 +88,7 @@ internal class BackgroundJobManagerImpl( |
86 | 88 | const val JOB_NOTIFICATION = "notification" |
87 | 89 | const val JOB_ACCOUNT_REMOVAL = "account_removal" |
88 | 90 | const val JOB_FILES_UPLOAD = "files_upload" |
| 91 | + const val ALBUM_JOB_FILES_UPLOAD = "album_files_upload" |
89 | 92 | const val JOB_FOLDER_DOWNLOAD = "folder_download" |
90 | 93 | const val JOB_FILES_DOWNLOAD = "files_download" |
91 | 94 | const val JOB_PDF_GENERATION = "pdf_generation" |
@@ -640,6 +643,8 @@ internal class BackgroundJobManagerImpl( |
640 | 643 |
|
641 | 644 | private fun startFileUploadJobTag(accountName: String): String = JOB_FILES_UPLOAD + accountName |
642 | 645 |
|
| 646 | + private fun startAlbumsFileUploadJobTag(accountName: String): String = ALBUM_JOB_FILES_UPLOAD + accountName |
| 647 | + |
643 | 648 | override fun isStartFileUploadJobScheduled(accountName: String): Boolean = |
644 | 649 | workManager.isWorkScheduled(startFileUploadJobTag(accountName)) |
645 | 650 |
|
@@ -703,6 +708,68 @@ internal class BackgroundJobManagerImpl( |
703 | 708 | } |
704 | 709 | } |
705 | 710 |
|
| 711 | + /** |
| 712 | + * This method supports uploading and copying selected files to Album |
| 713 | + * |
| 714 | + * @param user The user for whom the upload job is being created. |
| 715 | + * @param uploadIds Array of upload IDs to be processed. These IDs originate from multiple sources |
| 716 | + * and cannot be determined directly from the account name or a single function |
| 717 | + * within the worker. |
| 718 | + * @param albumName Album on which selected files should be copy after upload |
| 719 | + */ |
| 720 | + override fun startAlbumFilesUploadJob( |
| 721 | + user: User, |
| 722 | + uploadIds: LongArray, |
| 723 | + albumName: String, |
| 724 | + showSameFileAlreadyExistsNotification: Boolean |
| 725 | + ) { |
| 726 | + defaultDispatcherScope.launch { |
| 727 | + val batchSize = FileUploadHelper.MAX_FILE_COUNT |
| 728 | + val batches = uploadIds.toList().chunked(batchSize) |
| 729 | + val tag = startAlbumsFileUploadJobTag(user.accountName) |
| 730 | + |
| 731 | + val constraints = Constraints.Builder() |
| 732 | + .setRequiredNetworkType(NetworkType.CONNECTED) |
| 733 | + .build() |
| 734 | + |
| 735 | + val dataBuilder = Data.Builder() |
| 736 | + .putBoolean( |
| 737 | + FileUploadWorker.SHOW_SAME_FILE_ALREADY_EXISTS_NOTIFICATION, |
| 738 | + showSameFileAlreadyExistsNotification |
| 739 | + ) |
| 740 | + .putString(FileUploadWorker.ACCOUNT, user.accountName) |
| 741 | + .putInt(FileUploadWorker.TOTAL_UPLOAD_SIZE, uploadIds.size) |
| 742 | + .putString(AlbumFileUploadWorker.ALBUM_NAME, albumName) |
| 743 | + |
| 744 | + val workRequests = batches.mapIndexed { index, batch -> |
| 745 | + dataBuilder |
| 746 | + .putLongArray(FileUploadWorker.UPLOAD_IDS, batch.toLongArray()) |
| 747 | + .putInt(FileUploadWorker.CURRENT_BATCH_INDEX, index) |
| 748 | + |
| 749 | + oneTimeRequestBuilder(AlbumFileUploadWorker::class, ALBUM_JOB_FILES_UPLOAD, user) |
| 750 | + .addTag(tag) |
| 751 | + .setInputData(dataBuilder.build()) |
| 752 | + .setConstraints(constraints) |
| 753 | + .build() |
| 754 | + } |
| 755 | + |
| 756 | + // Chain the work requests sequentially |
| 757 | + if (workRequests.isNotEmpty()) { |
| 758 | + var workChain = workManager.beginUniqueWork( |
| 759 | + tag, |
| 760 | + ExistingWorkPolicy.APPEND_OR_REPLACE, |
| 761 | + workRequests.first() |
| 762 | + ) |
| 763 | + |
| 764 | + workRequests.drop(1).forEach { request -> |
| 765 | + workChain = workChain.then(request) |
| 766 | + } |
| 767 | + |
| 768 | + workChain.enqueue() |
| 769 | + } |
| 770 | + } |
| 771 | + } |
| 772 | + |
706 | 773 | private fun startFileDownloadJobTag(user: User, fileId: Long): String = |
707 | 774 | JOB_FOLDER_DOWNLOAD + user.accountName + fileId |
708 | 775 |
|
|
0 commit comments