Skip to content

Instantly share code, notes, and snippets.

@alin-turcu
Last active November 2, 2017 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alin-turcu/6bd1ec50c125dd146a06c47e3ad82eab to your computer and use it in GitHub Desktop.
Save alin-turcu/6bd1ec50c125dd146a06c47e3ad82eab to your computer and use it in GitHub Desktop.
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