@Result(FlickrApi.LOAD_IMAGES_EVENT)
  private void onPhotosLoaded(List<Photo> photos, boolean hasMore) {
    mPhotoCount = photos.size();
    mGridAdapter.setPhotos(photos, hasMore);
    mPagerAdapter.setPhotos(photos);
    mGridAdapter.onNextItemsLoaded();

    // Ensure listener called for 0 position
    mPagerListener.onPageSelected(mViews.pager.getCurrentItem());

    // Restoring saved state
    if (mPagerPhotoPosition != -1) {
      if (mPagerPhotoPosition < mPhotoCount) {
        mPagerAdapter.setActivated(true);
        mAnimator.enter(mPagerPhotoPosition, false);
      }
      mPagerPhotoPosition = -1;
    }

    if (mGridPosition != -1) {
      if (mGridPosition < mPhotoCount) {
        ((GridLayoutManager) mViews.grid.getLayoutManager())
            .scrollToPositionWithOffset(mGridPosition, mGridPositionFromTop);
      }
      mGridPosition = -1;
      mGridPositionFromTop = 0;
    }
  }
  private void initGrid() {
    // Setting up images grid
    final int cols = getResources().getInteger(R.integer.images_grid_columns);

    mViews.grid.setLayoutManager(new GridLayoutManager(this, cols));
    mViews.grid.setItemAnimator(new DefaultItemAnimator());

    mGridAdapter = new FlickrPhotoListAdapter(this);
    mGridAdapter.setLoadingOffset(PAGE_SIZE / 2);
    mGridAdapter.setCallbacks(
        new EndlessRecyclerAdapter.LoaderCallbacks() {
          @Override
          public boolean canLoadNextItems() {
            return mGridAdapter.canLoadNext();
          }

          @Override
          public void loadNextItems() {
            // We should either load all items that were loaded before state save / restore,
            // or next page if we already loaded all previously shown items
            int count = Math.max(mPhotoCount, mGridAdapter.getCount() + PAGE_SIZE);
            Events.create(FlickrApi.LOAD_IMAGES_EVENT).param(count).post();
          }
        });
    mViews.grid.setAdapter(mGridAdapter);
  }
  @Failure(FlickrApi.LOAD_IMAGES_EVENT)
  private void onPhotosLoadFail() {
    mGridAdapter.onNextItemsError();

    // Skipping state restoration
    if (mPagerPhotoPosition != -1) {
      // We can't show image right now, so we should return back to list
      onPositionUpdate(0f, true);
    }

    mPagerPhotoPosition = -1;
    mGridPosition = -1;
    mGridPositionFromTop = 0;
  }