Closed friskycoder closed 6 years ago
When calling getPhotos the first parameter is the page and the 2nd is the number per page. Try the following code
unsplash.getPhotos(2, 20, Order.POPULAR, new Unsplash.OnPhotosLoadedListener() {
@Override
public void onComplete(List<Photo> photos) {
}
@Override
public void onError(String error) {
}
});
Thank you for the reply
Yeh am using it that way the page changes but the number of photos per page is limited to 20 even if per page 100 is given.I need photos to generate continuosly.
On Tue 28 Aug, 2018, 11:24 PM Keenen Charles, notifications@github.com wrote:
When calling getPhotos the first parameter is the page and the 2nd is the number per page. Try the following code
unsplash.getPhotos(2, 20, Order.POPULAR, new Unsplash.OnPhotosLoadedListener() { @override https://github.com/override public void onComplete(List photos) { }
@Override public void onError(String error) { } });
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/KeenenCharles/AndroidUnplash/issues/7#issuecomment-416681377, or mute the thread https://github.com/notifications/unsubscribe-auth/AovPk-LARr5TlTxsAFT7TOV4g_H7eMNEks5uVYPkgaJpZM4WMz72 .
It looks like Unsplash has a limit of how much you can request per page. 30 worked for me but I can't get any more than that
Yeh max 30 for me too...is there any way i can get photos continuosly.Like is there any options to get photos randomly or so that are not limited to a single page so that the number of photos can go on.It would be really helpful.
You need to implement pagination in your app. After you get the first page of 30 photos, make a request for page 2 with 30 more photos and add it to the list of photos.
Sorry for asking, but I have no idea how it's done, kinda new to this.Could you please show me an example.
On Wed, Aug 29, 2018 at 7:40 PM Keenen Charles notifications@github.com wrote:
You need to implement pagination in your app. After you get the first page of 30 photos, make a request for page 2 with 30 more photos and add it to the list of photos.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/KeenenCharles/AndroidUnplash/issues/7#issuecomment-417170776, or mute the thread https://github.com/notifications/unsubscribe-auth/AovPkw6ZFB_9cLZB1PjRFiYrp1rtUU4Oks5uV1CIgaJpZM4WMz72 .
This article explains it pretty well. You'd just need to replace the API calls in the article with calls to the Unsplash library like above https://medium.com/@etiennelawlor/pagination-with-recyclerview-1cb7e66a502b
Is it like this
@Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); }
@Override
public void onScrolled(final RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int visibleItemCount = gridLayoutManager.getChildCount();
int totalItemCount = gridLayoutManager.getItemCount();
int firstVisibleItemPosition = gridLayoutManager.findFirstVisibleItemPosition();
if (!isLoading && !isLastPage) {
if ((visibleItemCount + firstVisibleItemPosition) >= totalItemCount
&& firstVisibleItemPosition >= 0
&& totalItemCount >= PAGE_SIZE) {
unsplash.getPhotos( 2,50,Order.LATEST, new Unsplash.OnPhotosLoadedListener() {
@Override
public void onComplete(List<Photo> photos) {
int photoCount = photos.size();
PhotoRecyclerAdapter adapter = new PhotoRecyclerAdapter(photos,c );
recyclerView.setAdapter(adapter);
}
@Override
public void onError(String error) {
Log.v("Error", error);
}
});
}
}
}
};
Yeah that's it but a couple things you should look at
You don't want to hardcode the page number as 2 because then it will only fetch the same images. You should have a variable that stores the page number and is incremented by 1 each time getPhotos is called
You shouldn't create and set a new adapter each time as it will only show the new images loaded. The adapter should be global and you should set the adapter to the recyclerview once outside of this function. You should look into how to add new items to an adapter and in the OnComplete where you currently create a new adapter you should just add the new items to the global adapter.
The pages are now loading but replace the previous loaded ones
Ah finally got it working, Thankyou Keenen for the help.
Nice!
@friskycoder
Ah finally got it working, Thankyou Keenen for the help.
Can you include your final method which got this working? Looking to implement something simillar but have never worked with pagination.
Ah finally got it working, Thankyou Keenen for the help. Can you include your final method which got this working?
The number of photos that the method getPhotos() and other methods load are limited to page 1 and only load fiew photos ...is there any way to increase the number of photos