Skip to content

Instantly share code, notes, and snippets.

@Marchuck
Created July 12, 2017 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marchuck/913193540e057c5983fea7c56dc39ea1 to your computer and use it in GitHub Desktop.
Save Marchuck/913193540e057c5983fea7c56dc39ea1 to your computer and use it in GitHub Desktop.
CatPresenter{
BehaviorSubject<List<Cat>> catsSubject = BehaviorSubject.create();
Disposable catsDisposable;
void onCreate(){
someClient.subscribe( cats -> { catsSubject.onNext(cats) })
}
void onResume(){
unsubscribe();
catsSubject.observeOn(AndroidSchedulers.mainThread()).subscribe( cats-> view.onCatsReceived(cats) );
}
void onPause(){
unsubscribe();
}
void unsubscribe(){
if(catsDisposable!=null){
catsDisposable.dispose();
catsDisposable = null;
}
}
}
CatsFragment{
CatsPresenter presenter;
onCreateView(...){
View v = ...;
presenter = new CatsPresenter(v)
}
void onResume(){
presenter.onResume();
}
void onPause(){
presenter.onPause();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment