How to perform pagination with lithography?

I am implementing APo Retrofit to receive data from the server and showing this in RecyclerViewusing the lithological structure, which is good. Since we all know when we have infinite data to show in recyclerview, we need to implement a pagination template. And I know that, but I'm confused how to implement this in a Lithuanian context. Litho provides a method onScrollListener():

final Component component = Recycler.create(context)
    .binder(recyclerBinder)
    .onScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            //
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            //
        })
    .build();

I don’t know: how to use customized EndlessRecyclerViewScrollListenerfor endless scrolling in Litho?

+3
source share
1 answer

"" , recyclerBinder onScrolled OnScrollListener. :

//Initialize the RecyclerBinder
recyclerBinder = new RecyclerBinder(c, new LinearLayoutInfo(getContext(), OrientationHelper.VERTICAL, false));

//Initialize a recycler component
Component component = Recycler.create(c)
                .onScrollListener(new RecyclerView.OnScrollListener() {
                    @Override
                    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                        super.onScrolled(recyclerView, dx, dy);

                        // use the recyclerBinder to determine what items at what position are visible - 
                        // (you could also use the findLastVisibleItemPosition() method depending on your implementation)
                        int firstVisibleItemPosition = recyclerBinder.findFirstVisibleItemPosition();

                        //check if it is within range relative to the current available items and is not loading (room to improve/modify logic pending use case)
                        if((recyclerBinder.getItemCount() - 5) <= firstVisibleItemPosition && !isLoading) {
                            //if so - use your service to get the next page
                            service.getNextPage();
                        }
                    }
                })
                .build();

,

public void callback(List<T> results) {
    int position = recyclerBinder.getItemCount();
    for(T result: results) {
        Component component = //assemble your component(s) ...
        ComponentInfo.Builder info = ComponentInfo.create().component(component);
        recyclerBinder.insertItemAt(position, info.build());
        position++;
    }
}
+1

Source: https://habr.com/ru/post/1677886/


All Articles