Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beyond-clouds-android
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
云深项目组
beyond-clouds-android
Commits
4689e9c8
Commit
4689e9c8
authored
Mar 19, 2020
by
段启岩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加认证失败提示
parent
2b200faa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
7 deletions
+33
-7
app/src/main/java/cn/yunliyunwai/beyondclouds/ui/login/LoginActivity.java
+3
-0
app/src/main/java/cn/yunliyunwai/beyondclouds/viewmodel/AuthenticationViewModel.java
+30
-7
No files found.
app/src/main/java/cn/yunliyunwai/beyondclouds/ui/login/LoginActivity.java
View file @
4689e9c8
...
@@ -68,6 +68,9 @@ public class LoginActivity extends BaseActivity<AuthenticationViewModel, Activit
...
@@ -68,6 +68,9 @@ public class LoginActivity extends BaseActivity<AuthenticationViewModel, Activit
if
(
authenticationState
==
AuthenticationViewModel
.
AuthenticationState
.
WAIT_FOR_FETCH_USER_INFO
)
{
if
(
authenticationState
==
AuthenticationViewModel
.
AuthenticationState
.
WAIT_FOR_FETCH_USER_INFO
)
{
// 获取用户信息
// 获取用户信息
viewModel
.
fetchUserInfo
();
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
)
{
}
else
if
(
authenticationState
==
AuthenticationViewModel
.
AuthenticationState
.
AUTHENTICATED
)
{
// 认证成功,关闭登录界面
// 认证成功,关闭登录界面
finish
();
finish
();
...
...
app/src/main/java/cn/yunliyunwai/beyondclouds/viewmodel/AuthenticationViewModel.java
View file @
4689e9c8
...
@@ -29,7 +29,7 @@ public class AuthenticationViewModel extends ViewModel {
...
@@ -29,7 +29,7 @@ public class AuthenticationViewModel extends ViewModel {
/**
/**
* 未认证
* 未认证
*/
*/
UN_AUTHENTICAT
ION
,
UN_AUTHENTICAT
E
,
/**
/**
* 等待获取用户信息
* 等待获取用户信息
...
@@ -37,6 +37,11 @@ public class AuthenticationViewModel extends ViewModel {
...
@@ -37,6 +37,11 @@ public class AuthenticationViewModel extends ViewModel {
WAIT_FOR_FETCH_USER_INFO
,
WAIT_FOR_FETCH_USER_INFO
,
/**
/**
* 认证失败
*/
AUTHENTICATE_FAILURE
,
/**
* 已认证
* 已认证
*/
*/
AUTHENTICATED
AUTHENTICATED
...
@@ -59,7 +64,12 @@ public class AuthenticationViewModel extends ViewModel {
...
@@ -59,7 +64,12 @@ public class AuthenticationViewModel extends ViewModel {
/**
/**
* accessToken
* accessToken
*/
*/
private
String
token
;
private
String
mToken
;
/**
* 认证失败的信息
*/
private
String
mAuthErrorMsg
;
/**
/**
* 用来保存上一个登录方式里账号输入框的值
* 用来保存上一个登录方式里账号输入框的值
...
@@ -104,10 +114,10 @@ public class AuthenticationViewModel extends ViewModel {
...
@@ -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
);
String
token
=
context
.
getSharedPreferences
(
SHARED_PREFERENCES_NAME_AUTHENTICATION
,
Context
.
MODE_PRIVATE
).
getString
(
SHARED_PREFERENCES_AUTHENTICATION_KEY_TOKEN
,
null
);
if
(
null
!=
token
)
{
if
(
null
!=
token
)
{
this
.
t
oken
=
token
;
this
.
mT
oken
=
token
;
this
.
authenticationState
.
setValue
(
AuthenticationState
.
AUTHENTICATED
);
this
.
authenticationState
.
setValue
(
AuthenticationState
.
AUTHENTICATED
);
}
else
{
}
else
{
this
.
authenticationState
.
setValue
(
AuthenticationState
.
UN_AUTHENTICAT
ION
);
this
.
authenticationState
.
setValue
(
AuthenticationState
.
UN_AUTHENTICAT
E
);
}
}
this
.
loginWay
.
setValue
(
LoginWay
.
ACCOUNT
);
this
.
loginWay
.
setValue
(
LoginWay
.
ACCOUNT
);
...
@@ -139,7 +149,11 @@ public class AuthenticationViewModel extends ViewModel {
...
@@ -139,7 +149,11 @@ public class AuthenticationViewModel extends ViewModel {
}
}
public
String
getToken
()
{
public
String
getToken
()
{
return
token
;
return
mToken
;
}
public
String
getAuthErrorMsg
()
{
return
mAuthErrorMsg
;
}
}
/**
/**
...
@@ -174,8 +188,11 @@ public class AuthenticationViewModel extends ViewModel {
...
@@ -174,8 +188,11 @@ public class AuthenticationViewModel extends ViewModel {
@Override
@Override
public
void
onChanged
(
Result
<
AuthenticationResult
>
authenticationResultResult
)
{
public
void
onChanged
(
Result
<
AuthenticationResult
>
authenticationResultResult
)
{
if
(
authenticationResultResult
.
getCode
()
==
0
)
{
if
(
authenticationResultResult
.
getCode
()
==
0
)
{
t
oken
=
authenticationResultResult
.
getData
().
getAccessToken
();
mT
oken
=
authenticationResultResult
.
getData
().
getAccessToken
();
authenticationState
.
setValue
(
AuthenticationState
.
WAIT_FOR_FETCH_USER_INFO
);
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 {
...
@@ -192,8 +209,11 @@ public class AuthenticationViewModel extends ViewModel {
@Override
@Override
public
void
onChanged
(
Result
<
AuthenticationResult
>
authenticationResultResult
)
{
public
void
onChanged
(
Result
<
AuthenticationResult
>
authenticationResultResult
)
{
if
(
authenticationResultResult
.
getCode
()
==
0
)
{
if
(
authenticationResultResult
.
getCode
()
==
0
)
{
t
oken
=
authenticationResultResult
.
getData
().
getAccessToken
();
mT
oken
=
authenticationResultResult
.
getData
().
getAccessToken
();
authenticationState
.
setValue
(
AuthenticationState
.
WAIT_FOR_FETCH_USER_INFO
);
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 {
...
@@ -209,6 +229,9 @@ public class AuthenticationViewModel extends ViewModel {
public
void
onChanged
(
Result
<
UserInfo
>
userInfoResult
)
{
public
void
onChanged
(
Result
<
UserInfo
>
userInfoResult
)
{
if
(
userInfoResult
.
getCode
()
==
0
)
{
if
(
userInfoResult
.
getCode
()
==
0
)
{
authenticationState
.
setValue
(
AuthenticationState
.
AUTHENTICATED
);
authenticationState
.
setValue
(
AuthenticationState
.
AUTHENTICATED
);
}
else
{
mAuthErrorMsg
=
userInfoResult
.
getMsg
();
authenticationState
.
setValue
(
AuthenticationState
.
AUTHENTICATE_FAILURE
);
}
}
}
}
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment