Search in sources :

Example 1 with User

use of com.wingjay.jianshi.bean.User in project jianshi by wingjay.

the class UserManager method login.

public void login(final Context context, @NonNull String email, @NonNull String password) {
    final ProgressDialog dialog = ProgressDialog.show(context, context.getString(R.string.logining), "");
    userService.login(email, password).compose(RxUtil.<JsonDataResponse<User>>normalSchedulers()).doOnTerminate(new Action0() {

        @Override
        public void call() {
            dialog.dismiss();
        }
    }).subscribe(new Action1<JsonDataResponse<User>>() {

        @Override
        public void call(JsonDataResponse<User> userJsonDataResponse) {
            if (userJsonDataResponse.getRc() == Constants.ServerResultCode.RESULT_OK) {
                User user = userJsonDataResponse.getData();
                if (user == null || user.getId() <= 0 || TextUtils.isEmpty(user.getEncryptedToken())) {
                    Toast.makeText(context, context.getString(R.string.login_failure), Toast.LENGTH_SHORT).show();
                    return;
                }
                userPrefsLazy.get().setAuthToken(user.getEncryptedToken());
                userPrefsLazy.get().setUser(user);
                context.startActivity(MainActivity.createIntent(context));
            } else {
                Timber.e("login failure msg: %s", userJsonDataResponse.getMsg());
                Toast.makeText(context, userJsonDataResponse.getMsg(), Toast.LENGTH_SHORT).show();
            }
        }
    }, new Action1<Throwable>() {

        @Override
        public void call(Throwable e) {
            Timber.e(e, "login failure");
            Toast.makeText(context, context.getString(R.string.network_error), Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : Action0(rx.functions.Action0) User(com.wingjay.jianshi.bean.User) JsonDataResponse(com.wingjay.jianshi.network.JsonDataResponse) ProgressDialog(android.app.ProgressDialog)

Example 2 with User

use of com.wingjay.jianshi.bean.User in project jianshi by wingjay.

the class UserManager method signup.

public void signup(final Context context, @NonNull String email, @NonNull String password) {
    final ProgressDialog dialog = ProgressDialog.show(context, context.getString(R.string.signuping), "");
    userService.signup(email, password).compose(RxUtil.<JsonDataResponse<User>>normalSchedulers()).doOnTerminate(new Action0() {

        @Override
        public void call() {
            dialog.dismiss();
        }
    }).subscribe(new Action1<JsonDataResponse<User>>() {

        @Override
        public void call(JsonDataResponse<User> userJsonDataResponse) {
            if (userJsonDataResponse.getRc() == Constants.ServerResultCode.RESULT_OK) {
                User user = userJsonDataResponse.getData();
                if (user == null || user.getId() <= 0 || TextUtils.isEmpty(user.getEncryptedToken())) {
                    Toast.makeText(context, context.getString(R.string.signup_failure), Toast.LENGTH_SHORT).show();
                    return;
                }
                userPrefsLazy.get().setAuthToken(user.getEncryptedToken());
                userPrefsLazy.get().setUser(user);
                context.startActivity(MainActivity.createIntent(context));
            } else {
                Timber.e("signup failure msg: %s", userJsonDataResponse.getMsg());
                Toast.makeText(context, userJsonDataResponse.getMsg(), Toast.LENGTH_SHORT).show();
            }
        }
    }, new Action1<Throwable>() {

        @Override
        public void call(Throwable e) {
            Timber.e(e, "signup failure");
            Toast.makeText(context, context.getString(R.string.network_error), Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : Action0(rx.functions.Action0) User(com.wingjay.jianshi.bean.User) JsonDataResponse(com.wingjay.jianshi.network.JsonDataResponse) ProgressDialog(android.app.ProgressDialog)

Aggregations

ProgressDialog (android.app.ProgressDialog)2 User (com.wingjay.jianshi.bean.User)2 JsonDataResponse (com.wingjay.jianshi.network.JsonDataResponse)2 Action0 (rx.functions.Action0)2