All Projects → airbnb → Rxgroups

airbnb / Rxgroups

Licence: apache-2.0
Easily group RxJava Observables together and tie them to your Android Activity lifecycle

Programming Languages

java
68154 projects - #9 most used programming language

Labels

Projects that are alternatives of or similar to Rxgroups

Androidrapidlibrary
Android 快速开发库,主要想实现一条属于自己的开发框架。包括网络访问,数据,UI等等
Stars: ✭ 577 (-16.98%)
Mutual labels:  rxjava
T Mvvm
This repository contains a detailed sample app that implements MVVM architecture using LiveData,ViewModel,Retrofit,Rxjava
Stars: ✭ 630 (-9.35%)
Mutual labels:  rxjava
Smartrecom
一款基于行为识别和个性化推荐的智能推荐APP,实时为你推荐音乐和电影,让你的生活更休闲,更精彩!
Stars: ✭ 663 (-4.6%)
Mutual labels:  rxjava
Fast Android Networking
🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀
Stars: ✭ 5,346 (+669.21%)
Mutual labels:  rxjava
Android Kotlin Mvp Architecture
This repository contains a detailed sample app that implements MVP architecture in Kotlin using Dagger2, Room, RxJava2, FastAndroidNetworking and PlaceholderView
Stars: ✭ 615 (-11.51%)
Mutual labels:  rxjava
Kovenant
Kovenant. Promises for Kotlin.
Stars: ✭ 657 (-5.47%)
Mutual labels:  rxjava
Rxweather
Architecting Android with RxJava
Stars: ✭ 570 (-17.99%)
Mutual labels:  rxjava
Rxwebsocket
An auto reconnection-webSocket build with okhttp and rxJava
Stars: ✭ 678 (-2.45%)
Mutual labels:  rxjava
Lazywaimai Android
一个类似于饿了么、美团外卖和百度外卖的APP,采用MVP架构,目前还有部分功能还未实现,但基本的订餐流程已实现。
Stars: ✭ 623 (-10.36%)
Mutual labels:  rxjava
Rxjavaextensions
RxJava 2.x & 3.x extra sources, operators and components and ports of many 1.x companion libraries.
Stars: ✭ 662 (-4.75%)
Mutual labels:  rxjava
Rxdogtag
Automatic tagging of RxJava 2+ originating subscribe points for onError() investigation.
Stars: ✭ 601 (-13.53%)
Mutual labels:  rxjava
C9mj
个人练手项目(新闻 + 视频直播): 基于 MVP + Glide + Retrofit + RxJava2.0 + butterknife 的C9MJ TV (斗鱼douyu/熊猫panda/战旗zhanqi/虎牙huya/龙珠longhzu/全民quanmin/网易cc/火猫huomao + 英雄联盟LOL/守望先锋OW/DOTA2/炉石传说hs/CSGO)App。ps:只有观看熊猫Panda TV才有弹幕(bullet/barrage/danmu)播放功能。
Stars: ✭ 607 (-12.66%)
Mutual labels:  rxjava
Mango
🏀 An Android app for dribbble.com
Stars: ✭ 659 (-5.18%)
Mutual labels:  rxjava
Kotlin Android Starter
[Kotlin Android] Kotlin Android starter based MVP/Dagger2/RxJava2/Robolectric/Espresso/Mockito. It provides a generator to fast create a Kotlin Android project.
Stars: ✭ 589 (-15.25%)
Mutual labels:  rxjava
Wanandroid
🐔🏀【停止维护,已使用Jetpack+Mvvm重构】根据鸿神提供的WanAndroid开放Api来制作的产品级玩安卓App,采用Kotlin语言,基于Material Design+AndroidX +MVP+RxJava+Retrofit等框架开发,注释超详细,方便大家练手
Stars: ✭ 674 (-3.02%)
Mutual labels:  rxjava
Rxpay
一个集成支付宝微信的支付工具
Stars: ✭ 576 (-17.12%)
Mutual labels:  rxjava
Retrofitcache
RetrofitCache让retrofit2+okhttp3+rxjava配置缓存如此简单。通过注解配置,可以针对每一个接口灵活配置缓存策略;同时让每一个接口方便支持数据模拟,可以代码减小侵入性,模拟数据可以从内存,Assets,url轻松获取。
Stars: ✭ 647 (-6.91%)
Mutual labels:  rxjava
Baby
一个私密社交APP,采用Dagger2+Rxjava+LeanCloud+环信+MVP+Tinker进行开发。
Stars: ✭ 687 (-1.15%)
Mutual labels:  rxjava
Reservoir
Android library to easily serialize and cache your objects to disk using key/value pairs.
Stars: ✭ 674 (-3.02%)
Mutual labels:  rxjava
Android Oss
Kickstarter for Android. Bring new ideas to life, anywhere.
Stars: ✭ 5,627 (+709.64%)
Mutual labels:  rxjava

RxGroups

Build Status

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().

Usage

  1. Add a GroupLifecycleManager field to your Activity, Fragment, Dialog, etc. and call its respective lifecycle methods according to your own (eg.: onPause, onResume, onDestroy, etc.);
  2. Annotate your 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.
  3. Before subscribing to your Observable, compose it with observableGroup.transform() to define a tag for that Observable;

Example

public class MyActivity extends Activity {
  private static final String OBSERVABLE_TAG = "arbitrary_tag";
  private TextView output;
  private FloatingActionButton button;
  private GroupLifecycleManager groupLifecycleManager;
  private ObservableGroup observableGroup;
  private Observable<Long> observable = Observable.interval(1, 1, TimeUnit.SECONDS);

  // The Observer field must be public, otherwise RxGroups can't access it
  @AutoResubscribe public final ResubscriptionObserver<Long> observer = new ResubscriptionObserver<Long>() {
    @Override public void onCompleted() {
      Log.d(TAG, "onCompleted()");
    }

    @Override public void onError(Throwable e) {
      Log.e(TAG, "onError()", e);
    }

    @Override public void onNext(Long l) {
      output.setText(output.getText() + " " + l);
    }

    @Override public Object resubscriptionTag() {
      return OBSERVABLE_TAG;
    }
  };

  @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    output = (TextView) findViewById(R.id.txt_output);
    button = (FloatingActionButton) findViewById(R.id.fab);
    SampleApplication application = (SampleApplication) getApplication();
    ObservableManager manager = application.observableManager();
    groupLifecycleManager = GroupLifecycleManager.onCreate(manager, savedInstanceState, this);
    observableGroup = groupLifecycleManager.group();

    button.setOnClickListener(v -> observable
        .compose(observableGroup.<Long>transform(OBSERVABLE_TAG))
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(observer));
  }

  @Override protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    groupLifecycleManager.onSaveInstanceState(outState);
  }

  @Override protected void onResume() {
    super.onResume();
    groupLifecycleManager.onResume();
  }

  @Override protected void onPause() {
    super.onPause();
    groupLifecycleManager.onPause();
  }

  @Override protected void onDestroy() {
    super.onDestroy();
    groupLifecycleManager.onDestroy(this);
  }
}

Optional: If you don't want to use a ResubscriptionObserverwith @AutoResubscribe just use a regular Observer anonymous class with a public method called resubscriptionTag(). Eg.:

@AutoResubscribe public final Observer<Long> observer = new Observer<Long>() {
    @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.

Download with Gradle

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.

License

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].