0

Note : This is a question that I asked straight on the LightCycle project github. It's a great tool from SongKick to build a clean MVP architecture over your android app .


There is a thing that I miss thought, I have an activity with many fragments and many fragmentsPresenters. Sometimes I do computation on my activity presenter and I want to send it to one or many of the fragment presenters (for example my table of content is displayes in the activity menu, and in a fragment that is shown full screen at the beginning).

How to I add a keep a reference of fragment presenters in my activity presenters (maybe it's not how I'm supposed to design it).

Second question. I have MyActivityPresenter that has two children : MyOnlineActivityPresenter and MyOfflineActivityPresenter. MyActivityPresenter.newPresenter(Network.isNetworkAvailable(contexte), few other args) decides whearas an online or offline presenter is instanciated. So I should do something like :

@LightCycle
PlayerPresenter presenter = PlayerPresenter.get(NetworkUtils.isNetworkAvailable(this));

But I've been told that I should never use context that way as It could be null at the class instanciation moment. Is it indeed a problem ?

also should I pass the few others arguments that I have in the onCreate Bundle ?

And I don't use dependency injection at the moment.

I hope that I'm clear, thanks again for this very useful lib

Renaud Favier
  • 1,645
  • 1
  • 17
  • 33

1 Answers1

0

This is the answer they gave me


How to I add a keep a reference of fragment presenters in my activity presenters (maybe it's not how I'm supposed to design it).

It is not something in the scope of this library. I can see 2 solutions for you :

  • inject the same instance
  • provide an accessor to the presenter from the fragment. (which seems to be better for you).

But I've been told that I should never use context that way as It could be null at the class instantiation moment. Is it indeed a problem ? also should I pass the few others arguments that I have in the onCreate Bundle ?

Same here.

  • You can use the app context which should be available and enough in your case
  • You can init this guy in the constructor because binding happens on create
Renaud Favier
  • 1,645
  • 1
  • 17
  • 33