This repository was archived by the owner on Mar 29, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork36
🚀 Awesome EventBus by RxJava.
License
NotificationsYou must be signed in to change notification settings
Sloaix/Apollo
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
EventBus by RxJava
- 基于RxJava
- 基于编译时注解技术,编译时生成绑定代码,非反射,性能0损耗
- 支持进程间通信
- 支持@Tag注解,支持多重Tag
- 支持@Sticky注解
- 支持@Take注解,接收指定次数事件
- 支持@SubscribeOn注解,指定订阅线程
- 支持@ObserveOn注解,指定观察线程
- 支持@Backpressure注解,支持3种背压策略(BackpressureStrategy.BUFFER,BackpressureStrategy.DROP,BackpressureStrategy.LATEST)
- 支持apollo core 非注解式使用
- 重写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);
为了避免内存泄露,应在组件生命周期内绑定和解绑。
publicabstractclassBaseActivityextendsActivity {privateApolloBindermBinder;@OverrideprotectedvoidonCreate(BundlesavedInstanceState) { ...mBinder =Apollo.bind(this); }@OverrideprotectedvoidonDestroy() { ...if(mBinder !=null){mBinder.unbind(); } } ...}
让发送更简单
Apollo.emit("event","hello apollo")
让接收更自在
@Receive("event")publicvoidonEvent(Stringmessage){ ...}
默认关闭
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) | 无 |
booleansticky =true;//只有tagApollo.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)
Apollo默认采用kryo来序列化IPC数据对象,你可以提供一个Serializer来修改默认的实现。
Apollo.serializer(newSerializable() {@NotNull@Overridepublicbyte[]serialize(@NotNullObjectobj) { ... }@Overridepublic <T>Tdeserialize(@NotNullbyte[]data,@NotNullClass<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.** { *; }
全面而完善的测试是开源库质量的保证,目前测试用例正在不断完善中:)
KryoSerializeTest
unittest
- RxJava2 - Reactive Extensions for the JVM
- RxAndroid2 - Reactive Extensions for Android
我们使用语义化版本控制规范 作为版本管理,有关可用的版本,请参阅此标签列表。
- lsxiao -lsxiao
更多贡献者 请参考这个项目的列表。
Apache License Version 2.0
About
🚀 Awesome EventBus by RxJava.
Topics
Resources
License
Stars
Watchers
Forks
Packages0
No packages published