use of io.classify.model.User in project classify-system by anverliedoit.
the class LoginActivity method doLogin.
@Override
public void doLogin(final String _username, final String _password) {
Log.i(TAG, "doLogin");
progressBar.setVisibility(View.VISIBLE);
screen.setVisibility(View.VISIBLE);
username = _username;
password = _password;
UserService userService = new DI().getRetrofit().create(UserService.class);
userService.getByUsername(username).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<User>() {
@Override
public void accept(User user) throws Exception {
if (user.getPassword().equals(password)) {
teacherHelper.saveUser(user.getTeacherId());
Intent intent = new Intent(getApplicationContext(), MainActivity2.class);
intent.putExtra("teacherId", user.getTeacherId());
isVaild = true;
startActivity(intent);
} else {
if (!isVaild)
Toast.makeText(LoginActivity.this, "Incorrect username or password", Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.INVISIBLE);
screen.setVisibility(View.INVISIBLE);
}
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
if (!isVaild)
Toast.makeText(LoginActivity.this, "Incorrect username or password", Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.INVISIBLE);
screen.setVisibility(View.INVISIBLE);
}
});
}
Aggregations