Commit 0448737f authored by mengcuiguang2's avatar mengcuiguang2

代码优化

parent 889ed912
......@@ -40,6 +40,7 @@ import com.jobo.wxpay.WXPay
import com.jobo.wxpay.WXPayInfoImpl
import com.youth.banner.listener.OnPageChangeListener
import kotlinx.android.synthetic.main.activity_new_vip.*
import java.net.URLEncoder
/**
......@@ -48,8 +49,8 @@ import kotlinx.android.synthetic.main.activity_new_vip.*
* 时间:2022/12/22 14:48
*/
class VipActivity : BaseActivity(), VipView, View.OnClickListener,
VipAdapter.OnItemClickListener,
CompoundButton.OnCheckedChangeListener {
VipAdapter.OnItemClickListener,
CompoundButton.OnCheckedChangeListener {
companion object {
const val IS_DETAIL = "IS_DETAIL"//是否从剧集详情页进入
......@@ -226,6 +227,21 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
return
}
// 自动签约付费
try {
if (paramsBean.params.isSign) {
AppConfig.enterAlipay = true
openAutoAlipay(paramsBean.params.params)
return
}
} catch (e: Exception) {
e.printStackTrace()
}
//支付宝小程序
// openAlipayApp()
// sdk支付
alipay(paramsBean)
}
}
......@@ -262,7 +278,7 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
if (data.expireTime > 0) {
readyGo(MainActivity::class.java)
val activity =
ActivityPageManager.getInstance().getActivity(MainActivity::class.java)
ActivityPageManager.getInstance().getActivity(MainActivity::class.java)
if (activity != null && activity is MainActivity) {
activity.clickTab4Layout()
}
......@@ -279,7 +295,7 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
when (keyCode) {
KeyEvent.KEYCODE_BACK -> {
if (UserManager.getInstance().newFlag
&& vipList != null && vipList!!.size > 0
&& vipList != null && vipList!!.size > 0
) {
vipAdapter.setPosition(0)
......@@ -308,7 +324,7 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
when (v?.id) {
R.id.ic_vip_quit -> {
if (UserManager.getInstance().newFlag &&
vipList != null && vipList!!.size > 0
vipList != null && vipList!!.size > 0
) {
vipAdapter.setPosition(0)
vipAdapter.notifyDataSetChanged()
......@@ -339,13 +355,13 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
} else {
if (TextUtils.equals(payType, WEIXIN_PAY)) {
vipPresenter.getVipPayParams(
"WEIXIN",
vipBean.pid, isAliPayInstalled()
"WEIXIN",
vipBean.pid, isAliPayInstalled()
)
} else if (TextUtils.equals(payType, ALIPAY)) {
vipPresenter.getVipPayParams(
"ALIPAY",
vipBean.pid, isAliPayInstalled()
"ALIPAY",
vipBean.pid, isAliPayInstalled()
)
}
}
......@@ -386,7 +402,7 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
shimmer_text?.postDelayed({
shimmer_text?.startShimmerAnimation()
breathAnim =
YoYo.with(Techniques.Pulse).duration(700).repeat(-1).playOn(shimmer_text)
YoYo.with(Techniques.Pulse).duration(700).repeat(-1).playOn(shimmer_text)
}, 200)
ic_vip_quit.setOnClickListener(this)
......@@ -442,18 +458,6 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
}
fun alipay(wxParanBean: WxPayParamBean) {
try {
// 自动签约付费
if (wxParanBean.params.isSign) {
AppConfig.enterAlipay = true
openAutoAlipay(wxParanBean.params.params)
return
}
} catch (e: Exception) {
e.printStackTrace()
}
//实例化支付宝支付策略
val aliPay = AliPay()
//构造支付宝订单实体。一般都是由服务端直接返回。
......@@ -478,22 +482,22 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
vipPresenter.queryVipOrder(wxParanBean.tid.toString(), false)
mainHandler.postDelayed(
{
if (isFinishing) return@postDelayed
{
if (isFinishing) return@postDelayed
// 挽留弹窗存在也不弹
if (payYesDialog != null && payYesDialog!!.isShowing) return@postDelayed
// 挽留弹窗存在也不弹
if (payYesDialog != null && payYesDialog!!.isShowing) return@postDelayed
if (vipList != null && vipList!!.size > 0) {
val vipBean = vipList!![vipAdapter.getPosition()]
// 0.01
if (vipBean.trial != 0) {
showPayCancelDialog()
if (vipList != null && vipList!!.size > 0) {
val vipBean = vipList!![vipAdapter.getPosition()]
// 0.01
if (vipBean.trial != 0) {
showPayCancelDialog()
}
}
}
},
2000
},
2000
)
}
})
......@@ -549,13 +553,13 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
val vipBean = vipList!![vipAdapter.getPosition()]
if (TextUtils.equals(payType, WEIXIN_PAY)) {
vipPresenter.getVipPayParams(
"WEIXIN",
vipBean.pid, isAliPayInstalled()
"WEIXIN",
vipBean.pid, isAliPayInstalled()
)
} else if (TextUtils.equals(payType, ALIPAY)) {
vipPresenter.getVipPayParams(
"ALIPAY",
vipBean.pid, isAliPayInstalled()
"ALIPAY",
vipBean.pid, isAliPayInstalled()
)
}
} else {
......@@ -602,13 +606,13 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
R.id.tv_agreement_next -> {
if (TextUtils.equals(payType, WEIXIN_PAY)) {
vipPresenter.getVipPayParams(
"WEIXIN",
vipBean.pid, isAliPayInstalled()
"WEIXIN",
vipBean.pid, isAliPayInstalled()
)
} else if (TextUtils.equals(payType, ALIPAY)) {
vipPresenter.getVipPayParams(
"ALIPAY",
vipBean.pid, isAliPayInstalled()
"ALIPAY",
vipBean.pid, isAliPayInstalled()
)
}
......@@ -617,10 +621,10 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
}
})
ruleAgreementDialog!!.setText(
vipBean.remarks,
vipBean.trialFirstDay,
vipBean.price,
vipBean.title
vipBean.remarks,
vipBean.trialFirstDay,
vipBean.price,
vipBean.title
)
ruleAgreementDialog!!.show()
} else {
......@@ -651,13 +655,13 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
} else {
if (TextUtils.equals(payType, WEIXIN_PAY)) {
vipPresenter.getVipPayParams(
"WEIXIN",
vipBean.pid, isAliPayInstalled()
"WEIXIN",
vipBean.pid, isAliPayInstalled()
)
} else if (TextUtils.equals(payType, ALIPAY)) {
vipPresenter.getVipPayParams(
"ALIPAY",
vipBean.pid, isAliPayInstalled()
"ALIPAY",
vipBean.pid, isAliPayInstalled()
)
}
}
......@@ -680,7 +684,7 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
private fun setBanner(data: List<VedioBean>) {
mainHandler.postDelayed({
val scrollToBottomAnimator =
ValueAnimator.ofInt(0, nsv.getChildAt(0).height - nsv.height)
ValueAnimator.ofInt(0, nsv.getChildAt(0).height - nsv.height)
scrollToBottomAnimator.addUpdateListener { animator ->
val value = animator.animatedValue as Int
nsv.scrollTo(0, value)
......@@ -702,23 +706,23 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
val adapter = VipBannerAdapter(data)
// 绑定生命周期
vip_banner.addBannerLifecycleObserver(this)
.setBannerGalleryEffect(80, 15, 0.8f)
.setAdapter(adapter)
.addOnPageChangeListener(object : OnPageChangeListener {
override fun onPageScrolled(
position: Int,
positionOffset: Float,
positionOffsetPixels: Int
) {
}
.setBannerGalleryEffect(80, 15, 0.8f)
.setAdapter(adapter)
.addOnPageChangeListener(object : OnPageChangeListener {
override fun onPageScrolled(
position: Int,
positionOffset: Float,
positionOffsetPixels: Int
) {
}
override fun onPageSelected(position: Int) {
GlideUtils.loadBlurImageView(mContext, data[position].coverImage, iv_blur)
tv_banner_title.text = String.format("《%1s》", data[position].title)
}
override fun onPageSelected(position: Int) {
GlideUtils.loadBlurImageView(mContext, data[position].coverImage, iv_blur)
tv_banner_title.text = String.format("《%1s》", data[position].title)
}
override fun onPageScrollStateChanged(state: Int) {}
})
override fun onPageScrollStateChanged(state: Int) {}
})
GlideUtils.loadBlurImageView(mContext, data[0].coverImage, iv_blur)
tv_banner_title.text = String.format("《%1s》", data[0].title)
}
......@@ -732,12 +736,12 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
vipPresenter.getVipPayParams(
"ALIPAY",
vipBean.pid, isAliPayInstalled()
"ALIPAY",
vipBean.pid, isAliPayInstalled()
)
}
})
.show()
.show()
}
fun startTimer() {
......@@ -764,4 +768,23 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
})
timer!!.start()
}
/**
* 跳转支付宝小程序
*/
private fun openAlipayApp() {
try {
val alipayAppId = "2021004145639480"
val path = "app_uid=" + UserManager.getInstance().userID//这里是传的参数
val link = URLEncoder.encode(path, "UTF-8")//这里是encode传的参数
val url =
// "alipays://platformapi/startapp?appId=2021004129666486&page=pages/loading&query=" + link
"alipays://platformapi/startapp?appId=" + alipayAppId + "&page=pages/loading&query=" + link
val uri = Uri.parse(url) // url为你要链接的地址
val intent = Intent(Intent.ACTION_VIEW, uri)
startActivity(intent)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment