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);
}
});
}
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);
}
});
}
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);
}
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);
}
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);
}
Aggregations