Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Latest commit

 

History

History
182 lines (136 loc) · 5.06 KB

README-EN.md

File metadata and controls

182 lines (136 loc) · 5.06 KB

Apollo

Inter-Process Communication , Compile-time Annotation.

Apollo , make RxBus simplified but not simple.

English Document

Start

quick integration with 3 minutes

integration

use jitpack in your module.

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

depend these in your build.gralde.

dependencies {
  implementation "io.reactivex.rxjava2:rxandroid:2.0.1"

  implementation "com.github.lsxiao.Apollo:core:1.0.2"

  //IPC module,optional
  implementation "com.github.lsxiao.Apollo:ipc:1.0.2"

  annotationProcessor "com.github.lsxiao.Apollo:processor:1.0.2"

  //for kotlin
  kapt "com.github.lsxiao.Apollo:processor:1.0.2"
}

Usage

init

ApolloBinderGeneratorImpl在编译时生成。

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

bind/unbind

In order to avoid memory leaks, it should be bind and unbind within the component lifecycle.

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

emit

make emit easier.

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

receive

receive anywhere you like.

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

ipc

default is closed.

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

your data object which need to ipc must has a non-parameter-constructor,because apollo used kory to serialize object.

more usage see below.

Advanced Usage

Annotation List

Notice!!!,The annotated function must be public, and @Receive is required ,others is optional.

annotation parameter description default
@Receive string tag list, or a string
@Sticky remove is remove after receive event. ture
@SubscribeOn subscribe on scheduler SchedulerProvider.Tag.IO
@ObserveOn observe on scheduler SchedulerProvider.Tag.MAIN
@Take how many times can be received.
@Backpressure backpressure strategy(BackpressureStrategy.BUFFER,BackpressureStrategy.DROP,BackpressureStrategy.LATEST)

Method

boolean sticky = true;

//only tag
Apollo.emit("tag");
//tag and object
Apollo.emit("tag","event");

//stikcy(can received event which is annotated by @Sticky)
Apollo.emit("tag","event",stikcy)
//only tag and stikcy
Apollo.emit("tag",sticky)

Custom Serializer

Apollo use kory to serialize object,you can override it by providing a 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) {
        ...
    }
});

ProGuard

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

Build with ReactiveX

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

How to contribute

welcome pr.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • lsxiao - Android developer - lsxiao See also the list of contributors who participated in this project.

License

Apache License Version 2.0

Acknowledgments

  • All I love, and who love me.