Search in sources :

Example 16 with Action0

use of rx.functions.Action0 in project RxLifecycle by trello.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "onCreate()");
    setContentView(R.layout.activity_main);
    // Specifically bind this until onPause()
    Observable.interval(1, TimeUnit.SECONDS).doOnUnsubscribe(new Action0() {

        @Override
        public void call() {
            Log.i(TAG, "Unsubscribing subscription from onCreate()");
        }
    }).compose(this.<Long>bindUntilEvent(ActivityEvent.PAUSE)).subscribe(new Action1<Long>() {

        @Override
        public void call(Long num) {
            Log.i(TAG, "Started in onCreate(), running until onPause(): " + num);
        }
    });
}
Also used : Action0(rx.functions.Action0)

Example 17 with Action0

use of rx.functions.Action0 in project RxLifecycle by trello.

the class MainActivity method onStart.

@Override
protected void onStart() {
    super.onStart();
    Log.d(TAG, "onStart()");
    // Using automatic unsubscription, this should determine that the correct time to
    // unsubscribe is onStop (the opposite of onStart).
    Observable.interval(1, TimeUnit.SECONDS).doOnUnsubscribe(new Action0() {

        @Override
        public void call() {
            Log.i(TAG, "Unsubscribing subscription from onStart()");
        }
    }).compose(this.<Long>bindToLifecycle()).subscribe(new Action1<Long>() {

        @Override
        public void call(Long num) {
            Log.i(TAG, "Started in onStart(), running until in onStop(): " + num);
        }
    });
}
Also used : Action0(rx.functions.Action0)

Example 18 with Action0

use of rx.functions.Action0 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 19 with Action0

use of rx.functions.Action0 in project Rutgers-Course-Tracker by tevjef.

the class CoursePresenterImpl method loadCourses.

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

        @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<Course> courseList) {
            if (getView() != null)
                getView().setData(courseList);
            if (courseList.size() > 0) {
                if (getView() != null)
                    getView().showLayout(View.LayoutType.LIST);
            }
        }
    };
    mSubscription = mRetroRutgers.getCourses(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 : Action0(rx.functions.Action0) Subscriber(rx.Subscriber) List(java.util.List) Course(com.tevinjeffrey.rutgersct.rutgersapi.model.Course)

Example 20 with Action0

use of rx.functions.Action0 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)

Aggregations

Action0 (rx.functions.Action0)134 Subscription (rx.Subscription)58 Test (org.junit.Test)56 CountDownLatch (java.util.concurrent.CountDownLatch)50 Action1 (rx.functions.Action1)28 AtomicReference (java.util.concurrent.atomic.AtomicReference)23 ArrayList (java.util.ArrayList)16 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)16 List (java.util.List)15 Func1 (rx.functions.Func1)13 HystrixRuntimeException (com.netflix.hystrix.exception.HystrixRuntimeException)12 Observable (rx.Observable)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 OnClick (butterknife.OnClick)10 IOException (java.io.IOException)9 CommandStreamTest (com.netflix.hystrix.metric.CommandStreamTest)8 UiThreadTest (android.support.test.annotation.UiThreadTest)7 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)7 TestCollapserTimer (com.netflix.hystrix.HystrixCollapserTest.TestCollapserTimer)7 Method (java.lang.reflect.Method)7