Skip to content

Commit 1cbea54

Browse files
committed
add documentation and simplify
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent ea92187 commit 1cbea54

5 files changed

Lines changed: 42 additions & 24 deletions

File tree

app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadBroadcastManager.kt

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Nextcloud - Android Client
33
*
4-
* SPDX-FileCopyrightText: 2023 Alper Ozturk <alper.ozturk@nextcloud.com>
4+
* SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com>
55
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH
66
* SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
77
*/
@@ -25,13 +25,23 @@ import com.owncloud.android.operations.UploadFileOperation
2525
class FileUploadBroadcastManager(private val broadcastManager: LocalBroadcastManager) {
2626

2727
companion object {
28-
private const val TAG = "📣" + "FileUploadBroadcastManager"
28+
private const val TAG = "📣" + "FileUploadBroadcastManager"
2929

3030
const val UPLOAD_ADDED = "UPLOAD_ADDED"
31-
const val UPLOAD_STARTED = "UPLOAD_START"
32-
const val UPLOAD_FINISHED = "UPLOAD_FINISH"
31+
const val UPLOAD_STARTED = "UPLOAD_STARTED"
32+
const val UPLOAD_FINISHED = "UPLOAD_FINISHED"
3333
}
3434

35+
/**
36+
* Sends a broadcast indicating that an upload added
37+
*
38+
* ### Triggered when
39+
* - [UploadFileOperation] added
40+
*
41+
* ### Observed by
42+
* - [com.owncloud.android.ui.activity.UploadListActivity.UploadFinishReceiver]
43+
*
44+
*/
3545
fun sendAdded(context: Context) {
3646
Log_OC.d(TAG, "upload added broadcast sent")
3747
val intent = Intent(UPLOAD_ADDED).apply {
@@ -40,10 +50,17 @@ class FileUploadBroadcastManager(private val broadcastManager: LocalBroadcastMan
4050
broadcastManager.sendBroadcast(intent)
4151
}
4252

43-
fun sendStarted(
44-
upload: UploadFileOperation,
45-
context: Context,
46-
) {
53+
/**
54+
* Sends a broadcast indicating that an upload started
55+
*
56+
* ### Triggered when
57+
* - [UploadFileOperation] started
58+
*
59+
* ### Observed by
60+
* - [com.owncloud.android.ui.activity.UploadListActivity.UploadFinishReceiver]
61+
*
62+
*/
63+
fun sendStarted(upload: UploadFileOperation, context: Context) {
4764
Log_OC.d(TAG, "upload started broadcast sent")
4865
val intent = Intent(UPLOAD_STARTED).apply {
4966
putExtra(FileUploadWorker.EXTRA_REMOTE_PATH, upload.remotePath) // real remote

app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadWorker.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,11 @@ class FileUploadWorker(
284284
operation: UploadFileOperation,
285285
result: RemoteOperationResult<*>
286286
) {
287+
val isLastUpload = currentUploadIndex == totalUploadSize
288+
287289
val shouldBroadcast =
288-
(totalUploadSize > BATCH_SIZE && currentUploadIndex > 0) && currentUploadIndex % BATCH_SIZE == 0
290+
(currentUploadIndex % BATCH_SIZE == 0 && totalUploadSize > BATCH_SIZE) ||
291+
isLastUpload
289292

290293
if (shouldBroadcast) {
291294
fileUploadBroadcastManager.sendFinished(

app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,7 @@ class FileDisplayActivity :
16701670
private val tag = "UploadFinishReceiver"
16711671

16721672
override fun onReceive(context: Context?, intent: Intent) {
1673-
Log_OC.d(tag,"upload finish received broadcast")
1673+
Log_OC.d(tag, "upload finish received broadcast")
16741674

16751675
val uploadedRemotePath = intent.getStringExtra(FileUploadWorker.EXTRA_REMOTE_PATH)
16761676
val accountName = intent.getStringExtra(FileUploadWorker.ACCOUNT_NAME)

app/src/main/java/com/owncloud/android/ui/activity/UploadListActivity.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ private void refresh() {
177177
}
178178

179179
@Override
180-
protected void onResume() {
181-
Log_OC.v(TAG, "onResume() start");
182-
super.onResume();
180+
protected void onStart() {
181+
Log_OC.v(TAG, "onStart() start");
182+
super.onStart();
183183

184184
// Listen for upload messages
185185
uploadFinishReceiver = new UploadFinishReceiver();
@@ -189,19 +189,18 @@ protected void onResume() {
189189
uploadIntentFilter.addAction(FileUploadBroadcastManager.UPLOAD_FINISHED);
190190
localBroadcastManager.registerReceiver(uploadFinishReceiver, uploadIntentFilter);
191191

192-
Log_OC.v(TAG, "onResume() end");
193-
192+
Log_OC.v(TAG, "onStart() end");
194193
}
195194

196195
@Override
197-
protected void onPause() {
198-
Log_OC.v(TAG, "onPause() start");
196+
protected void onStop() {
197+
Log_OC.v(TAG, "onStop() start");
199198
if (uploadFinishReceiver != null) {
200199
localBroadcastManager.unregisterReceiver(uploadFinishReceiver);
201200
uploadFinishReceiver = null;
202201
}
203-
super.onPause();
204-
Log_OC.v(TAG, "onPause() end");
202+
super.onStop();
203+
Log_OC.v(TAG, "onStop() end");
205204
}
206205

207206
@Override

app/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ class PreviewImageActivity :
255255

256256
public override fun onStart() {
257257
super.onStart()
258+
registerReceivers()
258259
val optionalUser = user
259260
if (optionalUser.isPresent) {
260261
var file: OCFile? = file ?: throw IllegalStateException("Instanced with a NULL OCFile")
@@ -379,9 +380,7 @@ class PreviewImageActivity :
379380
}
380381
}
381382

382-
override fun onResume() {
383-
super.onResume()
384-
383+
private fun registerReceivers() {
385384
downloadFinishReceiver = DownloadFinishReceiver()
386385
val downloadIntentFilter = IntentFilter(getDownloadFinishMessage())
387386
localBroadcastManager.registerReceiver(downloadFinishReceiver!!, downloadIntentFilter)
@@ -391,13 +390,13 @@ class PreviewImageActivity :
391390
localBroadcastManager.registerReceiver(uploadFinishReceiver, uploadIntentFilter)
392391
}
393392

394-
public override fun onPause() {
393+
public override fun onStop() {
395394
if (downloadFinishReceiver != null) {
396395
localBroadcastManager.unregisterReceiver(downloadFinishReceiver!!)
397396
downloadFinishReceiver = null
398397
}
399398

400-
super.onPause()
399+
super.onStop()
401400
}
402401

403402
private fun backToDisplayActivity() {

0 commit comments

Comments
 (0)