Skip to content

Simplified task long task execution by using Android architecture ViewModel and LiveData with RxAndroid

License

Notifications You must be signed in to change notification settings

VyacheslavShmakin/RxViewModelTask

Repository files navigation

Download API Licence

RxViewModelTask

Simplified task long task execution by using Android architecture ViewModel and LiveData with RxAndroid. You can simply implement Observable/Flowable/Maybe/Single/Completable objects and pass them to RxViewModelTask. It will be executed with respect to Android Lifecycle)

Download

Gradle:

implementation 'com.github.VyacheslavShmakin:rx-vmt:1.3.1'

Maven:

<dependency>
    <groupId>com.github.VyacheslavShmakin</groupId>
    <artifactId>rx-vmt</artifactId>
    <version>1.3.1</version>
    <type>aar</type>
</dependency>

Usage

// "this" - Fragment or FragmentActivity will be used as ViewModelStoreOwner and LifeCycleOwner
RxViewModelTask.create(this, "Unique String key in Fragment/FragmentActivity")
  .init(observable, observer, true)
//.init(flowable, observer, true)
//.init(single, singleObserver)
//.init(maybe, maybeObserver)
//.init(completable, completableObserver)
// You're able to use "restart" method also
// To stop running task use "stop" method
  .stop()
  • init will execute Observable/Flowable/Maybe/Single/Completable object only once. Even if you call this multiple times the last callback method will be called.
  • restart will execute Observable/Flowable/Maybe/Single/Completable object every restart call.
  • Observable and Flowable implementation are able to collect all items when ViewModel inactive and pass them when ViewModel became active. To use this feature just enable the flag collectAll when calling init or restart method. This option is disabled by default. Please be careful by using this option to avoid UI freezes when you passing a lot of data in a short time

Imported libraries with initial version

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.11'
implementation 'android.arch.lifecycle:extensions:2.0.0'

Releases

No releases published

Packages

No packages published

Languages