use of com.tevinjeffrey.rmp.common.Parameter in project Rutgers-Course-Tracker by tevjef.
the class SectionInfoPresenterImpl method loadRMP.
public void loadRMP() {
final Iterable<Instructors> professorsNotFound = new ArrayList<>(mSection.getInstructors());
cancePreviousSubscription();
Subscriber<Professor> subscriber = new Subscriber<Professor>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
@Override
public void onNext(Professor professor) {
if (getView() != null)
getView().addRMPProfessor(professor);
}
};
mSubscription = buildSearchParameters(mSection).flatMap(new Func1<Parameter, Observable<Professor>>() {
@Override
public Observable<Professor> call(Parameter parameter) {
return rmp.getProfessor(parameter);
}
}).doOnNext(new Action1<Professor>() {
@Override
public void call(Professor professor) {
for (final Iterator<Instructors> iterator = professorsNotFound.iterator(); iterator.hasNext(); ) {
Instructors i = iterator.next();
if (StringUtils.getJaroWinklerDistance(i.getLastName(), professor.getLastName()) > .70 || StringUtils.getJaroWinklerDistance(i.getLastName(), professor.getFirstName()) > .70) {
iterator.remove();
}
}
}
}).subscribeOn(mBackgroundThread).observeOn(mMainThread).doOnTerminate(new Action0() {
@Override
public void call() {
if (getView() != null) {
getView().showRatingsLayout();
getView().hideRatingsLoading();
for (Instructors i : professorsNotFound) {
getView().addErrorProfessor(i.getName());
}
}
}
}).subscribe(subscriber);
}
Aggregations