Call-Through Events listener as a separated class

16 views
Skip to first unread message

Mingfai

unread,
Jun 23, 2013, 6:23:17 PM6/23/13
to tran...@googlegroups.com
hi,

Let's take ActivityMenuComponent as an example, two activity may share the same listener. And for me, without Transfuse, I just put the handling of Menu stuff in a separated class (initially an inner class, at the end I moved all action bar related event handling stuff to a standalone class) for code maintainable. 

Wouldn't it be nice if the ActivityMenuComponent can actually be a separated class configured by annotation and be wired to handle events in an activity? 

For sure, the implementation class with need to have the Activity injected to it, otherwise it cannot do anything meaningful. 

regards,
mingfai

Mingfai

unread,
Jun 23, 2013, 7:28:25 PM6/23/13
to tran...@googlegroups.com
On Mon, Jun 24, 2013 at 6:23 AM, Mingfai <mingf...@gmail.com> wrote:

Wouldn't it be nice if the ActivityMenuComponent can actually be a separated class configured by annotation and be wired to handle events in an activity? 


with Transfuse, my activity classes doesn't need to extend Activity, I can make the ActivityMenuComponent implementation class as the superclass of an Activity. 

i.e.
@Activity @RegisterListener
class Main extends MenuController{}

class MenuController implements ActivityMenuComponent{ /** implementation */ }

it serves my purpose of separating menu/actionbar event handling code. 

regards,
mingfai 

John Ericksen

unread,
Jun 24, 2013, 11:43:44 PM6/24/13
to tran...@googlegroups.com
Mingfai,

You can share an ActivityMenuComponent between two classes.  You simply have to inject the shared component into both and annotate that Injection with @RegisterListener:

class MenuController implements ActivityMenuComponent{...}

@Activity
class One{
  @inject @RegisterListener
  MenuController controller;
}

@Activity
class Twp{
  @inject @RegisterListener
  MenuController controller;
}

And yes, you can inject the current Activity into the MenuController.  Just make sure the MenuController is either prototype scoped (prefered) or context scoped.

If you're playing with ActionBars, I'd appreciate some feedback.  I have an issue open currently to investigate integrating ActionBarSherlock as a plugin.

Hope that clears up any questions.

John
Reply all
Reply to author
Forward
0 new messages