Search in sources :

Example 1 with PhotoListAdapter

use of com.alexvasilkov.gestures.sample.demo.adapter.PhotoListAdapter in project GestureViews by alexvasilkov.

the class DemoActivity method initGrid.

/**
 * Initializing grid view (RecyclerView) and endless loading.
 */
private void initGrid() {
    // Setting up images grid
    final int cols = getResources().getInteger(R.integer.images_grid_columns);
    views.grid.setLayoutManager(new GridLayoutManager(this, cols));
    gridAdapter = new PhotoListAdapter(this);
    gridAdapter.setLoadingOffset(PAGE_SIZE / 2);
    gridAdapter.setCallbacks(new EndlessRecyclerAdapter.LoaderCallbacks() {

        @Override
        public boolean canLoadNextItems() {
            return gridAdapter.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(savedPhotoCount, gridAdapter.getCount() + PAGE_SIZE);
            Events.create(FlickrApi.LOAD_IMAGES_EVENT).param(count).post();
        }
    });
    views.grid.setAdapter(gridAdapter);
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) PhotoListAdapter(com.alexvasilkov.gestures.sample.demo.adapter.PhotoListAdapter) EndlessRecyclerAdapter(com.alexvasilkov.gestures.sample.demo.adapter.EndlessRecyclerAdapter) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)1 EndlessRecyclerAdapter (com.alexvasilkov.gestures.sample.demo.adapter.EndlessRecyclerAdapter)1 PhotoListAdapter (com.alexvasilkov.gestures.sample.demo.adapter.PhotoListAdapter)1