Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnLoadMore is being called twice at the initilization #3

Closed
Mystogun opened this issue Dec 17, 2017 · 8 comments
Closed

OnLoadMore is being called twice at the initilization #3

Mystogun opened this issue Dec 17, 2017 · 8 comments

Comments

@Mystogun
Copy link

No description provided.

@NoNews
Copy link
Owner

NoNews commented Dec 17, 2017

Hi @Mystogun, сan you show the code of your Fragment or Activity?
Also, how many items you load from one request? (I mean, limit)

@NoNews
Copy link
Owner

NoNews commented Dec 17, 2017

#1

@Mystogun
Copy link
Author

Mystogun commented Dec 19, 2017

I'm loading 20 items per request to a recycler and the OnLoadMore is being called twice

here's the initialization

paginate = Paginate.with(binding.list, this)
                .setLoadingTriggerThreshold(2)
                .with(recyclerView)
                .setOnLoadMoreListener(new OnLoadMoreListener() {
                    @Override
                    public void onLoadMore() {
                        loadPosts();
                    }
                })
                .build();

and here is the loadPosts() method

private void loadPosts() {
            Call<GetRecentResponse> call = retrofit.create(PostsInterface.class).getRecent(page, offset);
            call.enqueue(new Callback<GetRecentResponse>() {
                @Override
                public void onResponse(Call<GetRecentResponse> call, Response<GetRecentResponse> response) {
                    binding.loading.setVisibility(View.GONE);
                    binding.textStatus.setVisibility(View.GONE);
                    binding.status.setVisibility(View.GONE);
                    isLoading = false;
                    if (!reachedBottom) {
                        if (response.body() != null) {
                            if (response.body().getRecent() != null) {
                                if (response.body().getRecent().size() > 0) {
                                    posts = response.body().getRecent();
                                    adapter.addItems(posts);
                                    page++;
                                } else if (response.body().getRecent().size() == 0) {
                                    reachedBottom = true;
                                }
                            }
                        }
                    }
                 }

                @Override
                public void onFailure(Call<GetRecentResponse> call, Throwable t) {
                    binding.loading.setVisibility(View.GONE);
                    binding.status.setImageResource(R.drawable.error2x);
                    binding.textStatus.setText(t.getLocalizedMessage());
                    isLoading = false;
                }
            });
}

@NoNews
Copy link
Owner

NoNews commented Dec 19, 2017

@Mystogun Can you try setLoadingTriggerThreshold(0) in your builder? I described behavior here #1

And..why you use with two times?

@NoNews
Copy link
Owner

NoNews commented Dec 19, 2017

@Mystogun And, show your gradle dependencies.
I think you use library Paginate.
But this repository belongs to the library NoPaginate

In your case it would be like this:

implementation 'ru.alexbykov:nopaginate:0.4.4' in gradle

Paginate paginate = new PaginateBuilder()
              .with(recyclerView)
              .setOnLoadMoreListener(new OnLoadMoreListener() {
                  @Override
                  public void onLoadMore() {
                      //http or db request here
                  }
              })
              .build();

That's it.

@Mystogun
Copy link
Author

@NoNews, OK I'll try using setLoadingTriggerThreshold(0)

yeah, I was using Paginate before, then there was a lot of bugs with it so I changed to yours NoPaginate
because it offered more features.

@Mystogun
Copy link
Author

The setLoadingTriggerThreshold(0) worked fine, Thanks a lot

@NoNews
Copy link
Owner

NoNews commented Dec 19, 2017

@Mystogun I am glad to help!

Note, in the version 0.4.4 setLoadingTriggerThreshold(0) is default behavior.
It means, that install manually setLoadingTriggerThreshold(0) not necessary.

@NoNews NoNews closed this as completed Dec 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants