Created
January 26, 2017 00:19
-
-
Save Emeritus-DarranKelinske/3ed580732dc36cebdb7bc9059e4a5efe to your computer and use it in GitHub Desktop.
idling resource that waits for child count to be greater than 0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public QuestionOptionIdlingResource(ViewInteraction viewInteraction, long timeout) { | |
this.timeout = timeout; | |
startTime = System.currentTimeMillis(); | |
viewInteraction.check(new ViewAssertion() { | |
@Override | |
public void check(View view, NoMatchingViewException noViewFoundException) { | |
questionView = (LinearLayout) view; | |
} | |
}); | |
} | |
@Override public String getName() { | |
return QuestionOptionIdlingResource.class.getSimpleName(); | |
} | |
@Override | |
public boolean isIdleNow() { | |
long elapsed = System.currentTimeMillis() - startTime; | |
boolean isTimedOut = elapsed >= timeout; | |
boolean idle = hasChildren() || isTimedOut; | |
if (idle) { | |
resourceCallback.onTransitionToIdle(); | |
} | |
return idle; | |
} | |
private boolean hasChildren() { | |
return questionView != null && questionView.getChildCount() > 0; | |
} | |
@Override public void registerIdleTransitionCallback(ResourceCallback resourceCallback) { | |
this.resourceCallback = resourceCallback; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment