Skip to content
This repository has been archived by the owner on Dec 26, 2023. It is now read-only.

fcannizzaro/fast-event

Repository files navigation

fast-event

Simple event creation

Build Status Android Arsenal

How to include

Step 1. Add it in your root build.gradle at the end of repositories:

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

Step 2. Add the dependency

dependencies {
    compile 'com.github.fcannizzaro:fast-event:1.0.0'
}

Static Methods

bind(Class clazz, [, Activity activity])

register event annotations.

emit(event, Object ... args)

emit event.

delete(event)

delete event.

Annotations

@Event(String: event)

define method to run.

@OnUi

run method on ui.

@Async

run method on a thread.

Usage

Activity / Service / Class

class Sample extends Activity {

    @OnUi
    @Event("my-event")
    private void onUpdate(String key, Integer counter) {
        // do something
    }

    @Async
    @Event("my-event-on-thread")
    private void onUpdate(String key) {
        // do something
    }
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ...
        FastEvent.bind(this);
        ...
    }
    
}

Fragment

class Sample extends Fragment {

    // define events
    // ...
    
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        ...
        FastEvent.bind(this, getActivity());
        ...
    }
    
}

Emit

 FastEvent.emit("my-event", "fcannizzaro", 20);

License

MIT - Francesco Cannizzaro