登录流程修改
This commit is contained in:
@@ -49,17 +49,10 @@ public class AddUserInfoFragment extends BaseFragment
|
||||
private TextInputEditText tvNick;
|
||||
private Button okBtn;
|
||||
private ImageView tvRandomNick;
|
||||
private File photoFile;
|
||||
private int gender = -1;
|
||||
private XRadioGroup rgGender;
|
||||
private RadioButton rbMale;
|
||||
AddUserInfoActivity addUserInfoActivity;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
addUserInfoActivity = (AddUserInfoActivity) activity;
|
||||
}
|
||||
private String avatarUrl = "https://image.zhongjialx.com/default_avatar.png";
|
||||
|
||||
@Override
|
||||
public int getRootLayoutId() {
|
||||
@@ -82,7 +75,6 @@ public class AddUserInfoFragment extends BaseFragment
|
||||
gender = -1;
|
||||
okBtn.setOnClickListener(this);
|
||||
tvRandomNick.setOnClickListener(this);
|
||||
|
||||
addWXUserInfo();
|
||||
}
|
||||
|
||||
@@ -90,25 +82,21 @@ public class AddUserInfoFragment extends BaseFragment
|
||||
private void addWXUserInfo() {
|
||||
ThirdUserInfo thirdUserInfo = AuthModel.get().getThirdUserInfo();
|
||||
if (thirdUserInfo != null) {
|
||||
if (thirdUserInfo.getType() == ThirdUserInfo.TYPE_WX || thirdUserInfo.getType() == ThirdUserInfo.TYPE_QQ){
|
||||
String avatarUrlWX = thirdUserInfo.getUserIcon();
|
||||
String nick = thirdUserInfo.getUserName();
|
||||
String str_gender = thirdUserInfo.getUserGender()==null?"":thirdUserInfo.getUserGender();
|
||||
int gender = str_gender.equals("m")?UserInfo.GENDER_MALE:UserInfo.GENDER_FEMALE;
|
||||
commit(nick,avatarUrlWX,gender);
|
||||
}else {
|
||||
init();
|
||||
if (thirdUserInfo.getType() == ThirdUserInfo.TYPE_WX || thirdUserInfo.getType() == ThirdUserInfo.TYPE_QQ) {
|
||||
avatarUrl = thirdUserInfo.getUserIcon();
|
||||
String str_gender = thirdUserInfo.getUserGender() == null ? "" : thirdUserInfo.getUserGender();
|
||||
gender = str_gender.equals("m") ? UserInfo.GENDER_MALE : UserInfo.GENDER_FEMALE;
|
||||
rgGender.check(gender == UserInfo.GENDER_MALE ? R.id.rb_male : R.id.rb_female);
|
||||
}
|
||||
}else {
|
||||
init();
|
||||
}
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
tvNick.setFilters(new InputFilter[]{new InputFilter.LengthFilter(8)});
|
||||
// 设置默认昵称
|
||||
setRandomNick();
|
||||
rgGender.setOnCheckedChangeListener((radioGroup, i) -> gender = i == rbMale.getId()?UserInfo.GENDER_MALE:UserInfo.GENDER_FEMALE);
|
||||
rgGender.setOnCheckedChangeListener((radioGroup, i) -> gender = i == rbMale.getId() ? UserInfo.GENDER_MALE : UserInfo.GENDER_FEMALE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,11 +112,8 @@ public class AddUserInfoFragment extends BaseFragment
|
||||
toast("必须要选性别哦");
|
||||
return;
|
||||
}
|
||||
|
||||
String avatarUrl = "https://image.zhongjialx.com/default_avatar.png";
|
||||
commit(tvNick.getText().toString(),avatarUrl,gender);
|
||||
commit(tvNick.getText().toString(), avatarUrl, gender);
|
||||
break;
|
||||
|
||||
case R.id.tv_random_nick:
|
||||
StatisticManager.Instance().onEvent(StatisticsProtocol.Event.EVENT_INFORMATION_RANDOM_NAME,
|
||||
"随机昵称");
|
||||
@@ -140,7 +125,7 @@ public class AddUserInfoFragment extends BaseFragment
|
||||
}
|
||||
}
|
||||
|
||||
private void setRandomNick(){
|
||||
private void setRandomNick() {
|
||||
tvRandomNick.setEnabled(false);
|
||||
UserModel.get().getRandomNick()
|
||||
.compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
|
||||
@@ -160,7 +145,7 @@ public class AddUserInfoFragment extends BaseFragment
|
||||
});
|
||||
}
|
||||
|
||||
private void commit(String nick,String avatarUrl,int gender) {
|
||||
private void commit(String nick, String avatarUrl, int gender) {
|
||||
UserInfo userInfo = new UserInfo();
|
||||
userInfo.setUid(AuthModel.get().getCurrentUid());
|
||||
userInfo.setNick(nick);
|
||||
@@ -168,7 +153,7 @@ public class AddUserInfoFragment extends BaseFragment
|
||||
|
||||
if (gender == UserInfo.GENDER_MALE || gender == UserInfo.GENDER_FEMALE) {
|
||||
userInfo.setGender(gender);
|
||||
}else {
|
||||
} else {
|
||||
toast("必须要选性别哦");
|
||||
return;
|
||||
}
|
||||
@@ -195,7 +180,7 @@ public class AddUserInfoFragment extends BaseFragment
|
||||
@Override
|
||||
public void onSuccess(UserInfo userInfo) {
|
||||
getDialogManager().dismissDialog();
|
||||
StatisticManager.Instance().onEvent(StatisticsProtocol.Event.EVENT_COMPLETE,"注册完成(提交个人资料)");
|
||||
StatisticManager.Instance().onEvent(StatisticsProtocol.Event.EVENT_COMPLETE, "注册完成(提交个人资料)");
|
||||
AuthModel.get().setThirdUserInfo(null);
|
||||
getActivity().finish();
|
||||
}
|
||||
|
@@ -1,12 +1,14 @@
|
||||
package com.yizhuan.xchat_android_core.user;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.LruCache;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.yizhuan.xchat_android_core.auth.AuthModel;
|
||||
import com.yizhuan.xchat_android_core.auth.entity.ThirdUserInfo;
|
||||
import com.yizhuan.xchat_android_core.auth.event.LoginEvent;
|
||||
import com.yizhuan.xchat_android_core.auth.event.LogoutEvent;
|
||||
import com.yizhuan.xchat_android_core.base.BaseModel;
|
||||
@@ -15,7 +17,6 @@ import com.yizhuan.xchat_android_core.bean.response.ServiceResult;
|
||||
import com.yizhuan.xchat_android_core.bean.response.result.GiftWallListResult;
|
||||
import com.yizhuan.xchat_android_core.bean.response.result.UserListResult;
|
||||
import com.yizhuan.xchat_android_core.bean.response.result.UserResult;
|
||||
import com.yizhuan.xchat_android_core.community.CommunityConstant;
|
||||
import com.yizhuan.xchat_android_core.level.event.CharmLevelUpEvent;
|
||||
import com.yizhuan.xchat_android_core.level.event.LevelUpEvent;
|
||||
import com.yizhuan.xchat_android_core.noble.NobleUtil;
|
||||
@@ -131,8 +132,28 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
@SuppressLint("CheckResult")
|
||||
private void onLogin(final long uid) {
|
||||
api.requestUserInfo(String.valueOf(uid))
|
||||
.flatMap(userResult -> {
|
||||
UserInfo userInfo = userResult.getData();
|
||||
ThirdUserInfo thirdUserInfo = AuthModel.get().getThirdUserInfo();
|
||||
if ((TextUtils.isEmpty(userInfo.getNick()) || TextUtils.isEmpty(userInfo.getAvatar())) && thirdUserInfo != null) {
|
||||
if (thirdUserInfo.getType() == ThirdUserInfo.TYPE_WX || thirdUserInfo.getType() == ThirdUserInfo.TYPE_QQ) {
|
||||
String avatarUrlWX = thirdUserInfo.getUserIcon();
|
||||
String nick = thirdUserInfo.getUserName();
|
||||
String str_gender = thirdUserInfo.getUserGender() == null ? "" : thirdUserInfo.getUserGender();
|
||||
int gender = str_gender.equals("m") ? UserInfo.GENDER_MALE : UserInfo.GENDER_FEMALE;
|
||||
return api.updateUserInfo(AuthModel.get().getTicket(), uid, nick, avatarUrlWX, gender)
|
||||
.map(userInfoServiceResult -> {
|
||||
if (userInfoServiceResult.isSuccess()) {
|
||||
return userInfoServiceResult;
|
||||
}
|
||||
return userResult;
|
||||
});
|
||||
}
|
||||
}
|
||||
return Single.just(userResult);
|
||||
})
|
||||
.compose(RxHelper.handleSchedulers())
|
||||
.flatMap((Function<UserResult, SingleSource<UserInfo>>) userResult -> {
|
||||
.flatMap(userResult -> {
|
||||
if (userResult == null || !userResult.isSuccess() || userResult.getData() == null) {
|
||||
if (currentUserInfo == null) {
|
||||
//首次登录请求用户信息失败,则退出登录
|
||||
@@ -141,16 +162,17 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
return Single.error(new Throwable("invalid userInfo"));
|
||||
}
|
||||
UserInfo userInfo = userResult.getData();
|
||||
//如果没有绑定手机号,提醒去绑定手机号
|
||||
if (userInfo.getDefUser() != 4 && !userInfo.isBindPhone()) {
|
||||
EventBus.getDefault().post(new NeedBindPhoneEvent());
|
||||
return Single.error(new Throwable("need bind phone"));
|
||||
}
|
||||
//首次注册需要完善昵称和头像
|
||||
if (TextUtils.isEmpty(userInfo.getNick()) || TextUtils.isEmpty(userInfo.getAvatar())) {
|
||||
EventBus.getDefault().post(new NeedCompleteInfoEvent());
|
||||
return Single.error(new Throwable("need nick and avatar"));
|
||||
}
|
||||
//如果没有绑定手机号,提醒去绑定手机号
|
||||
if (userInfo.getDefUser() != 4 && !userInfo.isBindPhone()) {
|
||||
EventBus.getDefault().post(new NeedBindPhoneEvent());
|
||||
return Single.error(new Throwable("need bind phone"));
|
||||
}
|
||||
|
||||
return Single.just(userResult.getData());
|
||||
})
|
||||
.subscribe(new Consumer<UserInfo>() {
|
||||
@@ -292,12 +314,12 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
return api.getUserInfoDetail(String.valueOf(uid))
|
||||
.compose(RxHelper.handleSchedulers())
|
||||
.flatMap(userDetailInfo -> {
|
||||
UserDetailInfo userInfo = userDetailInfo;
|
||||
if (null == userInfo) {
|
||||
return Single.error(new Exception("服务器返回的userInfo字段为空"));
|
||||
}
|
||||
return Single.just(userInfo);
|
||||
});
|
||||
UserDetailInfo userInfo = userDetailInfo;
|
||||
if (null == userInfo) {
|
||||
return Single.error(new Exception("服务器返回的userInfo字段为空"));
|
||||
}
|
||||
return Single.just(userInfo);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -737,7 +759,6 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 随机头像昵称开关
|
||||
*/
|
||||
@Override
|
||||
@@ -747,7 +768,6 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 随机昵称
|
||||
*/
|
||||
@Override
|
||||
@@ -757,7 +777,6 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 随机头像
|
||||
*/
|
||||
@Override
|
||||
@@ -773,7 +792,7 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
* @return -
|
||||
*/
|
||||
@GET("/user/get")
|
||||
Single<UserResult> requestUserInfo(@Query("uid") String uid);
|
||||
Single<ServiceResult<UserInfo>> requestUserInfo(@Query("uid") String uid);
|
||||
|
||||
@GET("/user/detail/get")
|
||||
Single<UserDetailInfo> getUserInfoDetail(@Query("uid") String uid);
|
||||
@@ -830,6 +849,22 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
@Field("userDesc") String userDesc,
|
||||
@Field("shareCode") String shareCode);
|
||||
|
||||
/**
|
||||
* @param ticket
|
||||
* @param uid
|
||||
* @param nick
|
||||
* @param avatar
|
||||
* @param gender
|
||||
* @return
|
||||
*/
|
||||
@FormUrlEncoded
|
||||
@POST("user/v2/update")
|
||||
Single<ServiceResult<UserInfo>> updateUserInfo(@Field("ticket") String ticket,
|
||||
@Field("uid") long uid,
|
||||
@Field("nick") String nick,
|
||||
@Field("avatar") String avatar,
|
||||
@Field("gender") int gender);
|
||||
|
||||
|
||||
/**
|
||||
* @param ticket
|
||||
@@ -929,7 +964,6 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
@Field("passwd") String password);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param erbanNo 66星球号或手机号码
|
||||
* @return -
|
||||
*/
|
||||
|
Reference in New Issue
Block a user