I want to replace the job scheduling aspect of my existing data syncing system with the new JetPack WorkManager (link to codelabs) component (in a sandbox branch of the app). My existing system works well but some of the new features in WorkManager
would come in handy (e.g. chaining).
My current system uses a shared LiveData
to communicate the progress from a job in progress to any UI element (RecyclerView
in my case) observing on it (I'm actually SwitchMapping in the ViewModel
into a list of SyncItem
s)
data class SyncItem(
val title: String,
private var _progress: Int,
var total: Int) : BaseObservable() {
var progress: Int
@Bindable get() = _progress
set(value) {
_progress = value
notifyPropertyChanged(BR.progress)
}
}
The new WorkManager
component has several methods (getStatusById
, getStatusesByTag
, etc.) that can be used to retrieve a LiveData with one or more WorkStatus
es, but these only report a course-grained status (running, success, failed, cancelled).
What is the recommended way of communicating progress (e.g. '546/1234 items downloaded') to the UI? The setOutputData
/getOutputData
pair seems to be used more to communicate between Worker
s (which I need when chaining) than with the UI.
Attached is a screenshot of what it looks like (in a [test] version of my app using my old method) when a user opens the sync status page (2 items completed, rest in progress).
In the final product the user will be able to cancel any jobs in progress and re-issue once-off work requests. Normally the jobs will be fired off by PeriodicWorkRequest
.