Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
YDL-Component-Medical
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨凯
YDL-Component-Medical
Commits
6ff932cd
Commit
6ff932cd
authored
Jan 06, 2021
by
YKai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:一键登录代码优化
parent
49b3a2bb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
112 additions
and
48 deletions
+112
-48
MainActivity.kt
app/src/main/java/com/ydl/component/MainActivity.kt
+1
-1
MineFragment.java
m-user/src/main/java/com/yidianling/user/mine/MineFragment.java
+44
-22
OneKeyLoginHelp.kt
m-user/src/main/java/com/yidianling/user/ui/login/OneKeyLoginHelp.kt
+67
-25
No files found.
app/src/main/java/com/ydl/component/MainActivity.kt
View file @
6ff932cd
...
...
@@ -92,7 +92,7 @@ class MainActivity : BaseLceActivity<DemoContract.View, DemoContract.Presenter>(
// .withBoolean("bind_phone", false)
// .withBoolean("isFromGuide", true)
// .navigation()
if
(!
OneKeyLoginHelp
.
i
sGetTokenSuccess
)
{
if
(!
OneKeyLoginHelp
.
mI
sGetTokenSuccess
)
{
OneKeyLoginHelp
.
setAuthListener
()
}
OneKeyLoginHelp
.
getLoginToken
(
false
)
...
...
m-user/src/main/java/com/yidianling/user/mine/MineFragment.java
View file @
6ff932cd
...
...
@@ -352,10 +352,21 @@ public class MineFragment extends BaseFragment implements SwipeRefreshLayout.OnR
.
into
(
img_head
);
}
//33说去掉
// if (!TextUtils.isEmpty(userInfo.getHome_bg())) {
// GlideApp.with(this).load(userInfo.getHome_bg()).error(R.drawable.profile_bg_11).into(img_bg);//设置封面
// }
}
/**
* 跳转到登录
*
*/
private
void
startLogin
(){
if
(
OneKeyLoginHelp
.
INSTANCE
.
getMIsOpenOneKeyLogin
())
{
if
(!
OneKeyLoginHelp
.
INSTANCE
.
getMIsGetTokenSuccess
())
{
OneKeyLoginHelp
.
INSTANCE
.
setAuthListener
();
}
OneKeyLoginHelp
.
INSTANCE
.
getLoginToken
(
true
);
}
else
{
RegisterAndLoginActivity
.
Companion
.
start
(
getActivity
());
}
}
...
...
@@ -364,11 +375,13 @@ public class MineFragment extends BaseFragment implements SwipeRefreshLayout.OnR
int
id
=
v
.
getId
();
//切换环境逻辑按钮
if
(
id
==
R
.
id
.
text_userName
||
id
==
R
.
id
.
cv_duration
)
{
if
(!
UserHelper
.
INSTANCE
.
isLogin
())
{
RegisterAndLoginActivity
.
Companion
.
start
(
getActivity
());
// RegisterAndLoginActivity.Companion.start(getActivity());
startLogin
();
}
}
else
if
(
id
==
R
.
id
.
iv_edit_info
)
{
//修改资料
if
(!
UserHelper
.
INSTANCE
.
isLogin
())
{
RegisterAndLoginActivity
.
Companion
.
start
(
getActivity
());
// RegisterAndLoginActivity.Companion.start(getActivity());
startLogin
();
return
;
}
if
(
userInfoData
!=
null
)
{
...
...
@@ -381,10 +394,7 @@ public class MineFragment extends BaseFragment implements SwipeRefreshLayout.OnR
}
if
(!
UserHelper
.
INSTANCE
.
isLogin
())
{
// RegisterAndLoginActivity.Companion.start(getActivity());
if
(!
OneKeyLoginHelp
.
INSTANCE
.
isGetTokenSuccess
()){
OneKeyLoginHelp
.
INSTANCE
.
setAuthListener
();
}
OneKeyLoginHelp
.
INSTANCE
.
getLoginToken
(
true
);
startLogin
();
return
;
}
if
(
userInfoData
!=
null
)
{
...
...
@@ -393,20 +403,23 @@ public class MineFragment extends BaseFragment implements SwipeRefreshLayout.OnR
}
}
else
if
(
id
==
R
.
id
.
ll_account
)
{
//账户余额
if
(!
UserHelper
.
INSTANCE
.
isLogin
())
{
RegisterAndLoginActivity
.
Companion
.
start
(
getActivity
());
// RegisterAndLoginActivity.Companion.start(getActivity());
startLogin
();
return
;
}
startActivity
(
new
Intent
(
getActivity
(),
AccountHistoryActivity
.
class
));
}
else
if
(
id
==
R
.
id
.
ll_red_packet
)
{
//我的红包
if
(!
UserHelper
.
INSTANCE
.
isLogin
())
{
RegisterAndLoginActivity
.
Companion
.
start
(
getActivity
());
// RegisterAndLoginActivity.Companion.start(getActivity());
startLogin
();
return
;
}
clearCouponStatus
();
ModularServiceManager
.
INSTANCE
.
provide
(
IAppService
.
class
).
myRedPockIntent
(
getActivity
());
}
else
if
(
id
==
R
.
id
.
ll_fans
)
{
//粉丝
if
(!
UserHelper
.
INSTANCE
.
isLogin
())
{
RegisterAndLoginActivity
.
Companion
.
start
(
getActivity
());
// RegisterAndLoginActivity.Companion.start(getActivity());
startLogin
();
return
;
}
...
...
@@ -414,7 +427,8 @@ public class MineFragment extends BaseFragment implements SwipeRefreshLayout.OnR
NewH5Activity
.
start
(
getActivity
(),
h5Params
);
}
else
if
(
id
==
R
.
id
.
ll_guanzhu
)
{
//我关注的
if
(!
UserHelper
.
INSTANCE
.
isLogin
())
{
RegisterAndLoginActivity
.
Companion
.
start
(
getActivity
());
// RegisterAndLoginActivity.Companion.start(getActivity());
startLogin
();
return
;
}
...
...
@@ -422,7 +436,8 @@ public class MineFragment extends BaseFragment implements SwipeRefreshLayout.OnR
NewH5Activity
.
start
(
getActivity
(),
h5Params1
);
}
else
if
(
id
==
R
.
id
.
ll_my_trends
)
{
if
(!
UserHelper
.
INSTANCE
.
isLogin
())
{
RegisterAndLoginActivity
.
Companion
.
start
(
getActivity
());
// RegisterAndLoginActivity.Companion.start(getActivity());
startLogin
();
return
;
}
BuryPointUtils
.
getInstance
().
createMap
()
...
...
@@ -436,13 +451,15 @@ public class MineFragment extends BaseFragment implements SwipeRefreshLayout.OnR
}
else
if
(
id
==
R
.
id
.
jtv_account_setting
)
{
//账号设置
//点击消息 未登录请先登录
if
(!
UserHelper
.
INSTANCE
.
isLogin
())
{
RegisterAndLoginActivity
.
Companion
.
start
(
getActivity
());
// RegisterAndLoginActivity.Companion.start(getActivity());
startLogin
();
return
;
}
startActivity
(
new
Intent
(
getActivity
(),
AccountSettingActivity
.
class
));
}
else
if
(
id
==
R
.
id
.
jtv_account_privacy
)
{
// 未登录请先登录
if
(!
UserHelper
.
INSTANCE
.
isLogin
())
{
RegisterAndLoginActivity
.
Companion
.
start
(
getActivity
());
// RegisterAndLoginActivity.Companion.start(getActivity());
startLogin
();
return
;
}
UserHelper
.
INSTANCE
.
getUsetSetting
().
setMeSafePrivateIsClick
(
true
);
...
...
@@ -450,7 +467,8 @@ public class MineFragment extends BaseFragment implements SwipeRefreshLayout.OnR
startActivity
(
new
Intent
(
getActivity
(),
PrivacyActivity
.
class
));
}
else
if
(
id
==
R
.
id
.
ll_trade_order
)
{
//预约
if
(!
UserHelper
.
INSTANCE
.
isLogin
())
{
RegisterAndLoginActivity
.
Companion
.
start
(
getActivity
());
// RegisterAndLoginActivity.Companion.start(getActivity());
startLogin
();
return
;
}
BuryPointUtils
.
getInstance
().
createMap
()
...
...
@@ -461,13 +479,15 @@ public class MineFragment extends BaseFragment implements SwipeRefreshLayout.OnR
NewH5Activity
.
start
(
getActivity
(),
h5Params3
);
}
else
if
(
id
==
R
.
id
.
ll_my_courses
)
{
//我的课程
if
(!
UserHelper
.
INSTANCE
.
isLogin
())
{
RegisterAndLoginActivity
.
Companion
.
start
(
getActivity
());
// RegisterAndLoginActivity.Companion.start(getActivity());
startLogin
();
return
;
}
ModularServiceManager
.
INSTANCE
.
provide
(
ICourseService
.
class
).
startMyCourseActivity
(
getActivity
());
}
else
if
(
id
==
R
.
id
.
ll_call_order
)
{
//倾诉
if
(!
UserHelper
.
INSTANCE
.
isLogin
())
{
RegisterAndLoginActivity
.
Companion
.
start
(
getActivity
());
// RegisterAndLoginActivity.Companion.start(getActivity());
startLogin
();
return
;
}
BuryPointUtils
.
getInstance
().
createMap
()
...
...
@@ -491,7 +511,8 @@ public class MineFragment extends BaseFragment implements SwipeRefreshLayout.OnR
}
}
else
if
(
id
==
R
.
id
.
ll_my_test_log
)
{
//测试记录
if
(!
UserHelper
.
INSTANCE
.
isLogin
())
{
RegisterAndLoginActivity
.
Companion
.
start
(
getActivity
());
// RegisterAndLoginActivity.Companion.start(getActivity());
startLogin
();
return
;
}
BuryPointUtils
.
getInstance
().
createMap
()
...
...
@@ -508,7 +529,8 @@ public class MineFragment extends BaseFragment implements SwipeRefreshLayout.OnR
NewH5Activity
.
start
(
getActivity
(),
params1
);
}
else
if
(
id
==
R
.
id
.
ll_reward
)
{
if
(!
UserHelper
.
INSTANCE
.
isLogin
())
{
RegisterAndLoginActivity
.
Companion
.
start
(
getActivity
());
// RegisterAndLoginActivity.Companion.start(getActivity());
startLogin
();
return
;
}
H5Params
h5Param
=
new
H5Params
(
HttpConfig
.
Companion
.
getH5_URL
()
+
"course/invite-record"
,
null
);
...
...
m-user/src/main/java/com/yidianling/user/ui/login/OneKeyLoginHelp.kt
View file @
6ff932cd
...
...
@@ -2,7 +2,6 @@ package com.yidianling.user.ui.login
import
android.content.pm.ActivityInfo
import
android.graphics.Color
import
android.util.Log
import
android.util.TypedValue
import
android.view.Gravity
import
android.view.View
...
...
@@ -33,32 +32,35 @@ object OneKeyLoginHelp {
const
val
YDL_EXPERT_APP
=
2
const
val
PHONE_CHECK
=
1
// 本机号码验证
const
val
ONE_KEY_LOGIN
=
2
// 一键登录
private
var
mAuthType
:
Int
=
1
var
isGetTokenSuccess
=
true
var
mPhoneNumberAuthHelper
:
PhoneNumberAuthHelper
?
=
null
private
var
mActivity
:
BaseActivity
?
=
null
private
var
mAppType
:
Int
=
YDL_USER_APP
var
mIsGetTokenSuccess
=
true
// 获取token是否成功,默认是成功
var
mIsOpenOneKeyLogin
=
false
// 是否开启一键登录
var
mIsFromGuide
=
true
var
mAuthType
=
ONE_KEY_LOGIN
// 1:本机号码校验 2: ⼀键登录
private
lateinit
var
mActivity
:
BaseActivity
fun
sdkInit
(
activity
:
BaseActivity
,
a
uthType
:
Int
,
login
Type
:
Int
)
{
fun
sdkInit
(
activity
:
BaseActivity
,
a
ppType
:
Int
,
auth
Type
:
Int
)
{
mActivity
=
activity
mAppType
=
appType
mAuthType
=
authType
mPhoneNumberAuthHelper
=
PhoneNumberAuthHelper
.
getInstance
(
activity
,
mTokenListener
)
mPhoneNumberAuthHelper
?.
let
{
// APP是否处于调试状态,使⽤ getReporter.setLoggerEnable(true) 可以关闭此项检测
it
.
reporter
.
setLoggerEnable
(
true
)
// 设置密钥
if
(
a
uth
Type
==
YDL_USER_APP
)
{
if
(
a
pp
Type
==
YDL_USER_APP
)
{
it
.
setAuthSDKInfo
(
YDL_USER_APP_KEY
)
}
else
if
(
a
uth
Type
==
YDL_EXPERT_APP
)
{
}
else
if
(
a
pp
Type
==
YDL_EXPERT_APP
)
{
it
.
setAuthSDKInfo
(
YDL_EXPERT_APP_KEY
)
}
// 检查认证环境
// it.checkEnvAvailable(
login
Type) // type 1:本机号码校验 2: ⼀键登录
// it.checkEnvAvailable(
auth
Type) // type 1:本机号码校验 2: ⼀键登录
}
}
/**
* 设置token监听
*
...
...
@@ -74,16 +76,28 @@ object OneKeyLoginHelp {
fun
toLoginActivity
()
{
ARouter
.
getInstance
().
build
(
"/user/login"
)
.
withBoolean
(
"bind_phone"
,
false
)
.
withBoolean
(
"isFromGuide"
,
tru
e
)
.
withBoolean
(
"isFromGuide"
,
mIsFromGuid
e
)
.
navigation
()
}
/**
* 本机手机号码校验
*
*/
fun
getVerifyToken
()
{
mAuthType
=
PHONE_CHECK
mPhoneNumberAuthHelper
?.
getVerifyToken
(
5000
)
// 5000表示超时时间 单位ms
}
/**
* 拉起一键登录界面
*
* @param isOpenDialog 是否是弹窗
*/
fun
getLoginToken
(
isOpenDialog
:
Boolean
)
{
mIsFromGuide
=
isOpenDialog
mAuthType
=
ONE_KEY_LOGIN
mPhoneNumberAuthHelper
?.
let
{
// 打开页面
if
(
isOpenDialog
)
{
...
...
@@ -167,10 +181,14 @@ object OneKeyLoginHelp {
var
loginLogo
=
"ic_ydl_login_logo"
var
loginHeight
=
40
var
loginWidth
=
118
if
(
mAuthType
==
YDL_EXPERT_APP
)
{
var
appPrivacyOneTip
=
"壹点灵用户使用协议"
var
appPrivacyOne
=
"https://h5.ydl.com/SDUserProtol"
var
appPrivacyTwo
=
"https://m.ydl.com/Protol/yinsi"
if
(
mAppType
==
YDL_EXPERT_APP
)
{
loginLogo
=
"ic_expert_login_logo"
loginHeight
=
60
loginWidth
=
60
appPrivacyOneTip
=
"壹点灵专家使用协议"
}
phoneNumberAuthHelper
.
setAuthUIConfig
(
AuthUIConfig
.
Builder
()
...
...
@@ -199,10 +217,10 @@ object OneKeyLoginHelp {
.
setSwitchAccText
(
"切换号码"
)
.
setSwitchAccTextSize
(
15
)
.
setSwitchAccTextColor
(
Color
.
parseColor
(
"#1DA1F2"
))
.
setAppPrivacyOne
(
"壹点灵专家使用协议"
,
""
)
.
setAppPrivacyTwo
(
"隐私协议"
,
""
)
.
setAppPrivacyOne
(
appPrivacyOneTip
,
appPrivacyOne
)
.
setAppPrivacyTwo
(
"隐私协议"
,
appPrivacyTwo
)
.
setAppPrivacyColor
(
Color
.
parseColor
(
"#999999"
),
Color
.
parseColor
(
"#1da1f2"
))
.
setCheckboxHidden
(
true
)
// 设置是否同意协议的checkbox隐藏
//
.setCheckboxHidden(true) // 设置是否同意协议的checkbox隐藏
.
setPrivacyBefore
(
"登录即代表您同意"
)
.
setScreenOrientation
(
ActivityInfo
.
SCREEN_ORIENTATION_SENSOR_PORTRAIT
)
// 设置竖屏
.
setAuthPageActIn
(
"in_activity"
,
"out_activity"
)
...
...
@@ -247,10 +265,10 @@ object OneKeyLoginHelp {
.
setSwitchAccTextSize
(
15
)
.
setSwitchAccTextColor
(
Color
.
parseColor
(
"#666666"
))
.
setSwitchOffsetY
(
168
)
.
setAppPrivacyOne
(
"壹点灵
专家使用协议"
,
"
"
)
.
setAppPrivacyTwo
(
"隐私协议"
,
""
)
.
setAppPrivacyOne
(
"壹点灵
用户使用协议"
,
"https://h5.ydl.com/SDUserProtol
"
)
.
setAppPrivacyTwo
(
"隐私协议"
,
"
https://m.ydl.com/Protol/yinsi
"
)
.
setAppPrivacyColor
(
Color
.
parseColor
(
"#999999"
),
Color
.
parseColor
(
"#1da1f2"
))
.
setCheckboxHidden
(
true
)
// 设置是否同意协议的checkbox隐藏
//
.setCheckboxHidden(true) // 设置是否同意协议的checkbox隐藏
.
setPrivacyBefore
(
"登录即代表您同意"
)
.
setDialogHeight
(
dialogHeight
)
.
setDialogBottom
(
true
)
...
...
@@ -266,10 +284,15 @@ object OneKeyLoginHelp {
val
tokenRet
=
TokenRet
.
fromJson
(
s
)
when
(
tokenRet
.
code
)
{
ResultCode
.
CODE_START_AUTHPAGE_SUCCESS
->
{
// 唤起一键登录页面成功
Log
.
i
(
"TAG"
,
"唤起授权页成功:$s"
)
Log
Util
.
e
(
"唤起授权页成功:$s"
)
}
ResultCode
.
CODE_SUCCESS
->
{
// 点击登录后获取token成功
val
token
=
tokenRet
.
token
if
(
mAuthType
==
PHONE_CHECK
)
{
// 本机号码校验
verifyTokenResultListener
.
onTokenSuccess
(
token
)
}
else
{
// 登录
}
mPhoneNumberAuthHelper
?.
setAuthListener
(
null
)
}
}
...
...
@@ -277,18 +300,37 @@ object OneKeyLoginHelp {
override
fun
onTokenFailed
(
s
:
String
)
{
LogUtil
.
e
(
s
)
i
sGetTokenSuccess
=
false
mI
sGetTokenSuccess
=
false
val
tokenRet
=
TokenRet
.
fromJson
(
s
)
when
(
tokenRet
.
code
)
{
ResultCode
.
CODE_ERROR_USER_CANCEL
->
{
// 用户主动取消一键登录
if
(
mAuthType
==
PHONE_CHECK
)
{
// 本机号码校验
verifyTokenResultListener
.
onTokenFailed
(
tokenRet
)
}
else
{
// 一键登录
when
(
tokenRet
.
code
)
{
ResultCode
.
CODE_ERROR_USER_CANCEL
->
{
// 用户主动取消一键登录
}
else
->
{
// 其它失败原因
// 跳转到原生登录界面
toLoginActivity
()
}
else
->
{
// 其它失败原因
// 跳转到原生登录界面
toLoginActivity
()
}
}
}
mPhoneNumberAuthHelper
?.
setAuthListener
(
null
)
}
}
// 号码验证监听
private
lateinit
var
verifyTokenResultListener
:
VerifyTokenResultListener
interface
VerifyTokenResultListener
{
fun
onTokenSuccess
(
result
:
String
?)
fun
onTokenFailed
(
result
:
TokenRet
)
}
fun
setVerifyTokenResultListener
(
listener
:
VerifyTokenResultListener
)
{
verifyTokenResultListener
=
listener
}
}
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