use of com.alexvasilkov.events.Events.Result in project GestureViews by alexvasilkov.
the class DemoActivity method onPhotosLoaded.
/**
* Photos loading results callback.
*/
@Result(FlickrApi.LOAD_IMAGES_EVENT)
private void onPhotosLoaded(List<Photo> photos, boolean hasMore) {
// RecyclerView will continue scrolling when new items are added, we need to stop it.
// Seems like this buggy behavior was introduced in support library v26.0.x
final boolean onBottom = views.grid.findViewHolderForAdapterPosition(gridAdapter.getCount() - 1) != null;
if (onBottom) {
views.grid.stopScroll();
}
// Setting new photos list
gridAdapter.setPhotos(photos, hasMore);
pagerAdapter.setPhotos(photos);
gridAdapter.onNextItemsLoaded();
// Ensure listener called for 0 position
pagerListener.onPageSelected(views.pager.getCurrentItem());
// Restoring saved state
if (savedPagerPosition != NO_POSITION && savedPagerPosition < photos.size()) {
pagerAdapter.setActivated(true);
listAnimator.enter(savedPagerPosition, false);
}
if (savedGridPosition != NO_POSITION && savedGridPosition < photos.size()) {
GridLayoutManager manager = (GridLayoutManager) Objects.requireNonNull(views.grid.getLayoutManager());
manager.scrollToPositionWithOffset(savedGridPosition, savedGridPositionFromTop);
}
clearScreenState();
}
Aggregations