登录流程修改

This commit is contained in:
huangjian
2020-05-13 15:30:15 +08:00
parent 00734faff5
commit addb1e7149
2 changed files with 67 additions and 48 deletions

View File

@@ -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 -
*/