Allow in progress file transfers to be canceled
BUG: 349956
albertvaka | |
nicolasfella |
KDE Connect |
Allow in progress file transfers to be canceled
BUG: 349956
Send a large file from desktop to android
Press cancel in the progress notification
Result: the file transfer is cancelled and the cancelled file is deleted from storage
No Linters Available |
No Unit Test Coverage |
Buildable 4338 | |
Build 4356: arc lint + arc unit |
BackgroundJob looks line https://developer.android.com/reference/android/os/AsyncTask to me. Can we use that instead of creating our own thing?
You could but because there are so many issues with AsyncTask I would not recommend it (its even not recommended for running tasks that take longer than a few seconds).
Using BackgroundJob and BackgroundJobHandler also allows to start jobs from non Activities. Regarding orientation changes the same problems remain, we have to make sure that updates to the UI are done on the newly created activity/fragment not the old ones (The 2 I use only update a notification so no problems there).
Current best practices are using ViewModels that are retained and LiveData that deliver data to the activity/fragment only when the lifecycle permits it. So ViewModel starts a BackgroundJob and is guaranteed to receive the result updates the LiveData with the result and then when the Activity observing the LiveData becomes active it will receive the result.
Needs rebasing, but seems to work fine otherwise.
I don't think the desktop side would delete the partially transferred file, but that's something for another patch
Tested on my OnePlus and it works well.
+1 on not using AsyncTask.
Building our own Job management system seems a bit like an overkill just for this, though, but hopefully we can use it in more places.
src/org/kde/kdeconnect/Plugins/SharePlugin/ShareNotification.java | ||
---|---|---|
72–83 ↗ | (On Diff #44452) | Rename to addCancelButton or something like that? It does more than setting an id. |