Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Emeritus-DarranKelinske/3ed580732dc36cebdb7bc9059e4a5efe to your computer and use it in GitHub Desktop.
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
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