Commit 4689e9c8 by 段启岩

添加认证失败提示

parent 2b200faa
......@@ -68,6 +68,9 @@ public class LoginActivity extends BaseActivity<AuthenticationViewModel, Activit
if (authenticationState == AuthenticationViewModel.AuthenticationState.WAIT_FOR_FETCH_USER_INFO) {
// 获取用户信息
viewModel.fetchUserInfo();
} else if (authenticationState == AuthenticationViewModel.AuthenticationState.AUTHENTICATE_FAILURE) {
// 认证失败
Toast.makeText(LoginActivity.this, viewModel.getAuthErrorMsg(), Toast.LENGTH_SHORT).show();
} else if (authenticationState == AuthenticationViewModel.AuthenticationState.AUTHENTICATED) {
// 认证成功,关闭登录界面
finish();
......
......@@ -29,7 +29,7 @@ public class AuthenticationViewModel extends ViewModel {
/**
* 未认证
*/
UN_AUTHENTICATION,
UN_AUTHENTICATE,
/**
* 等待获取用户信息
......@@ -37,6 +37,11 @@ public class AuthenticationViewModel extends ViewModel {
WAIT_FOR_FETCH_USER_INFO,
/**
* 认证失败
*/
AUTHENTICATE_FAILURE,
/**
* 已认证
*/
AUTHENTICATED
......@@ -59,7 +64,12 @@ public class AuthenticationViewModel extends ViewModel {
/**
* accessToken
*/
private String token;
private String mToken;
/**
* 认证失败的信息
*/
private String mAuthErrorMsg;
/**
* 用来保存上一个登录方式里账号输入框的值
......@@ -104,10 +114,10 @@ public class AuthenticationViewModel extends ViewModel {
String token = context.getSharedPreferences(SHARED_PREFERENCES_NAME_AUTHENTICATION, Context.MODE_PRIVATE).getString(SHARED_PREFERENCES_AUTHENTICATION_KEY_TOKEN, null);
if (null != token) {
this.token = token;
this.mToken = token;
this.authenticationState.setValue(AuthenticationState.AUTHENTICATED);
} else {
this.authenticationState.setValue(AuthenticationState.UN_AUTHENTICATION);
this.authenticationState.setValue(AuthenticationState.UN_AUTHENTICATE);
}
this.loginWay.setValue(LoginWay.ACCOUNT);
......@@ -139,7 +149,11 @@ public class AuthenticationViewModel extends ViewModel {
}
public String getToken() {
return token;
return mToken;
}
public String getAuthErrorMsg() {
return mAuthErrorMsg;
}
/**
......@@ -174,8 +188,11 @@ public class AuthenticationViewModel extends ViewModel {
@Override
public void onChanged(Result<AuthenticationResult> authenticationResultResult) {
if (authenticationResultResult.getCode() == 0) {
token = authenticationResultResult.getData().getAccessToken();
mToken = authenticationResultResult.getData().getAccessToken();
authenticationState.setValue(AuthenticationState.WAIT_FOR_FETCH_USER_INFO);
} else {
mAuthErrorMsg = authenticationResultResult.getMsg();
authenticationState.setValue(AuthenticationState.AUTHENTICATE_FAILURE);
}
}
});
......@@ -192,8 +209,11 @@ public class AuthenticationViewModel extends ViewModel {
@Override
public void onChanged(Result<AuthenticationResult> authenticationResultResult) {
if (authenticationResultResult.getCode() == 0) {
token = authenticationResultResult.getData().getAccessToken();
mToken = authenticationResultResult.getData().getAccessToken();
authenticationState.setValue(AuthenticationState.WAIT_FOR_FETCH_USER_INFO);
} else {
mAuthErrorMsg = authenticationResultResult.getMsg();
authenticationState.setValue(AuthenticationState.AUTHENTICATE_FAILURE);
}
}
});
......@@ -209,6 +229,9 @@ public class AuthenticationViewModel extends ViewModel {
public void onChanged(Result<UserInfo> userInfoResult) {
if (userInfoResult.getCode() == 0) {
authenticationState.setValue(AuthenticationState.AUTHENTICATED);
} else {
mAuthErrorMsg = userInfoResult.getMsg();
authenticationState.setValue(AuthenticationState.AUTHENTICATE_FAILURE);
}
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment