Search in sources :

Example 1 with Subject

use of com.tevinjeffrey.rutgersct.rutgersapi.model.Subject in project Rutgers-Course-Tracker by tevjef.

the class SubjectPresenterImpl method loadSubjects.

@Override
public void loadSubjects(boolean pullToRefresh) {
    if (getView() != null)
        getView().showLoading(pullToRefresh);
    cancePreviousSubscription();
    Subscriber<List<Subject>> mSubscriber = new Subscriber<List<Subject>>() {

        @Override
        public void onCompleted() {
            if (getView() != null)
                getView().showLoading(false);
        }

        @Override
        public void onError(Throwable e) {
            //Lets the view decide what to display depending on what type of exception it is.
            if (getView() != null)
                getView().showError(e);
            //Removes the animated loading drawable
            if (getView() != null) {
                getView().showLoading(false);
            }
        }

        @Override
        public void onNext(List<Subject> subjectList) {
            if (getView() != null) {
                getView().setData(subjectList);
                if (subjectList.size() == 0)
                    getView().showError(new RutgersDataIOException());
                if (subjectList.size() > 0)
                    getView().showLayout(View.LayoutType.LIST);
            }
        }
    };
    mSubscription = mRetroRutgers.getSubjects(mRequest).doOnSubscribe(new Action0() {

        @Override
        public void call() {
            isLoading = true;
        }
    }).doOnTerminate(new Action0() {

        @Override
        public void call() {
            isLoading = false;
        }
    }).subscribeOn(mBackgroundThread).observeOn(mMainThread).subscribe(mSubscriber);
}
Also used : RutgersDataIOException(com.tevinjeffrey.rutgersct.rutgersapi.exceptions.RutgersDataIOException) Action0(rx.functions.Action0) Subscriber(rx.Subscriber) List(java.util.List) Subject(com.tevinjeffrey.rutgersct.rutgersapi.model.Subject)

Example 2 with Subject

use of com.tevinjeffrey.rutgersct.rutgersapi.model.Subject in project Rutgers-Course-Tracker by tevjef.

the class RetroRutgers method getSubjectFromJson.

public Subject getSubjectFromJson(String code) {
    List<Subject> subjectsList = mSubjectsList;
    Subject temp;
    for (int i = 0, size = subjectsList.size(); i < size; i++) {
        temp = subjectsList.get(i);
        if (temp.getCode().equals(code)) {
            return temp;
        }
    }
    return null;
}
Also used : Subject(com.tevinjeffrey.rutgersct.rutgersapi.model.Subject)

Example 3 with Subject

use of com.tevinjeffrey.rutgersct.rutgersapi.model.Subject in project Rutgers-Course-Tracker by tevjef.

the class SubjectPresenterImplTest method LoadSubjects_CompletesWithList.

@Test
public void LoadSubjects_CompletesWithList() throws Exception {
    subjectPresenterImpl.attachView(subjectView);
    databaseHandler.addSectionToDb(TestConts.getPrimarySemesterRequest());
    when(retroRutgers.getSubjects(any(Request.class))).thenReturn(Observable.just(new Subject()).toList());
    subjectPresenterImpl.loadSubjects(true);
    verify(subjectView).showLoading(true);
    verify(subjectView).showLoading(false);
    verify(subjectView).setData(anyListOf(Subject.class));
}
Also used : Request(com.tevinjeffrey.rutgersct.rutgersapi.model.Request) Subject(com.tevinjeffrey.rutgersct.rutgersapi.model.Subject) Test(org.junit.Test)

Example 4 with Subject

use of com.tevinjeffrey.rutgersct.rutgersapi.model.Subject in project Rutgers-Course-Tracker by tevjef.

the class SubjectFragmentAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final SubjectVH holder, int position) {
    final Subject subject = subjectList.get(position);
    holder.setSubjectTitle(subject);
    holder.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            itemClickListener.onItemClicked(subject, v);
        }
    });
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Subject(com.tevinjeffrey.rutgersct.rutgersapi.model.Subject)

Example 5 with Subject

use of com.tevinjeffrey.rutgersct.rutgersapi.model.Subject in project Rutgers-Course-Tracker by tevjef.

the class CourseFragment method setToolbarTitle.

private void setToolbarTitle() {
    Subject selectedSubject = getArguments().getParcelable(SubjectView.SELECTED_SUBJECT);
    super.setToolbarTitle(mToolbar, (selectedSubject != null ? selectedSubject.getCode() : "") + " | " + WordUtils.capitalize(selectedSubject != null ? selectedSubject.getDescription().toLowerCase() : ""));
}
Also used : Subject(com.tevinjeffrey.rutgersct.rutgersapi.model.Subject)

Aggregations

Subject (com.tevinjeffrey.rutgersct.rutgersapi.model.Subject)6 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 RutgersDataIOException (com.tevinjeffrey.rutgersct.rutgersapi.exceptions.RutgersDataIOException)1 Request (com.tevinjeffrey.rutgersct.rutgersapi.model.Request)1 List (java.util.List)1 Test (org.junit.Test)1 Subscriber (rx.Subscriber)1 Action0 (rx.functions.Action0)1