forked from ssseasonnn/RxDownload
-
Notifications
You must be signed in to change notification settings - Fork 1
Usage
Deishelon edited this page Jan 29, 2019
·
2 revisions
val mission = Mission(URL, FILE_NAME, SAVE_PATH, IS_OVERRIDE)
You can set overwrite
flag to true, which will explicitly re-download the file, otherwise, if the file already exists - Success will be returned
You can pass a PendingIntent to a Mission, so that if you enabled notifications & provided a custom Implementation for it -> you can set an action for your notification click.
Step 2. Subscribe to the mission updates (multiple calls do not cause to start download more than once)
val disposable = RxDownload.create(mission, autoStart = false)
.observeOn(AndroidSchedulers.mainThread())
.subscribe { status ->
}
There are a few customizable user-friendly presets of a pretty print of observable status:
val percent = status.percentPretty(INT_DECIMAL_POINT_FORMAT) // returns `String` i.e 12.2
val rawPercent = status.percent() // returns `Double`
val totalSize = status.formatTotalSize(INT_DECIMAL_POINT_FORMAT) // returns `String` i.e 22.2 MB
val dwnSoFarSize = status.formatDownloadSize(INT_DECIMAL_POINT_FORMAT) // returns `String` i.e 44.4 MB
val progress = status.formatString(INT_DECIMAL_POINT_FORMAT) // returns `String` i.e 44.4 MB / 102.3 MB
RxDownload.start(mission).subscribe()
Once you done listening dispose the observer, by calling. A good place for that is in onDestroy()
or onCleared()
import zlc.season.rxdownload3.helper.dispose
dispose(disposable)