Search in sources :

Example 1 with Request

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

the class TrackedSectionsPresenterImpl method loadTrackedSections.

public void loadTrackedSections(final boolean pullToRefresh) {
    if (getView() != null)
        getView().showLoading(pullToRefresh);
    cancePreviousSubscription();
    trackedSectinsSubscriber = new Subscriber<List<Section>>() {

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

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

        @Override
        public void onNext(List<Section> sectionList) {
            if (getView() != null) {
                getView().setData(sectionList);
            }
        }
    };
    mSubscription = mDatabaseHandler.getObservableSections().flatMap(new Func1<List<Request>, Observable<Section>>() {

        @Override
        public Observable<Section> call(List<Request> requests) {
            return mRetroRutgers.getTrackedSections(requests);
        }
    }).doOnSubscribe(new Action0() {

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

        @Override
        public void call() {
            isLoading = false;
        }
    }).toSortedList().subscribeOn(mBackgroundThread).observeOn(mMainThread).subscribe(trackedSectinsSubscriber);
}
Also used : Action0(rx.functions.Action0) Request(com.tevinjeffrey.rutgersct.rutgersapi.model.Request) List(java.util.List) Func1(rx.functions.Func1) Section(com.tevinjeffrey.rutgersct.rutgersapi.model.Course.Section)

Example 2 with Request

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

the class DatabaseReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    RutgersCTApp.getObjectGraph(context).inject(this);
    Request request = intent.getParcelableExtra(TrackedSectionsView.REQUEST);
    Course.Section section = intent.getParcelableExtra(CourseInfoView.SELECTED_SECTION);
    if (request != null && section != null) {
        //Removes section from databse
        mDatabaseHandler.removeSectionFromDb(request);
        //Notify user with a toast.
        notifyUser(context, section);
        //Remove notification from notification panel
        removeNotification(context, request);
    }
}
Also used : Request(com.tevinjeffrey.rutgersct.rutgersapi.model.Request) Course(com.tevinjeffrey.rutgersct.rutgersapi.model.Course)

Example 3 with Request

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

the class TrackedSectionsFragmentTest method testRecyclerItemClickAndRemoveSection.

@Test
public void testRecyclerItemClickAndRemoveSection() {
    Request expected = RutgersApiConts.getPrimarySemesterRequest();
    databaseHandler.addSectionToDb(expected);
    onView(withId(R.id.tsf_list)).perform(actionOnItemAtPosition(0, click()));
    onView(withId(R.id.add_courses_fab)).perform(click());
    databaseHandler.removeSectionFromDb(expected);
}
Also used : Request(com.tevinjeffrey.rutgersct.rutgersapi.model.Request) LargeTest(android.test.suitebuilder.annotation.LargeTest) Test(org.junit.Test)

Aggregations

Request (com.tevinjeffrey.rutgersct.rutgersapi.model.Request)3 LargeTest (android.test.suitebuilder.annotation.LargeTest)1 Course (com.tevinjeffrey.rutgersct.rutgersapi.model.Course)1 Section (com.tevinjeffrey.rutgersct.rutgersapi.model.Course.Section)1 List (java.util.List)1 Test (org.junit.Test)1 Action0 (rx.functions.Action0)1 Func1 (rx.functions.Func1)1