How to retain ScrollWheel Indices between model and view for screen changes.
Hi,
I'm trying to use a scroll wheel with a custom container to select the number of seconds an output will be on. The scroll wheel is on it's own screen which is accessed from a main screen. The scroll wheel index information is used as a system initialization/setup variable and needs to be able to be retained in the model when switching screens, so when the scroll wheel screen is reopened, the scroll wheel(s) show the previously selected value.
In the view I'm using the following base scroll wheel functions.
//Zone 1 Purge
void PurgeSetupView::scrollWheelZone1PrePurgeUpdateItem(textScrollContainer& item, int16_t itemIndex)
{
item.updateText(itemIndex);
presenter->userSetZone1PrePurge(itemIndex);
}
void PurgeSetupView::scrollWheelZone1PrePurgeUpdateCenterItem(textScrollCenterContainer& item, int16_t itemIndex)
{
item.updateText(itemIndex);
presenter->userSetZone1PrePurge(itemIndex);
}
void PurgeSetupView::setZone1PrePurge(int16_t itemIndex)
{
zone1prepurge = itemIndex; //test variable
scrollWheelZone1PrePurge.animateToItem(itemIndex, 0); //animate to the previously set item.
scrollWheelZone1PrePurge.invalidate();
}In the presenter I'm passing the itemIndex to the model and storing (all seems correct here when stepping through).
#ifndef PURGESETUPPRESENTER_HPP
#define PURGESETUPPRESENTER_HPP
#include <gui/model/ModelListener.hpp>
#include <mvp/Presenter.hpp>
using namespace touchgfx;
class PurgeSetupView;
class PurgeSetupPresenter : public touchgfx::Presenter, public ModelListener
{
public:
PurgeSetupPresenter(PurgeSetupView& v);
//Pre Purge Model Updates
void userSetZone1PrePurge(int16_t countIndex)
{
model->userSetZone1PrePurge(countIndex);
}
/**
* The activate function is called automatically when this screen is "switched in"
* (ie. made active). Initialization logic can be placed here.
*/
virtual void activate();
/**
* The deactivate function is called automatically when this screen is "switched out"
* (ie. made inactive). Teardown functionality can be placed here.
*/
virtual void deactivate();
virtual ~PurgeSetupPresenter() {};
private:
PurgeSetupPresenter();
PurgeSetupView& view;
};
#endif // PURGESETUPPRESENTER_HPP//Model.cpp
/*Zone Pre Purge Model State Values*/
void Model::userSetZone1PrePurge(int16_t countIndex)
{
zone1PrePurgeValue = countIndex;
}On the scroll wheel screen the updating of the scroll wheel value indicates properly. When I go back to the main screen and reopen the scroll wheel screen I call the 'view' function 'setZone1PrePurge' on activate to update, but the 'itemIndex/presented value' always reverts to 1.
#include <gui/purgesetup_screen/PurgeSetupView.hpp>
#include <gui/purgesetup_screen/PurgeSetupPresenter.hpp>
PurgeSetupPresenter::PurgeSetupPresenter(PurgeSetupView& v)
: view(v)
{
}
void PurgeSetupPresenter::activate()
{
view.setZone1PrePurge(model->getZone1PrePurge());
}
void PurgeSetupPresenter::deactivate()
{
}It seems that the value gets overwritten somewhere, but I can't figure out where. Or when the purge screen opens it reinitializes to the list through the 'setupScreen();'
PurgeSetupViewBase::setupScreen();
/*******Following within PurgeSetupViewBase***********************/
scrollWheelZone1PostPurge.initialize();
for (int i = 0; i < scrollWheelZone1PostPurgeListItems.getNumberOfDrawables(); i++)
{
scrollWheelZone1PostPurgeListItems[i].initialize();
}
for (int i = 0; i < scrollWheelZone1PostPurgeSelectedListItems.getNumberOfDrawables(); i++)
{
scrollWheelZone1PostPurgeSelectedListItems[i].initialize();
}How can I accomplish saving of the scroll wheel value/location so upon screen initialization it pulls the indices from the model and updates properly?
Thanks!
