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();
}
});
}
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();
}
});
}
Aggregations