Created
July 12, 2017 09:57
-
-
Save Marchuck/913193540e057c5983fea7c56dc39ea1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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