Guest User

Untitled

a guest
Oct 31st, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import static rx.Observable.error;
  2. import static rx.Observable.fromCallable;
  3. import static rx.Observable.just;
  4. import static rx.schedulers.Schedulers.io;
  5.  
  6. import com.groupon.grox.Action;
  7. import com.groupon.grox.commands.rxjava1.Command;
  8. import rx.Observable;
  9.  
  10. public class LoginCommand implements Command {
  11.  
  12. private LoginApiClient loginApiClient;
  13. private String username;
  14. private String password;
  15.  
  16. public LoginCommand(CharSequence username, CharSequence password, LoginApiClient loginApiClient){
  17. this.username = username;
  18. this.password = password;
  19. this.loginApiClient = loginApiClient;
  20. }
  21.  
  22. @Override
  23. public Observable<? extends Action> actions() {
  24. return loginApiClient.performLogin(username, password)
  25. .subscribeOn(io())
  26. .map(LoginSuccesfullAction::new)
  27. .cast(Action.class)
  28. .onErrorReturn(LoginFailedAction::new)
  29. .startWith(fromCallable(LoginInProgressAction::new));
  30. }
  31. }
Add Comment
Please, Sign In to add comment