package com.ecchilon.sadpanda.api;

import java.util.List;

import com.ecchilon.sadpanda.overview.GalleryEntry;
import com.google.inject.Inject;
import lombok.Getter;
import rx.Observable;

public class GalleryScroller {

	private final GalleryClient galleryClient;

	@Getter
	private boolean isLoading = false;
	@Getter
	private boolean hasMoreItems = true;

	@Inject
	GalleryScroller(GalleryClient galleryClient) {
		this.galleryClient = galleryClient;
	}

	public Observable<List<GalleryEntry>> loadPage(String base, int page) {
		isLoading = true;
		return galleryClient.getGalleryIndex(base, page).doOnNext(galleryEntries -> {
			isLoading = false;
			if (galleryEntries.size() < DataLoader.GALLERIES_PER_PAGE) {
				hasMoreItems = false;
			}
		});
	}
}

package com.ecchilon.sadpanda.api;

import java.util.List;

import com.ecchilon.sadpanda.overview.GalleryEntry;
import com.google.inject.Inject;
import lombok.Getter;
import rx.Observable;

public class GalleryScroller {

	private final GalleryClient galleryClient;

	@Getter
	private boolean isLoading = false;
	@Getter
	private boolean hasMoreItems = true;

	@Inject
	GalleryScroller(GalleryClient galleryClient) {
		this.galleryClient = galleryClient;
	}

	public Observable<List<GalleryEntry>> loadPage(String base, int page) {
		isLoading = true;
		return galleryClient.getGalleryIndex(base, page).doOnNext(galleryEntries -> {
			isLoading = false;
			if (galleryEntries.isEmpty()) {
				hasMoreItems = false;
			}
		});
	}
}

Fix early stop of gallery
Fix early stop of gallery

Sometimes it returns an item less than expected (due to expunging for example). Assume it's only complete when you get a completely empty collection
