我正在尝试在此处的其余调用中添加分页,并且看过很多tut,但是我不知道如何在Presenter中通过此调用进行分页,因此我可以通过REST API处理页面吗?在我的Json
中,我有这个:
“页面”:22, “页面”:1,
public class NearbyUsersPresenter implements NearbyUsersPresenterInterface {
NearbyUsersViewInterface mvi;
private String TAG = "NearbyUsersPresenter";
private SQLiteHandler db;
private volatile int pageNumber = 1;
public NearbyUsersPresenter(NearbyUsersViewInterface mvi) {
this.mvi = mvi;
}
@Override
public void getMessages() {
getObservable().subscribeWith(getObserver());
}
public Observable<NearbyUsersList> getObservable(){
db = new SQLiteHandler(mvi.getContext());
HashMap<String, String> user = db.getUserDetails();
final String apiKey = user.get("apiKey");
return RestClient.getClient().create(REST.class)
.NearbyUsers(apiKey, pageNumber, 20)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public DisposableObserver<NearbyUsersList> getObserver(){
return new DisposableObserver<NearbyUsersList>() {
@Override
public void onNext(@NonNull NearbyUsersList nearbyUsersList) {
mvi.displayNearbyUsers(nearbyUsersList);
}
@Override
public void onError(@NonNull Throwable e) {
Log.d(TAG,"Error"+e);
e.printStackTrace();
mvi.displayError("Error fetching NearbyUsers Data");
}
@Override
public void onComplete() {
Log.d(TAG,"Completed");
mvi.hideProgressBar();
}
};
}
}