-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix(receivers): upload #16317
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
Merged
+184
−226
Merged
fix(receivers): upload #16317
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cfb8c2b
fix(receivers): upload
alperozturk96 c997917
add documentation and simplify
alperozturk96 f281768
add documentation and simplify
alperozturk96 8ca761a
delete unused functions
alperozturk96 30eea76
add upload finish event for auto upload worker
alperozturk96 db21780
add upload finish event for auto upload worker
alperozturk96 07d7c1f
add upload finish event for auto upload worker
alperozturk96 71a2ed3
add upload started, added event
alperozturk96 fa5a187
Update app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadB…
alperozturk96 b64db5e
Update app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadB…
alperozturk96 74b2ad3
Update app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadB…
alperozturk96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadBroadcastManager.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| * Nextcloud - Android Client | ||
| * | ||
| * SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com> | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only | ||
| */ | ||
| package com.nextcloud.client.jobs.upload | ||
|
|
||
| import android.content.Context | ||
| import android.content.Intent | ||
| import androidx.localbroadcastmanager.content.LocalBroadcastManager | ||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult | ||
| import com.owncloud.android.lib.common.utils.Log_OC | ||
| import com.owncloud.android.operations.UploadFileOperation | ||
|
|
||
| /** | ||
| * Manages local broadcasts related to file upload lifecycle events. | ||
| * | ||
| * This class is responsible for notifying components about upload | ||
| * queue changes and upload state transitions (added, started, finished). | ||
| * | ||
| * All broadcasts are sent via [LocalBroadcastManager]. | ||
| */ | ||
| class FileUploadBroadcastManager(private val broadcastManager: LocalBroadcastManager) { | ||
|
|
||
| companion object { | ||
| private const val TAG = "📣" + "FileUploadBroadcastManager" | ||
|
|
||
| const val UPLOAD_ADDED = "UPLOAD_ADDED" | ||
| const val UPLOAD_STARTED = "UPLOAD_STARTED" | ||
| const val UPLOAD_FINISHED = "UPLOAD_FINISHED" | ||
| } | ||
|
|
||
| /** | ||
| * Sends a broadcast to indicate that an upload has been added to the database. | ||
| * | ||
| * ### Triggered when | ||
| * - [UploadFileOperation] added | ||
| * | ||
| * ### Observed by | ||
| * - [com.owncloud.android.ui.activity.UploadListActivity.UploadFinishReceiver] | ||
| * | ||
| */ | ||
| fun sendAdded(context: Context) { | ||
| Log_OC.d(TAG, "upload added broadcast sent") | ||
| val intent = Intent(UPLOAD_ADDED).apply { | ||
| setPackage(context.packageName) | ||
| } | ||
| broadcastManager.sendBroadcast(intent) | ||
| } | ||
|
|
||
| /** | ||
| * Sends a broadcast indicating that an upload started. | ||
| * | ||
| * ### Triggered when | ||
| * - [UploadFileOperation] started | ||
| * | ||
| * ### Observed by | ||
| * - [com.owncloud.android.ui.activity.UploadListActivity.UploadFinishReceiver] | ||
| * | ||
| */ | ||
| fun sendStarted(upload: UploadFileOperation, context: Context) { | ||
| Log_OC.d(TAG, "upload started broadcast sent") | ||
| val intent = Intent(UPLOAD_STARTED).apply { | ||
| putExtra(FileUploadWorker.EXTRA_REMOTE_PATH, upload.remotePath) // real remote | ||
| putExtra(FileUploadWorker.EXTRA_OLD_FILE_PATH, upload.originalStoragePath) | ||
| putExtra(FileUploadWorker.ACCOUNT_NAME, upload.user.accountName) | ||
| setPackage(context.packageName) | ||
| } | ||
| broadcastManager.sendBroadcast(intent) | ||
| } | ||
|
|
||
| /** | ||
| * Sends a broadcast indicating that an upload has finished, either | ||
| * successfully or with an error. | ||
| * | ||
| * ### Triggered when | ||
| * - [UploadFileOperation] completes execution | ||
| * | ||
| * ### Observed by | ||
| * - [com.owncloud.android.ui.activity.FileDisplayActivity.UploadFinishReceiver] | ||
| * - [com.owncloud.android.ui.activity.UploadListActivity.UploadFinishReceiver] | ||
| * - [com.owncloud.android.ui.preview.PreviewImageActivity.UploadFinishReceiver] | ||
| * | ||
| */ | ||
| fun sendFinished( | ||
| upload: UploadFileOperation, | ||
| uploadResult: RemoteOperationResult<*>, | ||
| unlinkedFromRemotePath: String?, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what this variable name refers to. I think we should either change this name or add a short explanation. |
||
| context: Context | ||
| ) { | ||
| Log_OC.d(TAG, "upload finished broadcast sent") | ||
| val intent = Intent(UPLOAD_FINISHED).apply { | ||
| // real remote path, after possible automatic renaming | ||
| putExtra(FileUploadWorker.EXTRA_REMOTE_PATH, upload.remotePath) | ||
| if (upload.wasRenamed()) { | ||
| upload.oldFile?.let { | ||
| putExtra(FileUploadWorker.EXTRA_OLD_REMOTE_PATH, it.remotePath) | ||
| } | ||
| } | ||
| putExtra(FileUploadWorker.EXTRA_OLD_FILE_PATH, upload.originalStoragePath) | ||
| putExtra(FileUploadWorker.ACCOUNT_NAME, upload.user.accountName) | ||
| putExtra(FileUploadWorker.EXTRA_UPLOAD_RESULT, uploadResult.isSuccess) | ||
| if (unlinkedFromRemotePath != null) { | ||
| putExtra(FileUploadWorker.EXTRA_LINKED_TO_PATH, unlinkedFromRemotePath) | ||
| } | ||
| setPackage(context.packageName) | ||
| } | ||
| broadcastManager.sendBroadcast(intent) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we should keep track of the calling and receiving functions, as they might change in the future. We would then have remember to manually adjust these comments.
Same for
sendStarted()andsendFinished().