Easily group RxJava Observables together and tie them to your Android Activity lifecycle
Easily group RxJava Observables together and tie them to your Android Activity lifecycle
RxGroups lets you group RxJava Observables together in groups and tie them to your Android lifecycle.
This is especially useful when used with Retrofit.
For simple scenarios you can probably just let the original request be cancelled and fire a new one. However it's easy to see how this becomes a problem in more complex situations.
Let's say your user is submitting a payment. You'll probably want to guarantee that you can reattach to the same in-flight or completed request after rotating the screen or leaving the Activity and returning later.
RxGroups will also automatically prevent events from being delivered to your Activity or Fragment
before onResume() and after onPause(). If that happens, they will be automatically cached in memory
and delivered once the user returns to your screen. If they never return, the memory is then reclaimed
automatically after onDestroy().
GroupLifecycleManager field to your Activity, Fragment, Dialog, etc. and call its respective lifecycle methods according to your own (eg.: onPause, onResume, onDestroy, etc.);ResubscriptionObserver with @AutoResubscribe and use method resubscriptionTag() to tell RxGroups what tag it should use for reattaching your Observer to it Observable automatically. To use RxGroups with Kotlin don't forget to annotate fields with @JvmField. Observable, compose it with observableGroup.transform() to define a tag for that Observable;…Optional: If you don't want to use a ResubscriptionObserver with @AutoResubscribe just use a
regular Observer anonymous class with a public method called resubscriptionTag(). Eg.:
@AutoResubscribe public final Observer observer = new Observer() {
@Override public void onCompleted() {
}
@Override public void onError(Throwable e) {
}
@Override public void onNext(Long l) {
}
public Object resubscriptionTag() {
return Arrays.asList("tag1", "tag2", "tag3");
}
};If the method doesn't exist or is not public, RxGroups will throw a RuntimeException letting you know.
You can use any Object tag for your Observer, including arrays and List, In that case, it will
associate the Observer with all the tags in the collection, allowing you to share the same
Observer with multiple Observables.
compile 'com.airbnb:rxgroups-android:0.3.5'Check out the Sample app for more details and a complete example!
Snapshots of the development version are available in
Sonatype's snapshots repository.
Copyright 2016 Airbnb, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.No open issues yet, or sync has not completed.