use of de.geeksfactory.opacclient.frontend.ResultsAdapterEndless.OnLoadMoreListener in project opacclient by opacapp.
the class SearchResultListFragment method setSearchResult.
public void setSearchResult(final SearchRequestResult searchresult) {
for (SearchResult result : searchresult.getResults()) {
result.setPage(searchresult.getPage_index());
}
if (searchresult.getTotal_result_count() >= 0) {
((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(getResources().getQuantityString(R.plurals.result_number, searchresult.getTotal_result_count(), searchresult.getTotal_result_count()));
}
if (searchresult.getResults().size() == 0 && searchresult.getTotal_result_count() <= 0) {
setEmptyText(getString(R.string.no_results));
}
this.searchresult = searchresult;
OpacApi api = null;
try {
api = app.getApi();
} catch (OpacClient.LibraryRemovedException ignored) {
}
adapter = new ResultsAdapterEndless(getActivity(), searchresult, new OnLoadMoreListener() {
@Override
public SearchRequestResult onLoadMore(int page) throws Exception {
SearchRequestResult res = app.getApi().searchGetPage(page);
setLastLoadedPage(page);
return res;
}
@Override
public void onError(Exception e) {
if (getActivity() != null) {
if (e instanceof OpacErrorException) {
showConnectivityError(e.getMessage());
} else if (e instanceof SSLSecurityException) {
showConnectivityError(getResources().getString(R.string.connection_error_detail_security));
} else if (e instanceof NotReachableException) {
showConnectivityError(getResources().getString(R.string.connection_error_detail_nre));
} else {
e.printStackTrace();
showConnectivityError();
}
}
}
@Override
public void updateResultCount(int resultCount) {
/*
* When IOpac finds more than 200 results, the real
* result count is not known until the second page is
* loaded
*/
if (resultCount >= 0 && getActivity() != null) {
((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(getResources().getQuantityString(R.plurals.result_number, resultCount, resultCount));
}
}
}, api);
setListAdapter(adapter);
getListView().setTextFilterEnabled(true);
setListShown(true);
}
Aggregations