Skip to content
This repository has been archived by the owner on Jan 3, 2019. It is now read-only.

WizardStep.notifyCompleted() causing focus loss #61

Open
nghamilton opened this issue Apr 27, 2015 · 14 comments
Open

WizardStep.notifyCompleted() causing focus loss #61

nghamilton opened this issue Apr 27, 2015 · 14 comments

Comments

@nghamilton
Copy link

Hello,

I am not convinced this isn't my implementation, but it seems that the notifyCompleted() method is causing interference with EditText field focus.

I have a test on whether a field has text entered (also tried other methods, such as with a OnFocusChangeListener and a setOnEditorActionListener, with same result). After a call to notifyCompleted() focus in the textfield is lost (I can't work out what element it moves to). Does this sound like it is something that could be happening from inside notifyCompleted()?

Thank you for any thoughts.

    editText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            //Save the wizard state so that the user can proceed, if a name has been entered
            if (s.toString().length() > 0)
                notifyCompleted();
            else
                notifyIncomplete();
        }
@Nimrodda
Copy link
Owner

Nimrodda commented May 1, 2015

Short answer: yes, it does. Unfortunately there doesn't seem to be anything that I currently can do about it. You should set the focus back to the UI element, which lost it.
Long answer:
when you call one of the notify methods, it posts a StepCompletedEvent event, which is then picked up by the Wizard's receive() and directly to onStepCompleted(), which has to call the ViewPager's adapter.notifyDataSetChanged() in order to rebuild the pages in the ViewPager and "open" the next step.

 @Override
    public void receive(Object event) {
        StepCompletedEvent stepCompletedEvent = (StepCompletedEvent) event;
        onStepCompleted(stepCompletedEvent.isStepCompleted(), stepCompletedEvent.getStep());
    }

    private void onStepCompleted(boolean isComplete, WizardStep step) {
        if (step != getCurrentStep()) return;
        int stepPosition = getCurrentStepPosition();


        // Check that the step is not already in this state to avoid spamming the viewpager
        if (wizardFlow.isStepCompleted(stepPosition) != isComplete) {
            wizardFlow.setStepCompleted(stepPosition, isComplete);
            mPager.getAdapter().notifyDataSetChanged();
            //Refresh the UI
            callbacks.onStepChanged();
        }
    }

It is mPager.getAdapter().notifyDataSetChanged(); which causes the loss of focus, since it's redrawing the UI.

@nghamilton
Copy link
Author

Thanks - I fixed it by extending your code and including a validation
callback on the steps, made the user interaction a bit neater for me as
well.

On Sat, May 2, 2015 at 12:43 AM, Nimrod Dayan [email protected]
wrote:

Short answer: yes, it does. Unfortunately there doesn't seem to be
anything that I currently can do about it. You should set the focus back to
the UI element, which lost it.
Long answer:
when you call one of the notify methods, it posts a StepCompletedEvent
event, which is then picked up by the Wizard's receive() and directly to
onStepCompleted(), which has to call the ViewPager's
adapter.notifyDataSetChanged() in order to rebuild the pages in the
ViewPager and "open" the next step.

@OverRide
public void receive(Object event) {
StepCompletedEvent stepCompletedEvent = (StepCompletedEvent) event;
onStepCompleted(stepCompletedEvent.isStepCompleted(), stepCompletedEvent.getStep());
}

private void onStepCompleted(boolean isComplete, WizardStep step) {
    if (step != getCurrentStep()) return;
    int stepPosition = getCurrentStepPosition();


    // Check that the step is not already in this state to avoid spamming the viewpager
    if (wizardFlow.isStepCompleted(stepPosition) != isComplete) {
        wizardFlow.setStepCompleted(stepPosition, isComplete);
        mPager.getAdapter().notifyDataSetChanged();
        //Refresh the UI
        callbacks.onStepChanged();
    }
}


Reply to this email directly or view it on GitHub
#61 (comment).

@Nimrodda
Copy link
Owner

Nimrodda commented May 8, 2015

care to share your solution? or perhaps make a pull request? thanks!

@alexissilva
Copy link

i have the same problem. please fix it :D.

@locomundo
Copy link

I have the same problem too. @nghamilton if you share your solution it would help. Thanks!

@nghamilton
Copy link
Author

Sorry for the late response; I made quite a few changes to the code, some of it was through extensions and some through the modifications to the wizardroid code. I'll try to create a branch now that has just a fix for this issue, and set up a pull request.

@nghamilton
Copy link
Author

I've pushed my changes to the branch I am working on: https://github.com/nghamilton/WizarDroid. I didn't fix this above issue, just worked around it with the features I've put in (validation and a goNext() event).

My code also allows for running a wizard within another wizard.

Be warned: this was code I hacked to use for what I needed. This also included changing the way the back button worked, and what happened when the user swiped.

I'll try to be faster to respond next time, if you have any questions, shoot them through to me.

@locomundo
Copy link

Thanks! I'll take a look.

I managed to fix it by extending a few of the classes. If anyone is interested I can write a summary of my changes. I didn't modify the wizaedroid library code, so no pull request.

I do have suggestions to make some members of some classes protected, so it can be easily extended.

@Nimrodda
Copy link
Owner

@locomundo feel free to share what you've done.
From WizarDroid perspective, notifyCompleted() should be called when the user is done interacting with the current step and ready to proceed to the next one. Whether the input from the user is valid or not is not the concern of the library. The user of the library should validate the input before calling notifyCompleted().

@marekas
Copy link

marekas commented Aug 20, 2015

thanks locomundo,

can you post your solution here how to extend these classes?

Marek

@boomsya
Copy link

boomsya commented Dec 16, 2015

the same problem with validation fields
after calling notifyCompleted() i have onCreate, onCreateView - app go crazy after that

i think when next step unlock - wizard tell to adapter what we have +1 pages and re-create pages :(((

@avrahamshukron
Copy link

@Nimrodda Why do you have to call notifyDataSetChanged() when a step is marked complete/incomplete? it sounds like enabling/disabling the Next button will be enough....

@Nimrodda
Copy link
Owner

@avrahamshukron calling notifyDataSetChanged() is necessary after adding/removing fragments from ViewPager.

@bsysop
Copy link

bsysop commented Jan 23, 2016

+1, will be great this feature.

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

No branches or pull requests

8 participants