Search in sources :

Example 1 with Professor

use of com.tevinjeffrey.rmp.common.Professor 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);
}
Also used : Professor(com.tevinjeffrey.rmp.common.Professor) Action0(rx.functions.Action0) Action1(rx.functions.Action1) ArrayList(java.util.ArrayList) Observable(rx.Observable) Instructors(com.tevinjeffrey.rutgersct.rutgersapi.model.Course.Section.Instructors) Subscriber(rx.Subscriber) Parameter(com.tevinjeffrey.rmp.common.Parameter)

Aggregations

Parameter (com.tevinjeffrey.rmp.common.Parameter)1 Professor (com.tevinjeffrey.rmp.common.Professor)1 Instructors (com.tevinjeffrey.rutgersct.rutgersapi.model.Course.Section.Instructors)1 ArrayList (java.util.ArrayList)1 Observable (rx.Observable)1 Subscriber (rx.Subscriber)1 Action0 (rx.functions.Action0)1 Action1 (rx.functions.Action1)1