Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. @ActivityScope
  2. public class MainPresenter
  3. //extends BasePresenter<MainPresenter.ViewContract>
  4. implements Bundleable, Dispatcher {
  5. //public interface ViewContract
  6. // extends Presenter.ViewContract {
  7. //}
  8.  
  9. //@Override
  10. //protected void initializeView(ViewContract view) {
  11. // // doesn't need to do a thing
  12. //}
  13.  
  14. @Inject
  15. public MainPresenter() {
  16. }
  17.  
  18. private BehaviorRelay<MainState> state = BehaviorRelay.createDefault(MainState.create());
  19.  
  20. public Observable<MainState> state() {
  21. return state.distinctUntilChanged();
  22. }
  23.  
  24. public void setTitle(int title) {
  25. state.accept(state.getValue().toBuilder().setTitle(title).build());
  26. }
  27.  
  28. public boolean onBackPressed() {
  29. if(state.getValue().isDrawerOpen()) {
  30. closeDrawer();
  31. return true;
  32. }
  33. return false;
  34. }
  35.  
  36. public void openDrawer() {
  37. state.accept(state.getValue().toBuilder().setIsDrawerOpen(true).build());
  38. }
  39.  
  40. public void closeDrawer() {
  41. state.accept(state.getValue().toBuilder().setIsDrawerOpen(false).build());
  42. }
  43.  
  44. public void toggleDrawer() {
  45. if(state.getValue().isDrawerOpen()) {
  46. closeDrawer();
  47. } else {
  48. openDrawer();
  49. }
  50. }
  51.  
  52. // ...
  53.  
  54. private void enableLeftDrawer() {
  55. state.accept(state.getValue().toBuilder().setLeftDrawerEnabled(true).build());
  56. }
  57.  
  58. private void disableLeftDrawer() {
  59. state.accept(state.getValue().toBuilder().setLeftDrawerEnabled(false).build());
  60. }
  61.  
  62. // ...
  63.  
  64. @Override
  65. public Bundle toBundle() {
  66. Bundle bundle = BundleFactory.create();
  67. bundle.putParcelable("state", state.getValue());
  68. return bundle;
  69. }
  70.  
  71. @Override
  72. public void fromBundle(@Nullable Bundle bundle) {
  73. if(bundle != null) {
  74. state.accept(bundle.getParcelable("state"));
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement