Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct way to load dynamic content in wizard #13

Open
femosso opened this issue Oct 11, 2015 · 2 comments
Open

Correct way to load dynamic content in wizard #13

femosso opened this issue Oct 11, 2015 · 2 comments

Comments

@femosso
Copy link

femosso commented Oct 11, 2015

In the sample code the AbstractWizardModel is being statically instantiated when MainActivity is created. Once this is done, the onNewRootPageList() callback is immediately triggered in the wizard model and I couldn't find a way to load the PageList with some dynamic contents.

The workaround I found for this is to make AbstractWizardModel class a inner class in MainActivity and have my dynamic content a global variable so I could access it from AbstractWizardModel. This generates a side effect since I'm no longer instantiating AbstractWizardModel class when the MainActivity is create. I'm instantiating it o onCreate() callback, so it is being called some time later in comparison with original code.

Is there an alternative way to load content in the form (PageList) dynamically?

@jppasa
Copy link

jppasa commented Apr 13, 2016

@femosso
Late response, but in case you need it. I made a workaround, but this is not the best solution. Also, it is not dynamic in the sense of adding pages at any time.

I downloaded all the code and inserted it into my app's code. Then I had to resolve all issues (copy resources, etc.)

Then, I modified AbstractWizardModel the following way:

public AbstractWizardModel(Context context) {
    mContext = context;
}

public void startRootPageList() {
    mRootPageList = onNewRootPageList();
}

Then, my wizard model constructor:

public WizardModel(Context context, Content content) {
    super(context);
    this.content = content;
    super.startRootPageList();
}

Finally, onNewRootPageList callback:

@Override
protected PageList onNewRootPageList() {
    if (content != null) {
        PageList pageList = new PageList();
        // Add pages to pageList according to content
        return pageList;
    }
    return new PageList();
}

@lauksas
Copy link

lauksas commented Sep 9, 2018

Old post, still this answer can help someone.
I got it resolved by moving the AbstractWizzardModel instantiation to the onCreate method on the Activity. Like below:

public class WizardActivity extends FragmentActivity implements
        PageFragmentCallbacks,
        ReviewFragment.Callbacks,
        ModelCallbacks {
     private AbstractWizardModel mWizardModel;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mWizardModel = new ActivityWizardModel(this);
    }
}

With that change you can do:
mContext.getString(R.string.your_string)
in any place at you concrete model.

I hope that helps.
PS: you can't load resource at that time because the method onCreate() do an eternal loop when you try to get the application context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants