Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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