Last active
November 2, 2017 08:06
-
-
Save alin-turcu/6bd1ec50c125dd146a06c47e3ad82eab 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
import com.groupon.grox.Store; | |
import com.groupon.grox.commands.rxjava1.Command; | |
import com.groupon.grox.sample.rx.R; | |
import rx.subscriptions.CompositeSubscription; | |
public class LoginActivity extends AppCompatActivity { | |
private LoginStateModel initialState = LoginStateModel.builder() | |
.setLoginState(LOGIN_NOT_STARTED) | |
.setLoggedInUser(null) | |
.build(); | |
private Store<LoginStateModel> store = new Store<>(initialState); | |
private CompositeSubscription subscription = new CompositeSubscription(); | |
private LoginApiClient loginApiClient; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
final View loginButton = findViewById(R.id.loginButton); | |
final EditText username = (TextView) findViewById(R.id.username); | |
final EditText password = (TextView) findViewById(R.id.password); | |
subscription.add(states(store).observeOn(mainThread()) | |
.subscribe(this::updateUI) | |
); | |
loginButton.setOnClickListener(v -> { | |
subscription.add(new LoginCommand(username.getText(), password.getText(), loginApiClient) | |
.actions() | |
.subscribe(store::dispatch) | |
); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment