in app/src/main/java/com/google/reviewit/widget/ScrollWithHeadingsView.java [92:141]
public void setContent(Iterator<Content> contentProvider) {
Content prevContent = null;
Content nextContent = contentProvider.hasNext()
? contentProvider.next()
: null;
while (nextContent != null) {
final Content content = nextContent;
contents.add(content);
nextContent = contentProvider.hasNext()
? contentProvider.next()
: null;
final boolean setWindowColor = prevContent == null;
post(new Runnable() {
@Override
public void run() {
addHeading(content);
if (setWindowColor) {
setWindowColor(content.getHeading());
}
scrollContent.addView(content.getContent());
}
});
prevContent = content;
}
onScrollListener = new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
Iterator<Content> it = contents.iterator();
Content prevContent = null;
Content nextContent = it.hasNext() ? it.next() : null;
while (nextContent != null) {
Content content = nextContent;
nextContent = it.hasNext() ? it.next() : null;
ScrollWithHeadingsView.this.onScrollChanged(
content, prevContent, nextContent);
prevContent = content;
}
}
};
scroll.getViewTreeObserver().addOnScrollChangedListener(onScrollListener);
LayoutUtil.addOneTimeOnGlobalLayoutListener(scroll,
new LayoutUtil.OneTimeOnGlobalLayoutListener() {
@Override
public void onFirstGlobalLayout() {
relayout();
}
});
}