cancel
Showing results for 
Search instead for 
Did you mean: 

Presenter / View ... which gets initialized first?

j o
Associate II

I'm trying to use the MVP system in what is hopefully a correct manner. The way I understand it, the Presenter takes the data from the Model and assembles it in a way that the View can display.

However, in the present implementation of the MVP in TouchGFX, the view is being configured before the Presenter has a chance to configure this information.

For example, when trying to implement a scroll wheel, I'm supposed to override the ScrollWheelUpdateItem as below:

void Screen2View::scrollWheel1UpdateItem(ListItem& item, int16_t itemIndex)
{
    touchgfx::TypedTextId id = presenter->getParameterOptionText(itemIndex);
    std::cout << "Setting text index to:" << id << std::endl;
    item.setText(id);
}

However, the call tree for switching to a different view is first initializing the view and *then* initializing the presenter. The following is from the TouchGFX library (MVPApplication.hpp):

static inline void finalizeTransition(Screen* newScreen, Presenter* newPresenter, Transition* newTransition)
{
    newScreen->setupScreen();
    newPresenter->activate();
    newScreen->bindTransition(*newTransition);
    newTransition->init();
 
    Application::getInstance()->draw();
}

As you can see, "setupScreen" is called *before* the presenter has been activated. Why? When the "setupScreen" is called, it's calling functions that rely on the presenter, which doesn't have the information yet. To me, it would make much more sense that lines 3&4 are swapped. Am I missing something?

Thanks,

Jeremy

2 REPLIES 2
userRobert
Associate II

I believe this order of execution.

TouchGFX Order of Execution

[MODEL   ]:Constructor()

[ VIEW :Main   ]:Constructor()

[MODEL_LISTENER]:Constructor()

[ PRESENTER :Main]:Constructor()

      [ VIEW :Main   ]-> setupScreen()

      [ PRESENTER :Main]-> activate()

      [ VIEW :Main   ]-> tearDownScreen

      [ PRESENTER :Main]-> deactivate()

[ VIEW :Main   ]:Destructor()

[ PRESENTER :Main]:Destructor()

[MODEL_LISTENER]:Destructor()

j o
Associate II

I know that's the order of execution, but as I said in my email, why is the presenter being activated *after* the screen is being setup? It needs the data that isn't yet activated in the presenter. If "activate" isn't supposed to setup data, what is it supposed to do, and where to I setup my data?