Skip to content
This repository has been archived by the owner on Apr 30, 2019. It is now read-only.

Allow to use Otto with AndroidAnnotations' generated classes. #15

Closed
wants to merge 1 commit into from

Conversation

naixx
Copy link

@naixx naixx commented Jul 28, 2012

There is a problem using https://github.com/excilys/androidannotations with Otto. When we pass this to Otto, it can see generated by AA class, which doesn't have any @Subscribe and @Produce annotations.
The first solution is to wrap all annotated methods on ClassA_ in the AndroidAnnotations project, something like this:

@EActivity
class ClassActivity{
  @Subscribe public void onMyEvent(Event event){
    //...
  }
}

Generated class could be:

class ClassActivity_{
  @Subscribe public void onMyEvent_(Event event){
    onMyEvent(event);  
  }
}

We use wrappers for methods to call this.onMyEvent which could be overriden in ClassActivity_

But it is rather complicated to generate lots of code. The easiest way is to modify Otto a bit. We assume, that ClassA_ is generated by AA from ClassA.

…me, that ClassA_ is generated by AA from ClassA.
@swankjesse
Copy link
Member

I'd rather otto do its own code generation. It's not too difficult and we can avoid a third-party dependency.

@JakeWharton
Copy link
Member

We're going to address this soon with code-generation. It also avoids this magic behavior which can lead to undesirable results.

@naixx
Copy link
Author

naixx commented Jul 31, 2012

@JakeWharton, can you please tell, what to expect?

@pyricau
Copy link
Member

pyricau commented Aug 9, 2012

Just came across this :) . I'm interested in knowing more about that "soon to come code generation". Any pointer :) ?

@pzmudzinski
Copy link

Any news about this issue?

@shrift
Copy link

shrift commented Sep 7, 2012

I believe I have run into this issue as well... Using AndroidAnnotations to enhance a fragment, and also to inject several fields (including Otto), I find that despite calling register in the enhanced fragment my @subscribe method does not receive any events. Indeed, all of those events end up in the DeadEvents listener... I had read that in theory as long as AndroidAnnotations does not override the @subscribe annotated method, the events would still get delivered, but it seems they are not. Perhaps this is due to the fragment being created in xml (where you have to reference the EnhancedFragment_ class)?

Anyways, very lengthy round about way of saying, I would love for "seamless" integration of Otto and AndroidAnnotations.

I'd be happy to help if there is any way I can.

@JakeWharton
Copy link
Member

The next major version of the library will restore superclass @Subscribe and @Produce functionality.

@shrift
Copy link

shrift commented Sep 7, 2012

Ah, fantastic. Thanks Jake!

@scottagarman
Copy link

Jake, has the superclass @Subscribe and @Produce functionality been restored? I can't seem to get it to work in versions after 1.2.1.

@JakeWharton
Copy link
Member

No, not yet. Haven't had time to work on the code-gen variant which would allow it's restoration without any performance impact.

@pyricau
Copy link
Member

pyricau commented Dec 17, 2012

If you're willing to work with experimental / unstable stuff, @JakeWharton actually wrote a POC on a branch. Here is a usage example: https://github.com/pyricau/CleanAndroidCode

@pyricau
Copy link
Member

pyricau commented Mar 5, 2013

AndroidAnnotations now correctly integrates with Otto, see androidannotations/androidannotations#526

@pzmudzinski
Copy link

Is it fixed in AA 2.7.1? Or is it fixed in latest Otto release?

@atali
Copy link

atali commented May 24, 2013

Great !!!!!!!!!!!!!!

pyricau added a commit that referenced this pull request Sep 19, 2013
abort post early if bus is destroyed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants