Skip to content
Deishelon edited this page Jan 29, 2019 · 2 revisions

Basic usage

Step 1. Create a mission

val mission = Mission(URL, FILE_NAME, SAVE_PATH, IS_OVERRIDE)

Overwrite existing file

You can set overwrite flag to true, which will explicitly re-download the file, otherwise, if the file already exists - Success will be returned

PendingIntent

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

Step 3. Start download

RxDownload.start(mission).subscribe()

Step 4. Dispose observer

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)