Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
android_street
Project
Project
Details
Activity
Releases
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
android
android_street
Commits
e2efe09d
Commit
e2efe09d
authored
Jul 29, 2021
by
mengcuiguang2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
微信登录重构
parent
d20322f8
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
284 additions
and
161 deletions
+284
-161
CsjGroMoreManager.kt
app/src/main/java/com/mints/street/ad/CsjGroMoreManager.kt
+1
-1
LoginViewModel.kt
app/src/main/java/com/mints/street/login/LoginViewModel.kt
+0
-2
MyFragment.kt
app/src/main/java/com/mints/street/main/my/MyFragment.kt
+47
-146
OpenvipActivity.kt
...src/main/java/com/mints/street/main/my/OpenvipActivity.kt
+23
-6
OpenvipViewModel.kt
...rc/main/java/com/mints/street/main/my/OpenvipViewModel.kt
+63
-4
SplashActivity.kt
app/src/main/java/com/mints/street/splash/SplashActivity.kt
+2
-2
WxLoginDialog.kt
...main/java/com/mints/street/widget/dialog/WxLoginDialog.kt
+148
-0
No files found.
app/src/main/java/com/mints/street/ad/CsjGroMoreManager.kt
View file @
e2efe09d
...
@@ -18,7 +18,7 @@ import java.util.*
...
@@ -18,7 +18,7 @@ import java.util.*
*/
*/
object
CsjGroMoreManager
{
object
CsjGroMoreManager
{
const
val
TT_AD_APPID
=
"
12345
"
const
val
TT_AD_APPID
=
"
5198591
"
private
var
sInit
:
Boolean
=
false
private
var
sInit
:
Boolean
=
false
...
...
app/src/main/java/com/mints/street/login/LoginViewModel.kt
View file @
e2efe09d
...
@@ -44,7 +44,6 @@ class LoginViewModel(application: Application) : BaseViewModel(application) {
...
@@ -44,7 +44,6 @@ class LoginViewModel(application: Application) : BaseViewModel(application) {
// KLog.e("sendMobileCode", response.result.toString())
// KLog.e("sendMobileCode", response.result.toString())
}
}
override
fun
onError
(
e
:
Throwable
)
{
override
fun
onError
(
e
:
Throwable
)
{
data
.
value
=
"失败"
KLog
.
e
(
"sendMobileCode"
,
"发送验证码错误"
)
KLog
.
e
(
"sendMobileCode"
,
"发送验证码错误"
)
}
}
})
})
...
@@ -79,7 +78,6 @@ class LoginViewModel(application: Application) : BaseViewModel(application) {
...
@@ -79,7 +78,6 @@ class LoginViewModel(application: Application) : BaseViewModel(application) {
}
}
override
fun
onError
(
e
:
Throwable
)
{
override
fun
onError
(
e
:
Throwable
)
{
data
.
value
=
"失败"
KLog
.
e
(
"LoginViewModel"
,
"登录错误"
)
KLog
.
e
(
"LoginViewModel"
,
"登录错误"
)
}
}
...
...
app/src/main/java/com/mints/street/main/my/MyFragment.kt
View file @
e2efe09d
This diff is collapsed.
Click to expand it.
app/src/main/java/com/mints/street/main/my/OpenvipActivity.kt
View file @
e2efe09d
...
@@ -22,8 +22,10 @@ import com.mints.street.bean.WxPayParamBean
...
@@ -22,8 +22,10 @@ import com.mints.street.bean.WxPayParamBean
import
com.mints.street.databinding.ActivityOpenvipBinding
import
com.mints.street.databinding.ActivityOpenvipBinding
import
com.mints.street.main.MainActivity
import
com.mints.street.main.MainActivity
import
com.mints.street.manager.UserManager
import
com.mints.street.manager.UserManager
import
com.mints.street.utils.json.JsonUtil
import
com.mints.street.widget.dialog.DialogListener
import
com.mints.street.widget.dialog.DialogListener
import
com.mints.street.widget.dialog.DialogUtils
import
com.mints.street.widget.dialog.DialogUtils
import
com.mints.street.widget.dialog.WxLoginDialog
import
kotlinx.android.synthetic.main.activity_openvip.*
import
kotlinx.android.synthetic.main.activity_openvip.*
import
kotlinx.android.synthetic.main.activity_openvip.bt_try
import
kotlinx.android.synthetic.main.activity_openvip.bt_try
import
kotlinx.android.synthetic.main.fragment_my.*
import
kotlinx.android.synthetic.main.fragment_my.*
...
@@ -42,6 +44,8 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
...
@@ -42,6 +44,8 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
private
var
vipList
:
MutableList
<
VipBean
.
ListBean
>?
=
null
private
var
vipList
:
MutableList
<
VipBean
.
ListBean
>?
=
null
private
var
currentPayType
=
""
private
var
currentPayType
=
""
private
val
loginDialog
by
lazy
{
WxLoginDialog
(
this
).
init
()
}
override
fun
initVariableId
()
=
BR
.
viewModel
override
fun
initVariableId
()
=
BR
.
viewModel
override
fun
initContentView
(
savedInstanceState
:
Bundle
?)
=
R
.
layout
.
activity_openvip
override
fun
initContentView
(
savedInstanceState
:
Bundle
?)
=
R
.
layout
.
activity_openvip
...
@@ -61,11 +65,24 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
...
@@ -61,11 +65,24 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
initListener
()
initListener
()
}
}
override
fun
onDestroy
()
{
super
.
onDestroy
()
loginDialog
.
setListener
(
null
)
loginDialog
.
onDestroy
()
}
private
fun
initListener
()
{
private
fun
initListener
()
{
iv_left_icon
.
setOnClickListener
(
this
)
iv_left_icon
.
setOnClickListener
(
this
)
bt_try
.
setOnClickListener
(
this
)
bt_try
.
setOnClickListener
(
this
)
ly_weixin
.
setOnClickListener
(
this
)
ly_weixin
.
setOnClickListener
(
this
)
ly_alipay
.
setOnClickListener
(
this
)
ly_alipay
.
setOnClickListener
(
this
)
loginDialog
.
setListener
(
object
:
WxLoginDialog
.
WxLoginListener
{
override
fun
loginSuc
(
wxInfo
:
String
)
{
viewModel
.
wechatlogin
(
JsonUtil
.
toJson
(
wxInfo
))
}
})
}
}
private
fun
initView
()
{
private
fun
initView
()
{
...
@@ -171,7 +188,6 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
...
@@ -171,7 +188,6 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
})
})
viewModel
.
isPaySuc
.
observe
(
this
,
Observer
<
Boolean
>
{
viewModel
.
isPaySuc
.
observe
(
this
,
Observer
<
Boolean
>
{
if
(
it
){
if
(
it
){
ToastUtils
.
showShort
(
"支付成功"
)
finish
()
finish
()
}
}
})
})
...
@@ -236,7 +252,7 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
...
@@ -236,7 +252,7 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
if
(
UserManager
.
INSTANCE
.
userIsLogin
())
{
if
(
UserManager
.
INSTANCE
.
userIsLogin
())
{
payVip
()
payVip
()
}
else
{
}
else
{
startActivity
(
OpenvipActivity
::
class
.
java
)
loginDialog
.
show
(
)
}
}
}
}
}
}
...
@@ -260,7 +276,11 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
...
@@ -260,7 +276,11 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
}
}
when
(
v
?.
id
)
{
when
(
v
?.
id
)
{
R
.
id
.
tv_payment
->
{
//继续支付
R
.
id
.
tv_payment
->
{
//继续支付
if
(
UserManager
.
INSTANCE
.
userIsLogin
())
{
payVip
()
payVip
()
}
else
{
loginDialog
.
show
()
}
}
}
R
.
id
.
tv_close
->
{
//取消
R
.
id
.
tv_close
->
{
//取消
finish
()
finish
()
...
@@ -320,9 +340,6 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
...
@@ -320,9 +340,6 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
com
.
blankj
.
utilcode
.
util
.
ToastUtils
.
showShort
(
"支付成功"
)
com
.
blankj
.
utilcode
.
util
.
ToastUtils
.
showShort
(
"支付成功"
)
finish
()
finish
()
}
}
// viewModel.queryVipOrder(wxParanBean.tid.toString())
com
.
blankj
.
utilcode
.
util
.
ToastUtils
.
showShort
(
"支付成功"
)
finish
()
})
{
throwable
->
})
{
throwable
->
ToastUtils
.
showShort
(
"支付异常,请联系管理员"
)
ToastUtils
.
showShort
(
"支付异常,请联系管理员"
)
}
}
...
...
app/src/main/java/com/mints/street/main/my/OpenvipViewModel.kt
View file @
e2efe09d
...
@@ -3,18 +3,26 @@ package com.mints.street.main.my
...
@@ -3,18 +3,26 @@ package com.mints.street.main.my
import
android.app.Application
import
android.app.Application
import
androidx.core.graphics.PathParser
import
androidx.core.graphics.PathParser
import
androidx.lifecycle.MutableLiveData
import
androidx.lifecycle.MutableLiveData
import
com.mints.street.bean.BaseResponse
import
com.blankj.utilcode.util.ToastUtils
import
com.mints.street.bean.PaymentBean
import
com.mints.street.bean.*
import
com.mints.street.bean.VipBean
import
com.mints.street.common.DeviceInfo
import
com.mints.street.bean.WxPayParamBean
import
com.mints.street.manager.UserManager
import
com.mints.street.manager.oaid.OaidManager
import
com.mints.street.model.ApiModel
import
com.mints.street.model.ApiModel
import
com.mints.street.netwrok.base.HttpSubscribeImpl
import
com.mints.street.netwrok.base.HttpSubscribeImpl
import
com.mints.street.utils.DeviceUuidFactory
import
me.goldze.mvvmhabit.base.BaseViewModel
import
me.goldze.mvvmhabit.base.BaseViewModel
import
me.goldze.mvvmhabit.utils.KLog
import
me.goldze.mvvmhabit.utils.KLog
import
java.util.HashMap
import
java.util.HashMap
class
OpenvipViewModel
(
application
:
Application
)
:
BaseViewModel
(
application
)
{
class
OpenvipViewModel
(
application
:
Application
)
:
BaseViewModel
(
application
)
{
val
deviceInfo
:
DeviceInfo
get
()
{
return
DeviceInfo
.
instance
}
val
Vipdata
:
MutableLiveData
<
VipBean
>
=
MutableLiveData
()
val
Vipdata
:
MutableLiveData
<
VipBean
>
=
MutableLiveData
()
val
Paymentdata
:
MutableLiveData
<
PaymentBean
>
=
MutableLiveData
()
val
Paymentdata
:
MutableLiveData
<
PaymentBean
>
=
MutableLiveData
()
val
vippayParams
:
MutableLiveData
<
WxPayParamBean
>
=
MutableLiveData
()
val
vippayParams
:
MutableLiveData
<
WxPayParamBean
>
=
MutableLiveData
()
...
@@ -102,4 +110,55 @@ class OpenvipViewModel(application: Application) : BaseViewModel(application) {
...
@@ -102,4 +110,55 @@ class OpenvipViewModel(application: Application) : BaseViewModel(application) {
}
}
)
)
}
}
fun
wechatlogin
(
wxInfo
:
String
)
{
val
vo
=
HashMap
<
String
,
Any
>()
vo
[
"wxInfo"
]
=
wxInfo
// vo["shumeiId"] = ShumeiManager.getInstance().shumeiDeviceId
vo
[
"device"
]
=
DeviceUuidFactory
().
deviceUuid
.
toString
()
ApiModel
.
wechatlogin
(
lifecycleProvider
,
vo
).
safeSubscribe
(
object
:
HttpSubscribeImpl
<
BaseResponse
<
UserBean
>>(
this
@OpenvipViewModel
,
true
)
{
override
fun
onBusinessSuccess
(
response
:
BaseResponse
<
UserBean
>)
{
//保存用户信息到Usermanager
UserManager
.
INSTANCE
.
saveUserInfo
(
response
.
result
)
this
@OpenvipViewModel
.
saveTerminalInfo
()
//提交设备信息
KLog
.
e
(
"wechatlogin"
,
"微信登录接口成功"
)
ToastUtils
.
showLong
(
"登录成功"
)
}
override
fun
onError
(
e
:
Throwable
)
{
super
.
onError
(
e
)
KLog
.
e
(
"wechatlogin"
,
"微信登录接口失败"
)
}
})
}
/**
* 提交设备信息
*/
fun
saveTerminalInfo
()
{
val
vo
=
hashMapOf
<
String
,
Any
>()
val
macAddress
:
String
=
deviceInfo
.
getMacAddress
()
val
mac
=
macAddress
.
replace
(
":"
,
""
)
vo
[
"mac"
]
=
mac
vo
[
"mac1"
]
=
macAddress
vo
[
"androidid"
]
=
deviceInfo
.
getAndroidId
(
null
)
vo
[
"imei"
]
=
deviceInfo
.
iMEI
vo
[
"oaid"
]
=
OaidManager
.
getOaid
()
vo
[
"os"
]
=
"android"
vo
[
"model"
]
=
deviceInfo
.
newModel
vo
[
"uuid"
]
=
DeviceUuidFactory
().
deviceUuid
vo
[
"osversion"
]
=
deviceInfo
.
oSVersion
vo
[
"appversion"
]
=
deviceInfo
.
versionName
ApiModel
.
saveTerminalInfo
(
lifecycleProvider
,
vo
).
safeSubscribe
(
object
:
HttpSubscribeImpl
<
BaseResponse
<
Any
>>(
this
@OpenvipViewModel
,
true
)
{
override
fun
onBusinessSuccess
(
response
:
BaseResponse
<
Any
>)
{
KLog
.
e
(
"saveTerminalInfo"
,
response
.
result
.
toString
())
}
})
}
}
}
app/src/main/java/com/mints/street/splash/SplashActivity.kt
View file @
e2efe09d
...
@@ -182,7 +182,7 @@ class SplashActivity : BaseActivity<ActivitySplashBinding, SplashViewModel>() {
...
@@ -182,7 +182,7 @@ class SplashActivity : BaseActivity<ActivitySplashBinding, SplashViewModel>() {
}
}
private
fun
showPowerDialog
()
{
private
fun
showPowerDialog
()
{
if
(
MMKV
.
mmkvWithID
(
Constant
.
LOAN_PERMISSION_FLAG
).
decodeBool
(
Constant
.
LOAN_PERMISSION_FLAG
,
fals
e
))
{
if
(
MMKV
.
mmkvWithID
(
Constant
.
LOAN_PERMISSION_FLAG
).
decodeBool
(
Constant
.
LOAN_PERMISSION_FLAG
,
tru
e
))
{
powerDialog
()
powerDialog
()
}
else
{
}
else
{
isClickAgree
=
true
isClickAgree
=
true
...
@@ -229,7 +229,7 @@ class SplashActivity : BaseActivity<ActivitySplashBinding, SplashViewModel>() {
...
@@ -229,7 +229,7 @@ class SplashActivity : BaseActivity<ActivitySplashBinding, SplashViewModel>() {
isClickAgree
=
true
isClickAgree
=
true
MMKV
.
mmkvWithID
(
Constant
.
LOAN_PERMISSION_FLAG
).
encode
(
Constant
.
LOAN_PERMISSION_FLAG
,
tru
e
)
MMKV
.
mmkvWithID
(
Constant
.
LOAN_PERMISSION_FLAG
).
encode
(
Constant
.
LOAN_PERMISSION_FLAG
,
fals
e
)
}
}
}
}
}
}
...
...
app/src/main/java/com/mints/street/widget/dialog/WxLoginDialog.kt
0 → 100644
View file @
e2efe09d
package
com.mints.street.widget.dialog
import
android.Manifest
import
android.content.Intent
import
android.graphics.Color
import
android.view.LayoutInflater
import
android.view.View
import
android.widget.CheckBox
import
android.widget.ImageView
import
android.widget.TextView
import
androidx.appcompat.widget.LinearLayoutCompat
import
androidx.fragment.app.FragmentActivity
import
cn.sharesdk.framework.ShareSDK
import
cn.sharesdk.wechat.friends.Wechat
import
com.google.android.material.bottomsheet.BottomSheetDialog
import
com.mints.street.R
import
com.mints.street.bean.WXInfo
import
com.mints.street.common.Constant
import
com.mints.street.login.LoginActivity
import
com.mints.street.login.LoginApi
import
com.mints.street.login.OnLoginListener
import
com.mints.street.utils.json.JsonUtil
import
com.mints.street.webview.MintsWebViewActivity
import
com.tbruyelle.rxpermissions2.RxPermissions
import
me.goldze.mvvmhabit.utils.RxUtils
import
me.goldze.mvvmhabit.utils.ToastUtils
import
java.util.*
/**
* 描述:微信登录
* 作者:孟崔广
* 时间:2021/7/29 10:51
*/
class
WxLoginDialog
(
context
:
FragmentActivity
)
:
OnLoginListener
{
var
wxLoginListener
:
WxLoginListener
?
=
null
private
var
mBottomSheetDialog
:
BottomSheetDialog
?
=
null
private
var
context
:
FragmentActivity
private
val
loginApi
by
lazy
{
LoginApi
()
}
init
{
this
.
context
=
context
}
/**
* 初始化
*/
fun
init
():
WxLoginDialog
{
//创建弹窗
if
(
mBottomSheetDialog
!=
null
)
return
this
mBottomSheetDialog
=
BottomSheetDialog
(
context
)
val
view1
:
View
=
LayoutInflater
.
from
(
context
).
inflate
(
R
.
layout
.
layout_popupwindow
,
null
)
mBottomSheetDialog
!!
.
setContentView
(
view1
)
mBottomSheetDialog
!!
.
window
!!
.
findViewById
<
View
>(
R
.
id
.
design_bottom_sheet
).
setBackgroundColor
(
Color
.
TRANSPARENT
)
val
iv_weixin
:
ImageView
=
view1
.
findViewById
(
R
.
id
.
iv_weixin
)
val
ly_phone
:
LinearLayoutCompat
=
view1
.
findViewById
(
R
.
id
.
ly_phone
)
val
cb_checked
:
CheckBox
=
view1
.
findViewById
(
R
.
id
.
cb_checked
)
val
tv_private
:
TextView
=
view1
.
findViewById
(
R
.
id
.
tv_private
)
val
tv_regist
:
TextView
=
view1
.
findViewById
(
R
.
id
.
tv_regist
)
tv_regist
.
setOnClickListener
{
MintsWebViewActivity
.
startWebView
(
name
=
"用户协议"
,
url
=
Constant
.
REGISTER_URL
)
}
tv_private
.
setOnClickListener
{
MintsWebViewActivity
.
startWebView
(
name
=
"隐私协议"
,
url
=
Constant
.
PRIVACY_URL
)
}
iv_weixin
.
setOnClickListener
{
if
(
cb_checked
!!
.
isChecked
)
{
val
wechat
=
ShareSDK
.
getPlatform
(
Wechat
.
NAME
)
if
(!
wechat
.
isClientValid
)
{
ToastUtils
.
showShort
(
"请先安装微信"
)
return
@setOnClickListener
}
RxPermissions
(
context
)
.
request
(
Manifest
.
permission
.
READ_PHONE_STATE
)
.
subscribe
{
granted
:
Boolean
->
if
(
granted
)
{
loginApi
.
setOnLoginListener
(
this
)
loginApi
.
setPlatform
(
Wechat
.
NAME
)
loginApi
.
login
(
context
)
}
else
{
// showMissingPermissionDialog("设备")
}
}
mBottomSheetDialog
!!
.
dismiss
()
}
else
{
ToastUtils
.
showShort
(
"请先同意用户协议与隐私政策"
)
}
}
RxUtils
.
onMultiClick
(
ly_phone
)
{
if
(
cb_checked
!!
.
isChecked
)
{
context
.
startActivity
(
Intent
(
context
,
LoginActivity
::
class
.
java
))
mBottomSheetDialog
!!
.
dismiss
()
}
else
{
ToastUtils
.
showShort
(
"请先同意用户协议与隐私政策"
)
}
}
return
this
}
/**
* 展示
*/
fun
show
(){
mBottomSheetDialog
?.
show
()
}
override
fun
onLogin
(
platform
:
String
?,
res
:
HashMap
<
String
,
Any
>?):
Boolean
{
try
{
val
wxInfo
=
WXInfo
()
wxInfo
?.
let
{
it
.
unionid
=
res
?.
get
(
"unionid"
).
toString
()
+
""
it
.
openid
=
res
?.
get
(
"openid"
).
toString
()
+
""
it
.
province
=
res
?.
get
(
"province"
).
toString
()
+
""
it
.
city
=
res
?.
get
(
"city"
).
toString
()
+
""
it
.
country
=
res
?.
get
(
"country"
).
toString
()
+
""
it
.
headimgurl
=
res
?.
get
(
"headimgurl"
).
toString
()
+
""
it
.
nickname
=
res
?.
get
(
"nickname"
).
toString
()
+
""
it
.
sex
=
(
res
?.
get
(
"sex"
).
toString
()
+
""
).
toInt
()
}
// if (!isHidden) {//当前fragment正在显示调用微信登陆接口
// viewModel.wechatlogin(JsonUtil.toJson(wxInfo))
// }
wxLoginListener
?.
loginSuc
(
JsonUtil
.
toJson
(
wxInfo
))
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
return
false
}
fun
onDestroy
(){
loginApi
.
setOnLoginListener
(
null
)
mBottomSheetDialog
=
null
}
fun
setListener
(
listener
:
WxLoginListener
?)
{
wxLoginListener
=
listener
}
interface
WxLoginListener
{
fun
loginSuc
(
wxInfo
:
String
)
}
}
\ No newline at end of file
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