Skip to content

Commit 239170e

Browse files
committed
add missing receivers
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent 0cfb0af commit 239170e

7 files changed

Lines changed: 195 additions & 144 deletions

File tree

app/src/main/java/com/nextcloud/client/jobs/BackgroundJobFactory.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ class BackgroundJobFactory @Inject constructor(
300300
accountManager,
301301
context,
302302
viewThemeUtils.get(),
303+
localBroadcastManager.get(),
303304
params
304305
)
305306
}

app/src/main/java/com/nextcloud/client/jobs/download/FileDownloadWorker.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import androidx.work.ForegroundInfo
2121
import androidx.work.WorkerParameters
2222
import com.nextcloud.client.account.User
2323
import com.nextcloud.client.account.UserAccountManager
24-
import com.nextcloud.model.WorkerState
25-
import com.nextcloud.model.WorkerStateObserver
2624
import com.nextcloud.utils.ForegroundServiceHelper
2725
import com.nextcloud.utils.extensions.getPercent
2826
import com.owncloud.android.R
@@ -140,7 +138,6 @@ class FileDownloadWorker(
140138
} finally {
141139
Log_OC.d(TAG, "cleanup")
142140
notificationManager.dismissNotification()
143-
setIdleWorkerState()
144141
}
145142
}
146143

@@ -168,14 +165,6 @@ class FileDownloadWorker(
168165
ForegroundServiceType.DataSync
169166
)
170167

171-
private fun setWorkerState(user: User?) {
172-
WorkerStateObserver.send(WorkerState.FileDownloadStarted(user, currentDownload))
173-
}
174-
175-
private fun setIdleWorkerState() {
176-
WorkerStateObserver.send(WorkerState.FileDownloadCompleted(getCurrentFile()))
177-
}
178-
179168
private fun removePendingDownload(accountName: String?) {
180169
pendingDownloads.remove(accountName)
181170
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Nextcloud - Android Client
3+
*
4+
* SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com>
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
package com.nextcloud.client.jobs.folderDownload
9+
10+
import android.content.Context
11+
import android.content.Intent
12+
import androidx.localbroadcastmanager.content.LocalBroadcastManager
13+
import com.nextcloud.client.jobs.download.FileDownloadWorker
14+
import com.owncloud.android.lib.common.utils.Log_OC
15+
16+
class FolderDownloadBroadcastManager(
17+
private val context: Context,
18+
private val broadcastManager: LocalBroadcastManager
19+
) {
20+
companion object {
21+
private const val TAG = "📣" + "FolderDownloadBroadcastManager"
22+
23+
const val DOWNLOAD_ADDED = "DOWNLOAD_ADDED"
24+
const val DOWNLOAD_FINISHED = "DOWNLOAD_FINISHED"
25+
26+
const val EXTRA_FILE_ID = "EXTRA_FILE_ID"
27+
}
28+
29+
fun sendAdded(id: Long) {
30+
Log_OC.d(TAG, "download added broadcast sent")
31+
32+
val intent = Intent(DOWNLOAD_ADDED).apply {
33+
putExtra(EXTRA_FILE_ID, id)
34+
}
35+
36+
broadcastManager.sendBroadcast(intent)
37+
}
38+
39+
fun sendFinished(id: Long) {
40+
Log_OC.d(TAG, "download finished broadcast sent")
41+
42+
val intent = Intent(DOWNLOAD_FINISHED).apply {
43+
putExtra(EXTRA_FILE_ID, id)
44+
}
45+
46+
broadcastManager.sendBroadcast(intent)
47+
}
48+
}

app/src/main/java/com/nextcloud/client/jobs/folderDownload/FolderDownloadWorker.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
package com.nextcloud.client.jobs.folderDownload
99

1010
import android.content.Context
11+
import androidx.localbroadcastmanager.content.LocalBroadcastManager
1112
import androidx.work.CoroutineWorker
1213
import androidx.work.ForegroundInfo
1314
import androidx.work.WorkerParameters
1415
import com.nextcloud.client.account.UserAccountManager
1516
import com.nextcloud.client.jobs.download.FileDownloadHelper
16-
import com.nextcloud.model.WorkerState
17-
import com.nextcloud.model.WorkerStateObserver
1817
import com.owncloud.android.datamodel.FileDataStorageManager
1918
import com.owncloud.android.datamodel.OCFile
2019
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
@@ -32,6 +31,7 @@ class FolderDownloadWorker(
3231
private val accountManager: UserAccountManager,
3332
private val context: Context,
3433
viewThemeUtils: ViewThemeUtils,
34+
localBroadcastManager: LocalBroadcastManager,
3535
params: WorkerParameters
3636
) : CoroutineWorker(context, params) {
3737

@@ -46,6 +46,7 @@ class FolderDownloadWorker(
4646
}
4747

4848
private val notificationManager = FolderDownloadWorkerNotificationManager(context, viewThemeUtils)
49+
private val folderDownloadBroadcastManager = FolderDownloadBroadcastManager(context, localBroadcastManager)
4950
private lateinit var storageManager: FileDataStorageManager
5051

5152
@Suppress("ReturnCount", "DEPRECATION")
@@ -79,6 +80,7 @@ class FolderDownloadWorker(
7980

8081
trySetForeground(folder)
8182

83+
folderDownloadBroadcastManager.sendAdded(folder.fileId)
8284
pendingDownloads.add(folder.fileId)
8385

8486
val downloadHelper = FileDownloadHelper.instance()
@@ -136,7 +138,7 @@ class FolderDownloadWorker(
136138
Log_OC.d(TAG, "❌ failed reason: $e")
137139
Result.failure()
138140
} finally {
139-
WorkerStateObserver.send(WorkerState.FolderDownloadCompleted(folder))
141+
folderDownloadBroadcastManager.sendFinished(folder.fileId)
140142
pendingDownloads.remove(folder.fileId)
141143
notificationManager.dismiss()
142144
}

app/src/main/java/com/nextcloud/model/WorkerState.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@
77
*/
88
package com.nextcloud.model
99

10-
import com.nextcloud.client.account.User
11-
import com.owncloud.android.datamodel.OCFile
12-
import com.owncloud.android.operations.DownloadFileOperation
13-
1410
sealed class WorkerState {
15-
data class FolderDownloadCompleted(var folder: OCFile) : WorkerState()
16-
17-
data class FileDownloadStarted(var user: User?, var currentDownload: DownloadFileOperation?) : WorkerState()
18-
data class FileDownloadCompleted(var currentFile: OCFile?) : WorkerState()
19-
2011
data object OfflineOperationsCompleted : WorkerState()
2112
}

0 commit comments

Comments
 (0)