Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.