All Projects → Sloaix → Apollo

Sloaix / Apollo

Licence: apache-2.0
🚀 Awesome EventBus by RxJava.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Apollo

ReactiveBus
🚍 Reactive Event Bus for JVM (1.7+) and Android apps built with RxJava 2
Stars: ✭ 17 (-94.83%)
Mutual labels:  rxjava, eventbus, rxjava2
Nybus
NYBus (RxBus) - A pub-sub library for Android and Java applications
Stars: ✭ 283 (-13.98%)
Mutual labels:  rxjava, rxjava2, eventbus
Rxbus
🚌 The RxBus as steady as an old dog.
Stars: ✭ 334 (+1.52%)
Mutual labels:  rxjava, rxjava2, eventbus
RXBus
RX based bus with lifecycle based queuing support
Stars: ✭ 53 (-83.89%)
Mutual labels:  rxjava, eventbus
IpcEventBus
Faster than Intents and easier than AIDLs.
Stars: ✭ 35 (-89.36%)
Mutual labels:  ipc, eventbus
android-online-course
Android Online Course
Stars: ✭ 22 (-93.31%)
Mutual labels:  rxjava, rxjava2
ReactiveConnectivity
ReactiveConnectivity - a library for Listen Connectivity Change on Android
Stars: ✭ 22 (-93.31%)
Mutual labels:  rxjava, rxjava2
Rxbiometric
☝️ RxJava and RxKotlin bindings for Biometric Prompt (Fingerprint Scanner) on Android
Stars: ✭ 295 (-10.33%)
Mutual labels:  rxjava, rxjava2
rxbus2
Listen and handle event ,based on RxJava.
Stars: ✭ 32 (-90.27%)
Mutual labels:  rxjava, eventbus
Swipe
👉 detects swipe events on Android
Stars: ✭ 324 (-1.52%)
Mutual labels:  rxjava, rxjava2
Rxanime
Visualizer to understand RxJava operators
Stars: ✭ 261 (-20.67%)
Mutual labels:  rxjava, rxjava2
T Mvp
Android AOP Architecture by Apt, AspectJ, Javassisit, based on Realm+Databinding+MVP+Retrofit+Rxjava2
Stars: ✭ 2,740 (+732.83%)
Mutual labels:  rxjava, rxjava2
Rxgps
Finding current location cannot be easier on Android !
Stars: ✭ 307 (-6.69%)
Mutual labels:  rxjava, rxjava2
RxCamera2
Rx Java 2 wrapper for Camera2 google API
Stars: ✭ 27 (-91.79%)
Mutual labels:  rxjava, rxjava2
RxFbLiveVideoEmoticons
Demo of Fb Live Video Reactions using RxJava2
Stars: ✭ 93 (-71.73%)
Mutual labels:  rxjava, rxjava2
rxjava2-http
Transmit RxJava2 Flowable over http with non-blocking backpressure
Stars: ✭ 19 (-94.22%)
Mutual labels:  rxjava, rxjava2
RxWebView
RxJava2 binding APIs for Android's WebView
Stars: ✭ 22 (-93.31%)
Mutual labels:  rxjava, rxjava2
RxHttp
基于RxJava2+Retrofit+OkHttp4.x封装的网络请求类库,亮点多多,完美兼容MVVM(ViewModel,LiveData),天生支持网络请求和生命周期绑定,天生支持多BaseUrl,支持文件上传下载进度监听,支持断点下载,支持Glide和网络请求公用一个OkHttpClient⭐⭐⭐
Stars: ✭ 25 (-92.4%)
Mutual labels:  rxjava, rxjava2
RxAnimator
An RxJava2 binding for android Animator
Stars: ✭ 80 (-75.68%)
Mutual labels:  rxjava, rxjava2
RxRetroAPICall
API call example using Retrofit and RxJava2
Stars: ✭ 16 (-95.14%)
Mutual labels:  rxjava, rxjava2

Apollo

EventBus by RxJava

  • 基于RxJava
  • 基于编译时注解技术,编译时生成绑定代码,非反射,性能0损耗
  • 支持进程间通信
  • 支持@Tag注解,支持多重Tag
  • 支持@Sticky注解
  • 支持@Take注解,接收指定次数事件
  • 支持@SubscribeOn注解,指定订阅线程
  • 支持@ObserveOn注解,指定观察线程
  • 支持@Backpressure注解,支持3种背压策略(BackpressureStrategy.BUFFER,BackpressureStrategy.DROP,BackpressureStrategy.LATEST)
  • 支持apollo core 非注解式使用

English Document

Todo

  • 重写demo
  • 完整的单元测试(已完成30%,见unittest module)

开始

用3分钟时间快速集成Apollo

集成

使用jitpack第三方依赖库

allProjects {
  repositories {
    maven { url "https://www.jitpack.io" }
  }
}

在项目所在build.gralde添加依赖

dependencies {
  //Apollo依赖RxAndroid2,请使用最新的版本
  implementation "io.reactivex.rxjava2:rxandroid:2.0.1"
  
  //Apollo的核心库
  implementation "com.github.lsxiao.Apollo:core:1.0.2"

  //IPC,如不需要可以不依赖
  implementation "com.github.lsxiao.Apollo:ipc:1.0.2"

  //Apollo的编译时注解处理器
  annotationProcessor "com.github.lsxiao.Apollo:processor:1.0.2"

  //如果你使用的是kotlin,请使用kapt
  kapt "com.github.lsxiao.Apollo:processor:1.0.2"
}

使用

初始化

ApolloBinderGeneratorImpl在编译时生成。

Apollo.init(AndroidSchedulers.mainThread(), this);

绑定/解绑

为了避免内存泄露,应在组件生命周期内绑定和解绑。

public abstract class BaseActivity extends Activity {
    private ApolloBinder mBinder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ...
        mBinder = Apollo.bind(this);
    }

    @Override
    protected void onDestroy() {
        ...
        if(mBinder != null){
            mBinder.unbind();        
        }
    }
    ...
}

发送

让发送更简单

Apollo.emit("event","hello apollo")

接收

让接收更自在

@Receive("event")
public void onEvent(String message){
    ...
}

进程间通信(IPC)

默认关闭

Apollo.init(AndroidSchedulers.mainThread(), this,true);

**!!!注意:**由于默认采用kryo序列化,所以任何需要在进程间传输的数据对象,自己包括其内部的成员对象都必须有一个默认的无参构造函数!!!

高级用法

注解

注意!!!,被注解的函数一定得是public修饰,且@Receive是必须注解,其余为可选注解。

注解 参数 描述 默认值
@Receive 接收一个字符串tag数组,或者单个字符串tag
@Sticky remove 接收后是否清除stikcy事件 ture
@SubscribeOn 订阅所在线程 SchedulerProvider.Tag.IO
@ObserveOn 观察所在线程 SchedulerProvider.Tag.MAIN
@Take 接收多少次事件,int型参数
@Backpressure 背压策略(BackpressureStrategy.BUFFER,BackpressureStrategy.DROP,BackpressureStrategy.LATEST)

更多方法

boolean sticky = true;

//只有tag
Apollo.emit("tag");
//tag和数据实体
Apollo.emit("tag","event");

//stikcy(只有被@Sticky注解的函数才能收到sticky事件)
Apollo.emit("tag","event",stikcy)

//只有tag的stikcy调用
Apollo.emit("tag",sticky)

注意,在emit一个boolean变量的时候,正确写法:

Apollo.emit("tag",true,sticky)

错误写法,这样直接就发送了一个不带参数的sticky事件:

Apollo.emit("tag",true)

自定义Serializer

Apollo默认采用kryo来序列化IPC数据对象,你可以提供一个Serializer来修改默认的实现。

Apollo.serializer(new Serializable() {
    @NotNull
    @Override
    public byte[] serialize(@NotNull Object obj) {
        ...
    }

    @Override
    public <T> T deserialize(@NotNull byte[] data, @NotNull Class<T> clazz) {
        ...
    }
});

混淆

-dontwarn com.esotericsoftware.kryo.**
-dontwarn org.objenesis.instantiator.**
-dontwarn org.codehaus.**
-dontwarn java.nio.**
-dontwarn java.lang.invoke.**
-keep class com.lsxiao.apollo.generate.** { *; }

测试

全面而完善的测试是开源库质量的保证,目前测试用例正在不断完善中:)

core module

KryoSerializeTest

unit test module

unittest

构建于ReactiveX之上

  • RxJava2 - Reactive Extensions for the JVM
  • RxAndroid2 - Reactive Extensions for Android

版本

我们使用 语义化版本控制规范 作为版本管理,有关可用的版本,请参阅此 标签列表

作者

更多 贡献者 请参考这个项目的列表。

开源许可

Apache License Version 2.0

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].