Skip to content

Commit b390b75

Browse files
committed
fix(receivers): upload
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent 5b7629a commit b390b75

3 files changed

Lines changed: 13 additions & 57 deletions

File tree

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

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,54 +13,31 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager
1313
import com.owncloud.android.lib.common.operations.RemoteOperationResult
1414
import com.owncloud.android.operations.UploadFileOperation
1515

16-
class FileUploaderDelegate {
17-
/**
18-
* Sends a broadcast in order to the interested activities can update their view
19-
*
20-
* TODO - no more broadcasts, replace with a callback to subscribed listeners once we drop FileUploader
21-
*/
22-
fun sendBroadcastUploadsAdded(context: Context, localBroadcastManager: LocalBroadcastManager) {
16+
class FileUploadBroadcastManager(private val broadcastManager: LocalBroadcastManager) {
17+
18+
fun sendAdded(context: Context) {
2319
val start = Intent(FileUploadWorker.getUploadsAddedMessage())
24-
// nothing else needed right now
2520
start.setPackage(context.packageName)
26-
localBroadcastManager.sendBroadcast(start)
21+
broadcastManager.sendBroadcast(start)
2722
}
2823

29-
/**
30-
* Sends a broadcast in order to the interested activities can update their view
31-
*
32-
* TODO - no more broadcasts, replace with a callback to subscribed listeners once we drop FileUploader
33-
*
34-
* @param upload Finished upload operation
35-
*/
36-
fun sendBroadcastUploadStarted(
24+
fun sendStarted(
3725
upload: UploadFileOperation,
3826
context: Context,
39-
localBroadcastManager: LocalBroadcastManager
4027
) {
4128
val start = Intent(FileUploadWorker.getUploadStartMessage())
4229
start.putExtra(FileUploadWorker.EXTRA_REMOTE_PATH, upload.remotePath) // real remote
4330
start.putExtra(FileUploadWorker.EXTRA_OLD_FILE_PATH, upload.originalStoragePath)
4431
start.putExtra(FileUploadWorker.ACCOUNT_NAME, upload.user.accountName)
4532
start.setPackage(context.packageName)
46-
localBroadcastManager.sendBroadcast(start)
33+
broadcastManager.sendBroadcast(start)
4734
}
4835

49-
/**
50-
* Sends a broadcast in order to the interested activities can update their view
51-
*
52-
* TODO - no more broadcasts, replace with a callback to subscribed listeners once we drop FileUploader
53-
*
54-
* @param upload Finished upload operation
55-
* @param uploadResult Result of the upload operation
56-
* @param unlinkedFromRemotePath Path in the uploads tree where the upload was unlinked from
57-
*/
58-
fun sendBroadcastUploadFinished(
36+
fun sendFinished(
5937
upload: UploadFileOperation,
6038
uploadResult: RemoteOperationResult<*>,
6139
unlinkedFromRemotePath: String?,
62-
context: Context,
63-
localBroadcastManager: LocalBroadcastManager
40+
context: Context
6441
) {
6542
val end = Intent(FileUploadWorker.getUploadFinishMessage())
6643
// real remote path, after possible automatic renaming
@@ -75,6 +52,6 @@ class FileUploaderDelegate {
7552
end.putExtra(FileUploadWorker.EXTRA_LINKED_TO_PATH, unlinkedFromRemotePath)
7653
}
7754
end.setPackage(context.packageName)
78-
localBroadcastManager.sendBroadcast(end)
55+
broadcastManager.sendBroadcast(end)
7956
}
8057
}

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class FileUploadWorker(
131131
private val notificationId = Random.nextInt()
132132
private val notificationManager = UploadNotificationManager(context, viewThemeUtils, notificationId)
133133
private val intents = FileUploaderIntents(context)
134-
private val fileUploaderDelegate = FileUploaderDelegate()
134+
private val fileUploadBroadcastManager = FileUploadBroadcastManager(localBroadcastManager)
135135

136136
override suspend fun doWork(): Result = try {
137137
Log_OC.d(TAG, "FileUploadWorker started")
@@ -206,10 +206,6 @@ class FileUploadWorker(
206206
notificationManager.dismissNotification()
207207
}
208208

209-
private fun setWorkerState(user: User?) {
210-
WorkerStateObserver.send(WorkerState.FileUploadStarted(user))
211-
}
212-
213209
private fun setIdleWorkerState() {
214210
WorkerStateObserver.send(WorkerState.FileUploadCompleted(currentUploadFileOperation?.file))
215211
}
@@ -269,9 +265,9 @@ class FileUploadWorker(
269265
return@withContext Result.failure()
270266
}
271267

272-
setWorkerState(user)
273268
val operation = createUploadFileOperation(upload, user)
274269
currentUploadFileOperation = operation
270+
fileUploadBroadcastManager.sendStarted(operation, context)
275271

276272
val currentIndex = (index + 1)
277273
val currentUploadIndex = (currentIndex + previouslyUploadedFileSize)
@@ -312,12 +308,11 @@ class FileUploadWorker(
312308

313309
if (shouldBroadcast) {
314310
// delay broadcast
315-
fileUploaderDelegate.sendBroadcastUploadFinished(
311+
fileUploadBroadcastManager.sendFinished(
316312
operation,
317313
result,
318314
operation.oldFile?.storagePath,
319-
context,
320-
localBroadcastManager
315+
context
321316
)
322317
}
323318
}

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import com.nextcloud.client.jobs.upload.FileUploadHelper;
2929
import com.nextcloud.client.jobs.upload.FileUploadWorker;
3030
import com.nextcloud.client.utils.Throttler;
31-
import com.nextcloud.model.WorkerState;
32-
import com.nextcloud.utils.extensions.ActivityExtensionsKt;
3331
import com.owncloud.android.R;
3432
import com.owncloud.android.databinding.UploadListLayoutBinding;
3533
import com.owncloud.android.datamodel.OCFile;
@@ -49,7 +47,6 @@
4947
import androidx.recyclerview.widget.GridLayoutManager;
5048
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
5149
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
52-
import kotlin.Unit;
5350

5451
/**
5552
* Activity listing pending, active, and completed uploads. User can delete completed uploads from view. Content of this
@@ -126,19 +123,6 @@ protected void onCreate(Bundle savedInstanceState) {
126123
setupDrawer();
127124

128125
setupContent();
129-
observeWorkerState();
130-
}
131-
132-
private void observeWorkerState() {
133-
ActivityExtensionsKt.observeWorker(this, state -> {
134-
if (state instanceof WorkerState.FileUploadStarted) {
135-
Log_OC.d(TAG, "Upload worker started");
136-
uploadListAdapter.loadUploadItemsFromDb();
137-
} else if (state instanceof WorkerState.FileUploadCompleted) {
138-
uploadListAdapter.loadUploadItemsFromDb(() -> swipeListRefreshLayout.setRefreshing(false));
139-
}
140-
return Unit.INSTANCE;
141-
});
142126
}
143127

144128
private void setupContent() {

0 commit comments

Comments
 (0)