cancel
Showing results for 
Search instead for 
Did you mean: 

How to retain ScrollWheel Indices between model and view for screen changes.

LBend.1
Associate III

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!

1 ACCEPTED SOLUTION

Accepted Solutions

Setter need call only in tearDownScreen(), but you need in view get actual marked index.

View solution in original post

6 REPLIES 6
MM..1
Chief II

I mean your idea use activate presenter is fail. You need do setup in screen setup call for example symbolic

void Screen3View::setupScreen() {
  Screen3ViewBase::setupScreen();
  xxindex = presenter->getsomevalue(); // this need one getter in presenter and second in model
setZone1PrePurge(xxindex);
}

I think I already tried that as well, but maybe I'm missing something? It always returns 1 for this.

ScreenView:

void PurgeSetupView::setupScreen()
{
	PurgeSetupViewBase::setupScreen();
 
	zone1prepurge = presenter->getZone1PrePurge();
	setZone1PrePurge(zone1prepurge);
}

Presenter:

#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);
	}
	int16_t getZone1PrePurge()
	{
		return model->getZone1PrePurge();
	}
 
    /**
     * 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.hpp:

	/******************************
	 * Purge Setup Model Callbacks
	 ******************************/
 
	int16_t getZone1PrePurge() const
	{
		return zone1PrePurgeValue;
	}

As first check and debug one direction for example in model hpp

public:
...
    virtual int16_t getZone1PrePurge();
protected:
    int zone1PrePurgeValue;

and code place in model cpp

	int16_t getZone1PrePurge()
	{
		return zone1PrePurgeValue;
	}

and init model with value for test

Model::Model() :
		zone1PrePurgeValue(2),
                modelListener(0) {
}

comment out calls setter...

This is the right direction for sure. Doing this and commenting out the setters in the view enable the initialized value of 2 to show up properly. Any thoughts on the retaining of a new scrolled to value? When I uncomment the following in the view, it reverts to 1.

//Zone 1 Purge
void PurgeSetupView::scrollWheelZone1PrePurgeUpdateItem(textScrollContainer& item, int16_t itemIndex)
{
	//presenter->userSetZone1PrePurge(itemIndex);
	item.updateText(itemIndex);
}
void PurgeSetupView::scrollWheelZone1PrePurgeUpdateCenterItem(textScrollCenterContainer& item, int16_t itemIndex)
{
	//presenter->userSetZone1PrePurge(itemIndex);
	item.updateText(itemIndex);
}

Setter need call only in tearDownScreen(), but you need in view get actual marked index.

This works! I think since my scroll list starts at value zero, but indices at 1 maybe I have to subtract 1 to get the proper displayed value. Otherwise every time I reopen the page the value increments by 1.

void PurgeSetupView::scrollWheelZone1PrePurgeUpdateCenterItem(textScrollCenterContainer& item, int16_t itemIndex)
{
	item.updateText(itemIndex);
	zone1prepurge = itemIndex-1;
}

Thanks!