search paging improvement

This commit is contained in:
bancika
2016-10-26 12:04:04 +02:00
parent 5ffb223a0d
commit 54e9797566
8 changed files with 176 additions and 65 deletions
@@ -0,0 +1,40 @@
package org.diylc.plugins.cloud.presenter;
import java.util.List;
import org.diylc.plugins.cloud.model.ProjectEntity;
public class PagingProvider {
private CloudPresenter cloudPresenter;
private String searchFor;
private String category;
private String sort;
private int itemsPerPage = 10;
private int currentPage;
private List<ProjectEntity> currentResults;
public PagingProvider(CloudPresenter cloudPresenter) {
this.cloudPresenter = cloudPresenter;
}
public List<ProjectEntity> startSession(String searchFor, String category, String sort) throws CloudException {
this.searchFor = searchFor;
this.category = category;
this.sort = sort;
this.currentPage = 1;
return currentResults = cloudPresenter.search(searchFor, category, sort, currentPage, itemsPerPage);
}
public boolean hasMoreData() {
return this.currentResults != null && this.currentResults.size() == itemsPerPage;
}
public List<ProjectEntity> requestMoreData() throws CloudException {
currentPage++;
return currentResults = cloudPresenter.search(searchFor, category, sort, currentPage, itemsPerPage);
}
}