Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotation processor #4

Open
MFlisar opened this issue Jan 30, 2018 · 0 comments
Open

Annotation processor #4

MFlisar opened this issue Jan 30, 2018 · 0 comments

Comments

@MFlisar
Copy link
Owner

MFlisar commented Jan 30, 2018

Idea

  1. Define subcriptions via annotations:

     @RxBusSubscribe
     public void onEvent(Event event) {
         // handle bus event here
     }
    
  2. Annotation processor should generate functions in this class:

     public final void subscribeRxBusEvents() {
          // generated code
          // disposables must be managed by the class so those are bound to this class
     }
    
    public final void unsubscribeRxBusEvents() {
        RxDisposableManager.unsubscribe(this);
    }
    
  3. user calls subscribeRxBusEvents() wherever he wants to subscribe all annotated functions in this class to bus - manually

  4. user also calls unsubscribeRxBusEvents() wherever he wants to unsubscribe all annotated functions in this class from bus - manually

Settings

@RxBusSubscribe has following annotation fields:

  • queuing... defines the RxBusBuilders withQueuing value
  • mode... defines the RxBusBuilders withMode value
  • key/keys... defines the RxBusBuilders withKey value

RxBusBuilder.create(<CLASS>.class) is derived from the annotated functions parameter class. public void onEvent(Event event) will generate a RxBusBuilder.create(Event.class) code line

Examples

    @RxBusSubscribe(queuing = false, mode = RxBusMode.Main)
    public void onEvent(Event event) {
        // handle bus event here
    }        

    @RxBusSubscribe(queuing = false, mode = RxBusMode.Main, key = R.integer.key1)
    public void onEvent(Event event) {
        // handle bus event here
    }

    @RxBusSubscribe(queuing = true, mode = RxBusMode.Background, keys = {R.integer.key1, R.integer.key2})
    public void onEvent(Event event) {
        // handle bus event here
    }

    @RxBusSubscribe(queuing = true, mode = RxBusMode.Background, keys = {"key1", "key2"})
    public void onEvent(Event event) {
        // handle bus event here
    }

TODO

  • just a idea so far
  • rethink annotation names
  • maybe enable auto subscribtion/unsubscription for classes with lifecycle via an additional annotation for the class itself (for Activity/Fragment/...). This could generate code that subscribes to the bus in the constructor/onCreate/onResume and unsubscribes them in the appropriate counter function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant