AuthPresenter extends BasePresenter<AuthFragmentContract.View>
                  
                  
                          implements AuthFragmentContract.Presenter {
                  
                  
                  
                  
                  
                      @NonNull
                  
                  
                      private final AccountFacade facade;
                  
                  
                  
                  
                  
                      @NonNull
                  
                  
                      private final MainActivityRouter router;
                  
                  
                  
                  
                  
                      @NonNull
                  
                  
                      private Disposable disposable;
                  
                  
                  
                  
                  
                      @Inject
                  
                  
                      public AuthPresenter(@NonNull @Foreground Scheduler foregroundScheduler,
                  
                  
                                           @NonNull @Background Scheduler backroundScheduler,
                  
                  
                                           @NonNull AccountFacade facade,
                  
                  
                                           @NonNull MainActivityRouter router) {
                  
                  
                          super(foregroundScheduler, backroundScheduler);
                  
                  
                          this.facade = facade;
                  
                  
                          this.router = router;
                  
                  
                      }
                  
                  
                  
                  
                  
                      @SuppressLint("CheckResult")
                  
                  
                      @Override
                  
                  
                      public void onSignInClicked(@NonNull String email, @NonNull String password) {
                  
                  
                          Account account = new Account.Builder()
                  
                  
                                  .email(email)
                  
                  
                                  .password(password)
                  
                  
                                  .build();
                  
                  
                  
                  
                  
                          disposable = facade.checkUserAuth(account)
                  
                  
                                  .observeOn(foregroundScheduler)
                  
                  
                                  .subscribeOn(backroundScheduler)
                  
                  
                                  .subscribe(() -> {
                  
                  
                                      router.navigateToFreightListScreen();
                  
                  
                                      disposable.dispose();
                  
                  
                                  }, throwable -> {
                  
                  
                                      checkException(throwable);
                  
                  
                                      disposable.dispose();
                  
                  
                                  });
                  
                  
                      }
                  
                  
                  
                  
                  
                      @Override
                  
                  
                      public void onSignUpClicked() {
                  
                  
                          router.navigateToSignUpScreen();
                  
                  
                      }
                  
                  
                  
                  
                  
                      @Override
                  
                  
                      public void onResetPasswordClicked() {
                  
                  
                          router.navigateToResetPasswordScreen();
                  
                  
                      }
                  
                  
                  
                  
                  
                      private void checkException(@NonNull Throwable throwable) {
                  
                  
                          if (throwable instanceof WrongEmailException) {
                  
                  
                              getView().showEmailValidatorError();
                  
                  
                          } else if (throwable instanceof WrongPasswordException) {
                  
                  
                              getView().showPasswordValidatorError();
                  
                  
                          } else {
                  
                  
                              getView().showError(throwable);
                  
                  
                          }
                  
                  
                      }
                  
                  
                  }
                  
                  
                
Лучше кидать gist - ом а не портянкой плэйн текста
нет смысла делать dispose() в оннекст или онеррор. Лучше складывать Disposable в CompositeDisposable а при уничтожении презентера очищать его.
Обсуждают сегодня