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

I read all the relevant information but the pagination does not work #26

Closed saiid2020 closed 4 years ago

saiid2020 commented 4 years ago

public class Productadaptermodel extends ItemModule { @NotNull @Override public ItemModuleConfig provideModuleConfig() { return new ItemModuleConfig() { @Override public int withLayoutResource() { return R.layout.layout_category_list; } }; }

@Override
public void onBind(@NotNull Item<Product> item, @NotNull ViewBinder viewBinder) {
    LayoutCategoryListBinding binding= (LayoutCategoryListBinding) viewBinder.getDataBinding();
    binding.setProduct(item.getModel());
    binding.executePendingBindings();

}

} //////// class Pagation extends PagingModule{

    @Override
    public void onLoadMore(int i) {
        viewModel.getProductListByPaging(cat_id,String.valueOf(i)).observe(owner, new Observer<Resource<List<Product>>>() {
            @Override
            public void onChanged(Resource<List<Product>> listResource) {
                if (listResource.status.equals(Status.SUCCESS)) {
                    oneAdapter.add(listResource.data);
                }

            }
        });

    }

    @NotNull
    @Override
    public PagingModuleConfig provideModuleConfig() {
        return new PagingModuleConfig() {
            @Override
            public int withVisibleThreshold() {
                return 0;
            }

            @Override
            public int withLayoutResource() {
                return R.layout.item_progress;
            }
        };
    }
}

public class Product implements Serializable, Diffable { SerializedName("Unique") @Expose public String unique; @Override public boolean areContentTheSame(@NonNull Object other) { return other instanceof Product && unique.equals(((Product) other).unique); }

@Override
public long getUniqueIdentifier() {
    return UUID.randomUUID().getMostSignificantBits();
}

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

idanatz commented 4 years ago

Found an issue with VisibleThreshold not calculated correctly, thanks! will be fixed in v2.0.0 that should be released In a few days. Be advised that v2.0.0 comes with a BIG API overall to the whole library so check the README before updating.

saiid2020 commented 4 years ago

Thanks for the quick reply. I'm waiting for the problem to be fixed

idanatz commented 4 years ago

v2.0.0 is out with the fix, pay attention to the breaking changes.