idanatz / OneAdapter

A Viewholderless Adapter for RecyclerView, who supports builtin diffing, states (paging, empty...), events (clicking, swiping...), and more.
MIT License
470 stars 45 forks source link

Problem pagination #28

Closed saiid2020 closed 3 years ago

saiid2020 commented 3 years ago

In pagination, after adding new items, you return to the top of the list and new items are added to the bottom of the list.

idanatz commented 3 years ago

As I said in the previous bug, there is Java implementation in the sample project. In this implementation when reaching loadMore, more items are added and the list does not return to the top. Check what is the difference between your implementation and mine.

https://github.com/ironSource/OneAdapter/blob/develop/sample/app/src/main/java/com/idanatz/sample/examples/BasicJavaExampleActivity.java

saiid2020 commented 3 years ago

my implementation : private class Pagation extends PagingModule {

    public Pagation() {

        config(builder -> {
            builder.setLayoutResource(R.layout.item_progress);
            builder.setVisibleThreshold(3);
            return null;

        });
        onLoadMore((mo )-> {

           viewModel.getcatgoryByIdPage(cat_id,String.valueOf(mo+1)).observe(owner, new Observer<Resource<List<Consumer>>>() {
               @Override
               public void onChanged(Resource<List<Consumer>> listResource) {
                   oneAdapter.add(listResource.data);

               }
           });
            return null;

        });

    }

}

private class Productadaptermodel extends ItemModule {

    public Productadaptermodel() {
        config(builder -> {
            builder.setLayoutResource(R.layout.layout_category_list);
            return null;
        });
        onBind((model, viewBinder, metadata) -> {
            LayoutCategoryListBinding binding = (LayoutCategoryListBinding) viewBinder.getDataBinding();
            binding.setProduct(model);
            binding.parent.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemClickListener.onItemClick(v, model, 1);

                }
            });

            binding.executePendingBindings();
            return null;
        });
        eventHooks.add(new ClickEventHook<Consumer>() {{
            onClick((model, viewBinder, metadata) -> {
                onItemClickListener.onItemClick(viewBinder.getRootView(), model, metadata.getPosition());

                return null;
            });
        }});

    }
}
   recycler_product = findViewById(R.id.recycler_product);
    recycler_product.setLayoutManager(new LinearLayoutManager(this));

    oneAdapter = new OneAdapter(recycler_product)
            .attachPagingModule(new Pagation())
            .attachItemModule(new Productadaptermodel())

          ;
idanatz commented 3 years ago

I don't know how your models look or implemented or what is returned from your ViewModel, but regarding everything else, I'm sorry I've tested this and your implementation works with no issues on my end. I've tested both Kotin & Java implementations, with DataBinding and without. Can you share a minimal project as possible with this issue so I can resolve it?

idanatz commented 3 years ago

any updates?