Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
android_fiveworld
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_fiveworld
Commits
e83b209b
Commit
e83b209b
authored
Jul 19, 2021
by
mengcuiguang2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加微信,支付宝支付功能
parent
53ec835e
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
360 additions
and
25 deletions
+360
-25
MainApi.kt
app/src/main/java/com/mints/street/api/MainApi.kt
+12
-0
MyFragment.kt
app/src/main/java/com/mints/street/main/my/MyFragment.kt
+7
-11
OpenvipActivity.kt
...src/main/java/com/mints/street/main/my/OpenvipActivity.kt
+42
-11
OpenvipViewModel.kt
...rc/main/java/com/mints/street/main/my/OpenvipViewModel.kt
+41
-0
ApiModel.kt
app/src/main/java/com/mints/street/model/ApiModel.kt
+16
-0
BrowserLayout.kt
app/src/main/java/com/mints/street/widget/BrowserLayout.kt
+175
-0
progress_bar_horizontal.xml
app/src/main/res/drawable/progress_bar_horizontal.xml
+17
-0
activity_mints_web_view.xml
app/src/main/res/layout/activity_mints_web_view.xml
+2
-3
progress_horizontal.xml
app/src/main/res/layout/progress_horizontal.xml
+25
-0
drawables.xml
app/src/main/res/values/drawables.xml
+23
-0
No files found.
app/src/main/java/com/mints/street/api/MainApi.kt
View file @
e83b209b
...
...
@@ -51,6 +51,18 @@ interface MainApi {
@POST
(
"api/getPayChannels"
)
fun
getPayChannels
(
@Body
vo
:
@JvmSuppressWildcards
Map
<
String
,
Any
>):
Observable
<
Response
<
BaseResponse
<
PaymentBean
>>>
/**
* 获取支付参数
*/
@POST
(
"api/trade/getVipPayParams"
)
fun
getVipPayParams
(
@Body
vo
:
@JvmSuppressWildcards
Map
<
String
,
Any
>):
Observable
<
Response
<
BaseResponse
<
WxPayParamBean
>>>
/**
* 支付成功
*/
@POST
(
"api/trade/queryVipOrder"
)
fun
queryVipOrder
(
@Body
vo
:
@JvmSuppressWildcards
Map
<
String
,
Any
>):
Observable
<
Response
<
BaseResponse
<
Any
>>>
/**
* 获取用户登录信息
*/
...
...
app/src/main/java/com/mints/street/main/my/MyFragment.kt
View file @
e83b209b
...
...
@@ -78,17 +78,13 @@ class MyFragment : BaseFragment<FragmentMyBinding, MyViewModel>(), OnRefreshList
override
fun
onResume
()
{
super
.
onResume
()
//查询用户登录信息
viewModel
.
getmyInfo
()
setUserLoginStatus
()
//
// if (userManager.userIsLogin()) {
// //查询用户登录信息
// viewModel.getmyInfo()
// } else {
// //重新显示界面信息
// setUserLoginStatus()
// }
if
(
userManager
.
userIsLogin
())
{
//查询用户登录信息
viewModel
.
getmyInfo
()
}
else
{
//重新显示界面信息
setUserLoginStatus
()
}
}
private
fun
initListener
()
{
...
...
app/src/main/java/com/mints/street/main/my/OpenvipActivity.kt
View file @
e83b209b
...
...
@@ -28,15 +28,19 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
private
var
mAdapter
:
DelegateAdapter
?
=
null
private
var
vipList
:
MutableList
<
VipBean
.
ListBean
>?
=
null
private
var
currentPayType
=
""
override
fun
initVariableId
()
=
BR
.
viewModel
override
fun
initContentView
(
savedInstanceState
:
Bundle
?)
=
R
.
layout
.
activity_openvip
override
fun
initData
()
{
super
.
initData
()
//获取vip福利信息
viewModel
.
openvipInfo
()
//获取支付方式
viewModel
.
getpaymentwey
(
"android"
)
if
(!
TextUtils
.
isEmpty
(
UserManager
.
INSTANCE
.
getUserID
())){
//获取vip福利信息
viewModel
.
openvipInfo
()
//获取支付方式
viewModel
.
getpaymentwey
(
"android"
)
}
initView
()
initListener
()
}
...
...
@@ -86,6 +90,27 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
vipList
=
it
.
list
as
MutableList
<
VipBean
.
ListBean
>?
mAdapter
?.
addAdapter
(
GridPaymentAdapter
(
this
,
it
.
list
!!
))
})
viewModel
.
vippayParams
.
observe
(
this
,
Observer
<
WxPayParamBean
>
{
if
(
TextUtils
.
equals
(
currentPayType
,
"WEIXIN"
))
{
if
(
it
==
null
||
it
.
params
==
null
)
{
ToastUtils
.
showShort
(
"微信支付维护中"
)
return
@Observer
}
wxPay
(
it
)
}
else
{
if
(
it
==
null
||
it
.
params
==
null
)
{
ToastUtils
.
showShort
(
"支付宝支付维护中"
)
return
@Observer
}
alipay
(
it
)
}
})
viewModel
.
isPaySuc
.
observe
(
this
,
Observer
<
Boolean
>
{
if
(
it
){
ToastUtils
.
showShort
(
"支付成功"
)
finish
()
}
})
viewModel
.
Paymentdata
.
observe
(
this
,
Observer
<
PaymentBean
>
{
if
(
it
.
list
.
isNullOrEmpty
())
{
return
@Observer
...
...
@@ -93,9 +118,13 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
for
(
str
in
it
.
list
!!
)
{
if
(
str
.
equals
(
"WEIXIN"
))
{
ly_weixin
.
visibility
=
View
.
VISIBLE
currentPayType
=
"WEIXIN"
}
if
(
str
.
equals
(
"ALIPAY"
))
{
ly_alipay
.
visibility
=
View
.
VISIBLE
if
(
TextUtils
.
isEmpty
(
currentPayType
)){
currentPayType
=
"ALIPAY"
}
}
}
}
...
...
@@ -110,18 +139,20 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
R
.
id
.
ly_weixin
->{
//支付宝支付
//设置选中样式
setOnChecked
(
1
)
currentPayType
=
"WEIXIN"
}
R
.
id
.
ly_alipay
->{
//支付宝支付
//设置选中样式
setOnChecked
(
2
)
currentPayType
=
"ALIPAY"
}
R
.
id
.
bt_try
->
{
if
(
vipList
!=
null
&&
vipList
!!
.
size
>
0
)
{
// if (TextUtils.equals("weixin", payDialog?.payChannel
)) {
// vipPresenter?.getVipPayParams("WEIXIN", vipList!![vipAdapter?.getPosition()
].pid)
//
} else {
// vipPresenter?.getVipPayParams("ALIPAY", vipList!![vipAdapter?.getPosition()
].pid)
//
}
if
(
TextUtils
.
equals
(
"WEIXIN"
,
currentPayType
))
{
viewModel
.
getVipPayParams
(
"WEIXIN"
,
vipList
!!
[
0
].
pid
)
}
else
{
viewModel
.
getVipPayParams
(
"ALIPAY"
,
vipList
!!
[
1
].
pid
)
}
}
}
}
...
...
@@ -155,7 +186,7 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
//支付成功
UserManager
.
INSTANCE
.
setVipFlag
(
true
)
}
// vipPresenter?.queryVipOrder(wxParanBean.tid.toString(), isPay
)
viewModel
.
queryVipOrder
(
wxParanBean
.
tid
.
toString
()
)
})
{
throwable
->
ToastUtils
.
showShort
(
"支付异常,请联系管理员"
)
}
...
...
@@ -168,7 +199,7 @@ class OpenvipActivity : BaseActivity<ActivityOpenvipBinding, OpenvipViewModel>()
//支付成功
UserManager
.
INSTANCE
.
setVipFlag
(
true
)
}
// vipPresenter?.queryVipOrder(wxParanBean.tid.toString(), isPay
)
viewModel
.
queryVipOrder
(
wxParanBean
.
tid
.
toString
()
)
})
{
throwable
->
ToastUtils
.
showShort
(
"支付异常,请联系管理员"
)
}
...
...
app/src/main/java/com/mints/street/main/my/OpenvipViewModel.kt
View file @
e83b209b
...
...
@@ -6,6 +6,7 @@ import androidx.lifecycle.MutableLiveData
import
com.mints.street.bean.BaseResponse
import
com.mints.street.bean.PaymentBean
import
com.mints.street.bean.VipBean
import
com.mints.street.bean.WxPayParamBean
import
com.mints.street.model.ApiModel
import
com.mints.street.netwrok.base.HttpSubscribeImpl
import
me.goldze.mvvmhabit.base.BaseViewModel
...
...
@@ -16,6 +17,8 @@ class OpenvipViewModel(application: Application) : BaseViewModel(application) {
val
Vipdata
:
MutableLiveData
<
VipBean
>
=
MutableLiveData
()
val
Paymentdata
:
MutableLiveData
<
PaymentBean
>
=
MutableLiveData
()
val
vippayParams
:
MutableLiveData
<
WxPayParamBean
>
=
MutableLiveData
()
val
isPaySuc
:
MutableLiveData
<
Boolean
>
=
MutableLiveData
()
/**
* 开通Vip
...
...
@@ -61,4 +64,42 @@ class OpenvipViewModel(application: Application) : BaseViewModel(application) {
)
}
/**
* 获取支付参数
*/
fun
getVipPayParams
(
payChannel
:
String
,
pid
:
String
)
{
val
vo
=
HashMap
<
String
,
Any
>()
vo
[
"payChannel"
]
=
payChannel
vo
[
"pid"
]
=
pid
ApiModel
.
getVipPayParams
(
lifecycleProvider
,
vo
).
safeSubscribe
(
object
:
HttpSubscribeImpl
<
BaseResponse
<
WxPayParamBean
>>(
this
@OpenvipViewModel
,
true
)
{
override
fun
onBusinessSuccess
(
response
:
BaseResponse
<
WxPayParamBean
>)
{
vippayParams
.
value
=
response
.
result
}
override
fun
onError
(
e
:
Throwable
)
{
}
}
)
}
/**
* 支付成功
*/
fun
queryVipOrder
(
tid
:
String
)
{
val
vo
=
HashMap
<
String
,
Any
>()
vo
[
"tid"
]
=
tid
ApiModel
.
queryVipOrder
(
lifecycleProvider
,
vo
).
safeSubscribe
(
object
:
HttpSubscribeImpl
<
BaseResponse
<
Any
>>(
this
@OpenvipViewModel
,
true
)
{
override
fun
onBusinessSuccess
(
response
:
BaseResponse
<
Any
>)
{
isPaySuc
.
value
=
true
}
override
fun
onError
(
e
:
Throwable
)
{
}
}
)
}
}
app/src/main/java/com/mints/street/model/ApiModel.kt
View file @
e83b209b
...
...
@@ -54,6 +54,22 @@ object ApiModel {
.
execute
(
lifecycleProvider
,
MainApi
.
newInstance
().
getPayChannels
(
map
))
}
/**
* 获取支付参数
*/
fun
getVipPayParams
(
lifecycleProvider
:
LifecycleProvider
<
Any
>?,
map
:
Map
<
String
,
Any
>):
Observable
<
Response
<
BaseResponse
<
WxPayParamBean
>>>
{
return
HttpManager
.
getInstance
()
.
execute
(
lifecycleProvider
,
MainApi
.
newInstance
().
getVipPayParams
(
map
))
}
/**
* 支付成功
*/
fun
queryVipOrder
(
lifecycleProvider
:
LifecycleProvider
<
Any
>?,
map
:
Map
<
String
,
Any
>):
Observable
<
Response
<
BaseResponse
<
Any
>>>
{
return
HttpManager
.
getInstance
()
.
execute
(
lifecycleProvider
,
MainApi
.
newInstance
().
queryVipOrder
(
map
))
}
/**
* 获取用户登录信息
*/
...
...
app/src/main/java/com/mints/street/widget/BrowserLayout.kt
0 → 100644
View file @
e83b209b
package
com.mints.street.widget
import
android.content.Context
import
android.content.Intent
import
android.net.Uri
import
android.os.Build
import
android.util.AttributeSet
import
android.util.TypedValue
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.webkit.WebChromeClient
import
android.webkit.WebSettings
import
android.webkit.WebView
import
android.webkit.WebViewClient
import
android.widget.LinearLayout
import
android.widget.ProgressBar
import
android.widget.TextView
import
com.mints.street.R
class
BrowserLayout
:
LinearLayout
{
private
var
mContext
:
Context
?
=
null
private
var
mWebView
:
WebView
?
=
null
private
var
mWebTitle
:
TextView
?
=
null
private
val
mBarHeight
=
5
private
var
mProgressBar
:
ProgressBar
?
=
null
constructor
(
context
:
Context
)
:
super
(
context
)
{
init
(
context
)
}
constructor
(
context
:
Context
,
attrs
:
AttributeSet
?
)
:
super
(
context
,
attrs
)
{
init
(
context
)
}
private
fun
init
(
context
:
Context
)
{
mContext
=
context
orientation
=
VERTICAL
mProgressBar
=
LayoutInflater
.
from
(
context
)
.
inflate
(
R
.
layout
.
progress_horizontal
,
null
)
as
ProgressBar
mProgressBar
!!
.
max
=
100
mProgressBar
!!
.
progress
=
0
addView
(
mProgressBar
,
LayoutParams
.
MATCH_PARENT
,
TypedValue
.
applyDimension
(
TypedValue
.
COMPLEX_UNIT_PX
,
mBarHeight
.
toFloat
(),
resources
.
displayMetrics
).
toInt
()
)
mWebView
=
WebView
(
context
)
mWebView
!!
.
settings
.
javaScriptEnabled
=
true
mWebView
!!
.
scrollBarStyle
=
View
.
SCROLLBARS_INSIDE_OVERLAY
mWebView
!!
.
settings
.
defaultTextEncodingName
=
"UTF-8"
mWebView
!!
.
settings
.
cacheMode
=
WebSettings
.
LOAD_NO_CACHE
mWebView
!!
.
settings
.
builtInZoomControls
=
true
mWebView
!!
.
settings
.
setSupportMultipleWindows
(
true
)
//将图片调整到适合webview的大小
mWebView
!!
.
settings
.
useWideViewPort
=
false
mWebView
!!
.
settings
.
loadWithOverviewMode
=
true
mWebView
!!
.
settings
.
setSupportZoom
(
true
)
mWebView
!!
.
settings
.
pluginState
=
WebSettings
.
PluginState
.
ON
mWebView
!!
.
settings
.
domStorageEnabled
=
true
mWebView
!!
.
settings
.
loadsImagesAutomatically
=
true
mWebView
!!
.
settings
.
displayZoomControls
=
false
// 支持打开新窗口
mWebView
!!
.
settings
.
javaScriptCanOpenWindowsAutomatically
=
true
try
{
mWebView
!!
.
setLayerType
(
View
.
LAYER_TYPE_NONE
,
null
)
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
//支持自动加载图片
mWebView
!!
.
settings
.
loadsImagesAutomatically
=
true
//解决5.0后https地址中图片不显示的问题(图片地址为http)
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
mWebView
!!
.
settings
.
mixedContentMode
=
WebSettings
.
MIXED_CONTENT_ALWAYS_ALLOW
}
//允许webview对文件的操作
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
JELLY_BEAN
)
{
mWebView
!!
.
settings
.
allowUniversalAccessFromFileURLs
=
true
mWebView
!!
.
settings
.
allowFileAccessFromFileURLs
=
true
}
mWebView
!!
.
settings
.
allowFileAccess
=
true
val
lps
=
LayoutParams
(
LayoutParams
.
MATCH_PARENT
,
0
,
1f
)
addView
(
mWebView
,
lps
)
mWebView
!!
.
setWebChromeClient
(
object
:
WebChromeClient
()
{
override
fun
onReceivedTitle
(
view
:
WebView
,
title
:
String
)
{
super
.
onReceivedTitle
(
view
,
title
)
if
(
mWebTitle
!=
null
)
{
mWebTitle
!!
.
text
=
title
}
}
override
fun
onProgressChanged
(
view
:
WebView
,
newProgress
:
Int
)
{
super
.
onProgressChanged
(
view
,
newProgress
)
if
(
newProgress
==
100
)
{
mProgressBar
!!
.
visibility
=
View
.
GONE
}
else
{
mProgressBar
!!
.
visibility
=
View
.
VISIBLE
mProgressBar
!!
.
progress
=
newProgress
}
}
})
mWebView
!!
.
webViewClient
=
object
:
WebViewClient
()
{
override
fun
shouldOverrideUrlLoading
(
view
:
WebView
,
url
:
String
):
Boolean
{
if
(
url
.
startsWith
(
"tel:"
))
{
try
{
val
intent
=
Intent
(
Intent
.
ACTION_DIAL
,
Uri
.
parse
(
url
))
intent
.
flags
=
Intent
.
FLAG_ACTIVITY_NEW_TASK
mContext
!!
.
startActivity
(
intent
)
}
catch
(
e
:
Exception
)
{
}
return
true
}
return
super
.
shouldOverrideUrlLoading
(
view
,
url
)
}
override
fun
onPageFinished
(
view
:
WebView
,
url
:
String
)
{
super
.
onPageFinished
(
view
,
url
)
}
}
}
fun
loadUrl
(
url
:
String
?)
{
mWebView
!!
.
loadUrl
(
url
!!
)
}
fun
canGoBack
():
Boolean
{
return
if
(
null
!=
mWebView
)
mWebView
!!
.
canGoBack
()
else
false
}
fun
canGoForward
():
Boolean
{
return
if
(
null
!=
mWebView
)
mWebView
!!
.
canGoForward
()
else
false
}
fun
goBack
()
{
if
(
null
!=
mWebView
)
{
mWebView
!!
.
goBack
()
}
}
fun
goForward
()
{
if
(
null
!=
mWebView
)
{
mWebView
!!
.
goForward
()
}
}
val
webView
:
WebView
?
get
()
=
if
(
mWebView
!=
null
)
mWebView
else
null
fun
setWebTitle
(
mWebTitle
:
TextView
?)
{
this
.
mWebTitle
=
mWebTitle
}
fun
clearWebView
()
{
if
(
mWebView
!=
null
)
{
val
parent
=
mWebView
!!
.
parent
as
ViewGroup
parent
?.
removeView
(
mWebView
)
mWebView
!!
.
removeAllViews
()
mWebView
!!
.
destroy
()
mWebView
=
null
}
}
}
\ No newline at end of file
app/src/main/res/drawable/progress_bar_horizontal.xml
0 → 100644
View file @
e83b209b
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<item
android:id=
"@android:id/background"
android:drawable=
"@drawable/progress_bar_bg"
/>
<item
android:id=
"@android:id/progress"
>
<clip>
<shape>
<solid
android:color=
"#3D5AFE"
/>
</shape>
</clip>
</item>
</layer-list>
\ No newline at end of file
app/src/main/res/layout/activity_mints_web_view.xml
View file @
e83b209b
...
...
@@ -16,11 +16,10 @@
android:layout_height=
"wrap_content"
app:ctb_theme=
"dark"
app:layout_constraintTop_toTopOf=
"parent"
/>
<WebView
android:id=
"@+id/webview"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
android:layout_height=
"match_parent"
/>
</LinearLayout>
</layout>
\ No newline at end of file
app/src/main/res/layout/progress_horizontal.xml
0 → 100644
View file @
e83b209b
<!--
~ Copyright (c) 2015 [1076559197@qq.com | tchen0707@gmail.com]
~
~ Licensed under the Apache License, Version 2.0 (the "License”);
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<ProgressBar
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id=
"@+id/my_profile_tracker"
style=
"?android:attr/progressBarStyleHorizontal"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:background=
"@null"
android:max=
"60"
android:indeterminateOnly=
"false"
android:progressDrawable=
"@drawable/progress_bar_horizontal"
/>
app/src/main/res/values/drawables.xml
0 → 100644
View file @
e83b209b
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2015 [1076559197@qq.com | tchen0707@gmail.com]
~
~ Licensed under the Apache License, Version 2.0 (the "License”);
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<resources>
<drawable
name=
"progress_bar_bg"
>
#00000000
</drawable>
<drawable
name=
"sr_primary"
>
#2B3238
</drawable>
<drawable
name=
"sr_primary_r"
>
#002444
</drawable>
</resources>
\ 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