VyacheslavShmakin / RxViewModelTask

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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'

About

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

License:Apache License 2.0


Languages

Language:Kotlin 100.0%