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
ad6d1955
Commit
ad6d1955
authored
Mar 20, 2020
by
段启岩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
适配最新登录接口
parent
8d6b8801
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
71 additions
and
6 deletions
+71
-6
app/src/main/java/cn/yunliyunwai/beyondclouds/SplashActivity.java
+6
-1
app/src/main/java/cn/yunliyunwai/beyondclouds/data/model/AuthenticationResult.java
+2
-0
app/src/main/java/cn/yunliyunwai/beyondclouds/data/model/ClientType.java
+28
-0
app/src/main/java/cn/yunliyunwai/beyondclouds/data/source/impl/UserRepositoryImpl.java
+3
-2
app/src/main/java/cn/yunliyunwai/beyondclouds/data/source/remote/UserApiStore.java
+3
-2
app/src/main/java/cn/yunliyunwai/beyondclouds/util/VersionUtils.java
+17
-0
app/src/main/java/cn/yunliyunwai/beyondclouds/viewmodel/AuthenticationViewModel.java
+12
-1
No files found.
app/src/main/java/cn/yunliyunwai/beyondclouds/SplashActivity.java
View file @
ad6d1955
...
...
@@ -3,6 +3,7 @@ package cn.yunliyunwai.beyondclouds;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.view.LayoutInflater
;
import
android.widget.Toast
;
import
androidx.annotation.Nullable
;
import
androidx.lifecycle.Observer
;
...
...
@@ -13,6 +14,7 @@ import javax.inject.Inject;
import
cn.yunliyunwai.beyondclouds.base.BaseActivity
;
import
cn.yunliyunwai.beyondclouds.databinding.ActivitySplashBinding
;
import
cn.yunliyunwai.beyondclouds.util.ContextUtils
;
import
cn.yunliyunwai.beyondclouds.util.VersionUtils
;
import
cn.yunliyunwai.beyondclouds.viewmodel.SplashActivityViewModel
;
/**
...
...
@@ -43,6 +45,9 @@ public class SplashActivity extends BaseActivity<SplashActivityViewModel, Activi
super
.
onCreate
(
savedInstanceState
);
String
versionName
=
VersionUtils
.
getVersionName
(
this
);
Toast
.
makeText
(
this
,
"App当前版本为"
+
versionName
,
Toast
.
LENGTH_SHORT
);
viewModel
.
getInitialStates
().
observe
(
this
,
new
Observer
<
SplashActivityViewModel
.
InitialStates
>()
{
@Override
public
void
onChanged
(
SplashActivityViewModel
.
InitialStates
initialStates
)
{
...
...
@@ -52,7 +57,7 @@ public class SplashActivity extends BaseActivity<SplashActivityViewModel, Activi
}
}
});
binding
.
getViewModel
()
.
initialize
();
viewModel
.
initialize
();
}
@Override
...
...
app/src/main/java/cn/yunliyunwai/beyondclouds/data/model/AuthenticationResult.java
View file @
ad6d1955
...
...
@@ -7,4 +7,6 @@ public class AuthenticationResult {
private
String
userId
;
private
String
accessToken
;
private
String
refreshToken
;
}
app/src/main/java/cn/yunliyunwai/beyondclouds/data/model/ClientType.java
0 → 100644
View file @
ad6d1955
package
cn
.
yunliyunwai
.
beyondclouds
.
data
.
model
;
public
enum
ClientType
{
WEB
(
1
),
ANDROID
(
2
)
;
private
Integer
type
;
ClientType
(
Integer
type
)
{
this
.
type
=
type
;
}
public
Integer
getType
()
{
return
type
;
}
public
static
ClientType
valueOf
(
Integer
type
)
{
if
(
null
==
type
)
{
return
WEB
;
}
for
(
ClientType
clientType
:
values
())
{
if
(
clientType
.
getType
().
equals
(
type
))
{
return
clientType
;
}
}
return
WEB
;
}
}
app/src/main/java/cn/yunliyunwai/beyondclouds/data/source/impl/UserRepositoryImpl.java
View file @
ad6d1955
...
...
@@ -6,6 +6,7 @@ import javax.inject.Inject;
import
javax.inject.Singleton
;
import
cn.yunliyunwai.beyondclouds.data.model.AuthenticationResult
;
import
cn.yunliyunwai.beyondclouds.data.model.ClientType
;
import
cn.yunliyunwai.beyondclouds.data.model.Result
;
import
cn.yunliyunwai.beyondclouds.data.model.UserInfo
;
import
cn.yunliyunwai.beyondclouds.data.model.form.AccountLoginForm
;
...
...
@@ -24,12 +25,12 @@ public class UserRepositoryImpl implements IUserRepository {
@Override
public
LiveData
<
Result
<
AuthenticationResult
>>
accountAuth
(
String
account
,
String
password
)
{
return
userApiStore
.
accountAuth
(
AccountLoginForm
.
create
(
account
,
password
));
return
userApiStore
.
accountAuth
(
AccountLoginForm
.
create
(
account
,
password
)
,
ClientType
.
ANDROID
.
getType
()
);
}
@Override
public
LiveData
<
Result
<
AuthenticationResult
>>
smsAuth
(
String
mobile
,
String
verifyCode
)
{
return
userApiStore
.
smsAuth
(
SmsLoginForm
.
create
(
mobile
,
verifyCode
));
return
userApiStore
.
smsAuth
(
SmsLoginForm
.
create
(
mobile
,
verifyCode
)
,
ClientType
.
ANDROID
.
getType
()
);
}
@Override
...
...
app/src/main/java/cn/yunliyunwai/beyondclouds/data/source/remote/UserApiStore.java
View file @
ad6d1955
...
...
@@ -10,6 +10,7 @@ import cn.yunliyunwai.beyondclouds.data.model.form.SmsLoginForm;
import
retrofit2.http.Body
;
import
retrofit2.http.GET
;
import
retrofit2.http.POST
;
import
retrofit2.http.Query
;
public
interface
UserApiStore
{
...
...
@@ -19,7 +20,7 @@ public interface UserApiStore {
* @return
*/
@POST
(
"auth/password"
)
LiveData
<
Result
<
AuthenticationResult
>>
accountAuth
(
@Body
AccountLoginForm
accountLoginForm
);
LiveData
<
Result
<
AuthenticationResult
>>
accountAuth
(
@Body
AccountLoginForm
accountLoginForm
,
@Query
(
"clientType"
)
Integer
clientType
);
/**
* 短信验证码登录
...
...
@@ -27,7 +28,7 @@ public interface UserApiStore {
* @return
*/
@POST
(
"auth/sms"
)
LiveData
<
Result
<
AuthenticationResult
>>
smsAuth
(
@Body
SmsLoginForm
smsLoginForm
);
LiveData
<
Result
<
AuthenticationResult
>>
smsAuth
(
@Body
SmsLoginForm
smsLoginForm
,
@Query
(
"clientType"
)
Integer
clientType
);
/**
* 获取我的用户信息
...
...
app/src/main/java/cn/yunliyunwai/beyondclouds/util/VersionUtils.java
0 → 100644
View file @
ad6d1955
package
cn
.
yunliyunwai
.
beyondclouds
.
util
;
import
android.content.Context
;
import
android.content.pm.PackageInfo
;
public
class
VersionUtils
{
public
static
String
getVersionName
(
Context
context
)
{
try
{
PackageInfo
packageInfo
=
context
.
getPackageManager
().
getPackageInfo
(
context
.
getPackageName
(),
0
);
return
packageInfo
.
versionName
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
}
app/src/main/java/cn/yunliyunwai/beyondclouds/viewmodel/AuthenticationViewModel.java
View file @
ad6d1955
...
...
@@ -26,6 +26,7 @@ public class AuthenticationViewModel extends ViewModel {
private
static
final
String
SHARED_PREFERENCES_NAME_AUTHENTICATION
=
"SHARED_PREFERENCES_AUTHENTICATION"
;
private
static
final
String
SHARED_PREFERENCES_AUTHENTICATION_KEY_TOKEN
=
"SHARED_PREFERENCES_AUTHENTICATION_TOKEN"
;
private
static
final
String
SHARED_PREFERENCES_AUTHENTICATION_KEY_REFRESH_TOKEN
=
"SHARED_PREFERENCES_AUTHENTICATION_REFRESH_TOKEN"
;
private
static
final
String
SHARED_PREFERENCES_AUTHENTICATION_KEY_USER_INFO
=
"SHARED_PREFERENCES_AUTHENTICATION_USER_INFO"
;
...
...
@@ -71,6 +72,11 @@ public class AuthenticationViewModel extends ViewModel {
private
String
mToken
;
/**
* refreshToken
*/
private
String
mRefreshToken
;
/**
* 认证失败的信息
*/
private
String
mAuthErrorMsg
;
...
...
@@ -198,6 +204,7 @@ public class AuthenticationViewModel extends ViewModel {
public
void
onChanged
(
Result
<
AuthenticationResult
>
authenticationResultResult
)
{
if
(
authenticationResultResult
.
getCode
()
==
0
)
{
mToken
=
authenticationResultResult
.
getData
().
getAccessToken
();
mRefreshToken
=
authenticationResultResult
.
getData
().
getRefreshToken
();
authenticationState
.
setValue
(
AuthenticationState
.
WAIT_FOR_FETCH_USER_INFO
);
}
else
{
mAuthErrorMsg
=
authenticationResultResult
.
getMsg
();
...
...
@@ -219,6 +226,7 @@ public class AuthenticationViewModel extends ViewModel {
public
void
onChanged
(
Result
<
AuthenticationResult
>
authenticationResultResult
)
{
if
(
authenticationResultResult
.
getCode
()
==
0
)
{
mToken
=
authenticationResultResult
.
getData
().
getAccessToken
();
mRefreshToken
=
authenticationResultResult
.
getData
().
getRefreshToken
();
authenticationState
.
setValue
(
AuthenticationState
.
WAIT_FOR_FETCH_USER_INFO
);
}
else
{
mAuthErrorMsg
=
authenticationResultResult
.
getMsg
();
...
...
@@ -256,6 +264,7 @@ public class AuthenticationViewModel extends ViewModel {
SharedPreferences
sharedPreferences
=
mContext
.
getSharedPreferences
(
SHARED_PREFERENCES_NAME_AUTHENTICATION
,
Context
.
MODE_PRIVATE
);
sharedPreferences
.
edit
()
.
putString
(
SHARED_PREFERENCES_AUTHENTICATION_KEY_TOKEN
,
mToken
)
.
putString
(
SHARED_PREFERENCES_AUTHENTICATION_KEY_REFRESH_TOKEN
,
mRefreshToken
)
.
putString
(
SHARED_PREFERENCES_AUTHENTICATION_KEY_USER_INFO
,
JsonUtils
.
toJson
(
mUserInfo
))
.
commit
();
}
...
...
@@ -266,9 +275,11 @@ public class AuthenticationViewModel extends ViewModel {
private
void
loadTokenAndUserInfoFromLocal
()
{
SharedPreferences
sharedPreferences
=
mContext
.
getSharedPreferences
(
SHARED_PREFERENCES_NAME_AUTHENTICATION
,
Context
.
MODE_PRIVATE
);
String
token
=
sharedPreferences
.
getString
(
SHARED_PREFERENCES_AUTHENTICATION_KEY_TOKEN
,
null
);
String
refreshToken
=
sharedPreferences
.
getString
(
SHARED_PREFERENCES_AUTHENTICATION_KEY_REFRESH_TOKEN
,
null
);
String
userInfo
=
sharedPreferences
.
getString
(
SHARED_PREFERENCES_AUTHENTICATION_KEY_USER_INFO
,
null
);
if
(
null
!=
token
&&
null
!=
userInfo
)
{
if
(
null
!=
token
&&
null
!=
refreshToken
&&
null
!=
userInfo
)
{
mToken
=
token
;
mRefreshToken
=
refreshToken
;
mUserInfo
=
JsonUtils
.
json2Bean
(
userInfo
,
UserInfo
.
class
);
this
.
authenticationState
.
setValue
(
AuthenticationState
.
AUTHENTICATED
);
}
else
{
...
...
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