Search in sources :

Example 1 with UserService

use of io.classify.service.UserService 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);
        }
    });
}
Also used : User(io.classify.model.User) UserService(io.classify.service.UserService) DI(io.classify.DI) Intent(android.content.Intent)

Example 2 with UserService

use of io.classify.service.UserService in project classify-system by anverliedoit.

the class ActivityChangePassword method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_user_changepassword);
    text1 = findViewById(R.id.activity_changepassword_text1);
    text2 = findViewById(R.id.activity_changepassword_text2);
    button = findViewById(R.id.activityt_changepassword_button);
    btnCancel = findViewById(R.id.activityt_changepassword_button_cancel);
    progressBar = findViewById(R.id.progressbar_cp);
    button.setOnClickListener(this);
    btnCancel.setOnClickListener(this);
    retrofit = new DI().getRetrofit();
    userService = retrofit.create(UserService.class);
    teacherService = new TeacherServiceImpl();
    progressBar.setVisibility(View.INVISIBLE);
    try {
        teacher = teacherService.getTeacherById(getIntent().getExtras().getLong("teacherId"));
    } catch (Exception e) {
        e.printStackTrace();
        teacher = new Teacher();
    }
}
Also used : DI(io.classify.DI) UserService(io.classify.service.UserService) Teacher(com.remswork.project.alice.model.Teacher) TeacherServiceImpl(com.remswork.project.alice.service.impl.TeacherServiceImpl)

Aggregations

DI (io.classify.DI)2 UserService (io.classify.service.UserService)2 Intent (android.content.Intent)1 Teacher (com.remswork.project.alice.model.Teacher)1 TeacherServiceImpl (com.remswork.project.alice.service.impl.TeacherServiceImpl)1 User (io.classify.model.User)1