Commit e853fb0e authored by mengcuiguang's avatar mengcuiguang

代码优化

parent 8175cb30
...@@ -35,6 +35,13 @@ public class VipBean implements Serializable { ...@@ -35,6 +35,13 @@ public class VipBean implements Serializable {
private String buttonText; private String buttonText;
private int payToModel;//0 app内部,1.只签约转支付宝浏览器支付 2.带uid转支付宝小程序(暂定只有一个小程序) private int payToModel;//0 app内部,1.只签约转支付宝浏览器支付 2.带uid转支付宝小程序(暂定只有一个小程序)
//带uid转支付宝小程序 第一个小程序
private String payToModel2FirstAlipayAppid;
//带uid转支付宝小程序 挽留用的第二个小程序
private String payToModel2SecondAlipayAppid;
public String getButtonText() { public String getButtonText() {
return buttonText; return buttonText;
} }
...@@ -122,5 +129,13 @@ public class VipBean implements Serializable { ...@@ -122,5 +129,13 @@ public class VipBean implements Serializable {
public void setPayToModel(int payToModel) { public void setPayToModel(int payToModel) {
this.payToModel = payToModel; this.payToModel = payToModel;
} }
public String getPayToModel2FirstAlipayAppid() {
return payToModel2FirstAlipayAppid;
}
public String getPayToModel2SecondAlipayAppid() {
return payToModel2SecondAlipayAppid;
}
} }
} }
...@@ -182,7 +182,7 @@ class VipPresenter : BasePresenter<VipView>() { ...@@ -182,7 +182,7 @@ class VipPresenter : BasePresenter<VipView>() {
}) })
} }
fun getVipPayParams(payChannel: String, pid: String, isInstallAlipay: Boolean) { fun getVipPayParams(payChannel: String, pid: String, isInstallAlipay: Boolean,enter:String) {
val vo = HashMap<String, Any>() val vo = HashMap<String, Any>()
// vo["payChannel"] = payChannel // vo["payChannel"] = payChannel
vo["payChannel"] = "ALIPAY" vo["payChannel"] = "ALIPAY"
...@@ -207,7 +207,7 @@ class VipPresenter : BasePresenter<VipView>() { ...@@ -207,7 +207,7 @@ class VipPresenter : BasePresenter<VipView>() {
val code: Int = baseResponse.getStatus() val code: Int = baseResponse.getStatus()
when (code) { when (code) {
200 -> { 200 -> {
view.getVipPayParamsSuc("ALIPAY", baseResponse.data) view.getVipPayParamsSuc("ALIPAY", baseResponse.data,enter)
} }
else -> { else -> {
view.showToast(baseResponse.getMessage()) view.showToast(baseResponse.getMessage())
......
...@@ -7,7 +7,7 @@ import com.duben.speedplayletu.mvp.model.WxPayParamBean ...@@ -7,7 +7,7 @@ import com.duben.speedplayletu.mvp.model.WxPayParamBean
interface VipView : BaseView { interface VipView : BaseView {
fun getVipProductSuc(data: VipBean) fun getVipProductSuc(data: VipBean)
fun getVipPayParamsSuc(payChannel:String,data: WxPayParamBean) fun getVipPayParamsSuc(payChannel:String,data: WxPayParamBean,enter:String)
fun queryVipOrderSuc(isPay:Boolean) fun queryVipOrderSuc(isPay:Boolean)
fun getUserSuc(data: UserBean) fun getUserSuc(data: UserBean)
......
...@@ -51,8 +51,8 @@ import java.net.URLEncoder ...@@ -51,8 +51,8 @@ import java.net.URLEncoder
* 时间:2022/12/22 14:48 * 时间:2022/12/22 14:48
*/ */
class VipActivity : BaseActivity(), VipView, View.OnClickListener, class VipActivity : BaseActivity(), VipView, View.OnClickListener,
VipAdapter.OnItemClickListener, VipAdapter.OnItemClickListener,
CompoundButton.OnCheckedChangeListener { CompoundButton.OnCheckedChangeListener {
companion object { companion object {
const val IS_DETAIL = "IS_DETAIL"//是否从剧集详情页进入 const val IS_DETAIL = "IS_DETAIL"//是否从剧集详情页进入
...@@ -63,6 +63,8 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener, ...@@ -63,6 +63,8 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
const val ALIPAY = "ALIPAY" const val ALIPAY = "ALIPAY"
const val THIRD_ID = "THIRD_ID" const val THIRD_ID = "THIRD_ID"
const val VEDIO_ID = "VEDIO_ID" const val VEDIO_ID = "VEDIO_ID"
const val ENTER_TYPE_DIALOG = "ENTER_TYPE_DIALOG"
const val ENTER_TYPE_ACTIVITY = "ENTER_TYPE_ACTIVITY"
} }
var timer: CountDownTimerSupport? = null var timer: CountDownTimerSupport? = null
...@@ -214,7 +216,7 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener, ...@@ -214,7 +216,7 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
} }
} }
override fun getVipPayParamsSuc(payChannel: String, paramsBean: WxPayParamBean) { override fun getVipPayParamsSuc(payChannel: String, paramsBean: WxPayParamBean, enter: String) {
if (!isFinishing) { if (!isFinishing) {
if (TextUtils.equals(payChannel, "WEIXIN")) { if (TextUtils.equals(payChannel, "WEIXIN")) {
if (paramsBean.params == null) { if (paramsBean.params == null) {
...@@ -231,17 +233,21 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener, ...@@ -231,17 +233,21 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
if (vipList != null && vipList!!.size > 0) { if (vipList != null && vipList!!.size > 0) {
val vipBean = vipList!![vipAdapter.getPosition()] val vipBean = vipList!![vipAdapter.getPosition()]
val payToModel=vipBean.payToModel val payToModel = vipBean.payToModel
//0 app内部,1.只签约转支付宝浏览器支付 2.带uid转支付宝小程序(暂定只有一个小程序) //0 app内部,1.只签约转支付宝浏览器支付 2.带uid转支付宝小程序(暂定只有一个小程序)
when(payToModel){ when (payToModel) {
0 ->{ 0 -> {
alipay(paramsBean) alipay(paramsBean)
} }
1 ->{ 1 -> {
openAutoAlipay(paramsBean.params.params) openAutoAlipay(paramsBean.params.params)
} }
2 ->{ 2 -> {
openAlipayApp() if (TextUtils.equals(ENTER_TYPE_ACTIVITY, enter)) {
openAlipayApp(vipBean.payToModel2FirstAlipayAppid)
} else {
openAlipayApp(vipBean.payToModel2SecondAlipayAppid)
}
} }
} }
} }
...@@ -280,7 +286,7 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener, ...@@ -280,7 +286,7 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
if (data.expireTime > 0) { if (data.expireTime > 0) {
readyGo(MainActivity::class.java) readyGo(MainActivity::class.java)
val activity = val activity =
ActivityPageManager.getInstance().getActivity(MainActivity::class.java) ActivityPageManager.getInstance().getActivity(MainActivity::class.java)
if (activity != null && activity is MainActivity) { if (activity != null && activity is MainActivity) {
activity.clickTab4Layout() activity.clickTab4Layout()
} }
...@@ -297,7 +303,7 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener, ...@@ -297,7 +303,7 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
when (keyCode) { when (keyCode) {
KeyEvent.KEYCODE_BACK -> { KeyEvent.KEYCODE_BACK -> {
if (UserManager.getInstance().newFlag if (UserManager.getInstance().newFlag
&& vipList != null && vipList!!.size > 0 && vipList != null && vipList!!.size > 0
) { ) {
vipAdapter.setPosition(0) vipAdapter.setPosition(0)
...@@ -326,7 +332,7 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener, ...@@ -326,7 +332,7 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
when (v?.id) { when (v?.id) {
R.id.ic_vip_quit -> { R.id.ic_vip_quit -> {
if (UserManager.getInstance().newFlag && if (UserManager.getInstance().newFlag &&
vipList != null && vipList!!.size > 0 vipList != null && vipList!!.size > 0
) { ) {
vipAdapter.setPosition(0) vipAdapter.setPosition(0)
vipAdapter.notifyDataSetChanged() vipAdapter.notifyDataSetChanged()
...@@ -357,13 +363,15 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener, ...@@ -357,13 +363,15 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
} else { } else {
if (TextUtils.equals(payType, WEIXIN_PAY)) { if (TextUtils.equals(payType, WEIXIN_PAY)) {
vipPresenter.getVipPayParams( vipPresenter.getVipPayParams(
"WEIXIN", "WEIXIN",
vipBean.pid, isAliPayInstalled() vipBean.pid, isAliPayInstalled(),
ENTER_TYPE_ACTIVITY
) )
} else if (TextUtils.equals(payType, ALIPAY)) { } else if (TextUtils.equals(payType, ALIPAY)) {
vipPresenter.getVipPayParams( vipPresenter.getVipPayParams(
"ALIPAY", "ALIPAY",
vipBean.pid, isAliPayInstalled() vipBean.pid, isAliPayInstalled(),
ENTER_TYPE_ACTIVITY
) )
} }
} }
...@@ -404,7 +412,7 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener, ...@@ -404,7 +412,7 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
shimmer_text?.postDelayed({ shimmer_text?.postDelayed({
shimmer_text?.startShimmerAnimation() shimmer_text?.startShimmerAnimation()
breathAnim = breathAnim =
YoYo.with(Techniques.Pulse).duration(700).repeat(-1).playOn(shimmer_text) YoYo.with(Techniques.Pulse).duration(700).repeat(-1).playOn(shimmer_text)
}, 200) }, 200)
ic_vip_quit.setOnClickListener(this) ic_vip_quit.setOnClickListener(this)
...@@ -484,22 +492,22 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener, ...@@ -484,22 +492,22 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
vipPresenter.queryVipOrder(wxParanBean.tid.toString(), false) vipPresenter.queryVipOrder(wxParanBean.tid.toString(), false)
mainHandler.postDelayed( 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) { if (vipList != null && vipList!!.size > 0) {
val vipBean = vipList!![vipAdapter.getPosition()] val vipBean = vipList!![vipAdapter.getPosition()]
// 0.01 // 0.01
if (vipBean.trial != 0) { if (vipBean.trial != 0) {
showPayCancelDialog() showPayCancelDialog()
}
} }
}
}, },
2000 2000
) )
} }
}) })
...@@ -556,13 +564,16 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener, ...@@ -556,13 +564,16 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
val vipBean = vipList!![vipAdapter.getPosition()] val vipBean = vipList!![vipAdapter.getPosition()]
if (TextUtils.equals(payType, WEIXIN_PAY)) { if (TextUtils.equals(payType, WEIXIN_PAY)) {
vipPresenter.getVipPayParams( vipPresenter.getVipPayParams(
"WEIXIN", "WEIXIN",
vipBean.pid, isAliPayInstalled() vipBean.pid, isAliPayInstalled(),
ENTER_TYPE_DIALOG
) )
} else if (TextUtils.equals(payType, ALIPAY)) { } else if (TextUtils.equals(payType, ALIPAY)) {
vipPresenter.getVipPayParams( vipPresenter.getVipPayParams(
"ALIPAY", "ALIPAY",
vipBean.pid, isAliPayInstalled() vipBean.pid, isAliPayInstalled(),
ENTER_TYPE_DIALOG
) )
} }
} else { } else {
...@@ -609,13 +620,15 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener, ...@@ -609,13 +620,15 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
R.id.tv_agreement_next -> { R.id.tv_agreement_next -> {
if (TextUtils.equals(payType, WEIXIN_PAY)) { if (TextUtils.equals(payType, WEIXIN_PAY)) {
vipPresenter.getVipPayParams( vipPresenter.getVipPayParams(
"WEIXIN", "WEIXIN",
vipBean.pid, isAliPayInstalled() vipBean.pid, isAliPayInstalled(),
ENTER_TYPE_ACTIVITY
) )
} else if (TextUtils.equals(payType, ALIPAY)) { } else if (TextUtils.equals(payType, ALIPAY)) {
vipPresenter.getVipPayParams( vipPresenter.getVipPayParams(
"ALIPAY", "ALIPAY",
vipBean.pid, isAliPayInstalled() vipBean.pid, isAliPayInstalled(),
ENTER_TYPE_ACTIVITY
) )
} }
...@@ -624,10 +637,10 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener, ...@@ -624,10 +637,10 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
} }
}) })
ruleAgreementDialog!!.setText( ruleAgreementDialog!!.setText(
vipBean.remarks, vipBean.remarks,
vipBean.trialFirstDay, vipBean.trialFirstDay,
vipBean.price, vipBean.price,
vipBean.title vipBean.title
) )
ruleAgreementDialog!!.show() ruleAgreementDialog!!.show()
} else { } else {
...@@ -658,13 +671,15 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener, ...@@ -658,13 +671,15 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
} else { } else {
if (TextUtils.equals(payType, WEIXIN_PAY)) { if (TextUtils.equals(payType, WEIXIN_PAY)) {
vipPresenter.getVipPayParams( vipPresenter.getVipPayParams(
"WEIXIN", "WEIXIN",
vipBean.pid, isAliPayInstalled() vipBean.pid, isAliPayInstalled(),
ENTER_TYPE_ACTIVITY
) )
} else if (TextUtils.equals(payType, ALIPAY)) { } else if (TextUtils.equals(payType, ALIPAY)) {
vipPresenter.getVipPayParams( vipPresenter.getVipPayParams(
"ALIPAY", "ALIPAY",
vipBean.pid, isAliPayInstalled() vipBean.pid, isAliPayInstalled(),
ENTER_TYPE_ACTIVITY
) )
} }
} }
...@@ -687,7 +702,7 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener, ...@@ -687,7 +702,7 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
private fun setBanner(data: List<VedioBean>) { private fun setBanner(data: List<VedioBean>) {
mainHandler.postDelayed({ mainHandler.postDelayed({
val scrollToBottomAnimator = val scrollToBottomAnimator =
ValueAnimator.ofInt(0, nsv.getChildAt(0).height - nsv.height) ValueAnimator.ofInt(0, nsv.getChildAt(0).height - nsv.height)
scrollToBottomAnimator.addUpdateListener { animator -> scrollToBottomAnimator.addUpdateListener { animator ->
val value = animator.animatedValue as Int val value = animator.animatedValue as Int
nsv.scrollTo(0, value) nsv.scrollTo(0, value)
...@@ -709,23 +724,23 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener, ...@@ -709,23 +724,23 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
val adapter = VipBannerAdapter(data) val adapter = VipBannerAdapter(data)
// 绑定生命周期 // 绑定生命周期
vip_banner.addBannerLifecycleObserver(this) vip_banner.addBannerLifecycleObserver(this)
.setBannerGalleryEffect(80, 15, 0.8f) .setBannerGalleryEffect(80, 15, 0.8f)
.setAdapter(adapter) .setAdapter(adapter)
.addOnPageChangeListener(object : OnPageChangeListener { .addOnPageChangeListener(object : OnPageChangeListener {
override fun onPageScrolled( override fun onPageScrolled(
position: Int, position: Int,
positionOffset: Float, positionOffset: Float,
positionOffsetPixels: Int positionOffsetPixels: Int
) { ) {
} }
override fun onPageSelected(position: Int) { override fun onPageSelected(position: Int) {
GlideUtils.loadBlurImageView(mContext, data[position].coverImage, iv_blur) GlideUtils.loadBlurImageView(mContext, data[position].coverImage, iv_blur)
tv_banner_title.text = String.format("《%1s》", data[position].title) 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) GlideUtils.loadBlurImageView(mContext, data[0].coverImage, iv_blur)
tv_banner_title.text = String.format("《%1s》", data[0].title) tv_banner_title.text = String.format("《%1s》", data[0].title)
} }
...@@ -739,12 +754,13 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener, ...@@ -739,12 +754,13 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
vipPresenter.getVipPayParams( vipPresenter.getVipPayParams(
"ALIPAY", "ALIPAY",
vipBean.pid, isAliPayInstalled() vipBean.pid, isAliPayInstalled(),
ENTER_TYPE_DIALOG
) )
} }
}) })
.show() .show()
} }
fun startTimer() { fun startTimer() {
...@@ -775,15 +791,16 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener, ...@@ -775,15 +791,16 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
/** /**
* 跳转支付宝小程序 * 跳转支付宝小程序
*/ */
private fun openAlipayApp() { private fun openAlipayApp(alipayAppId: String) {
AppConfig.enterAlipay = true AppConfig.enterAlipay = true
try { try {
val alipayAppId = "2021004157617228" val alipayAppId = "2021004157617228"
val path = "app_uid=" + UserManager.getInstance().userID+"&package_app="+Constant.MINTS_PKG_NAME//这里是传的参数 val path =
"app_uid=" + UserManager.getInstance().userID + "&package_app=" + Constant.MINTS_PKG_NAME//这里是传的参数
val link = URLEncoder.encode(path, "UTF-8")//这里是encode传的参数 val link = URLEncoder.encode(path, "UTF-8")//这里是encode传的参数
val url = val url =
// "alipays://platformapi/startapp?appId=2021004129666486&page=pages/loading&query=" + link // "alipays://platformapi/startapp?appId=2021004129666486&page=pages/loading&query=" + link
"alipays://platformapi/startapp?appId=" + alipayAppId + "&page=pages/loading&query=" + link "alipays://platformapi/startapp?appId=" + alipayAppId + "&page=pages/loading&query=" + link
val uri = Uri.parse(url) // url为你要链接的地址 val uri = Uri.parse(url) // url为你要链接的地址
val intent = Intent(Intent.ACTION_VIEW, uri) val intent = Intent(Intent.ACTION_VIEW, uri)
startActivity(intent) startActivity(intent)
...@@ -799,8 +816,10 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener, ...@@ -799,8 +816,10 @@ class VipActivity : BaseActivity(), VipView, View.OnClickListener,
val api: IWXAPI = WXAPIFactory.createWXAPI(context, appId) val api: IWXAPI = WXAPIFactory.createWXAPI(context, appId)
val req = WXLaunchMiniProgram.Req() val req = WXLaunchMiniProgram.Req()
req.userName = "gh_439c32026e1b" // 填小程序原始id req.userName = "gh_439c32026e1b" // 填小程序原始id
req.path = "/pages/loading?testApp1=mcg1&testApp2=mcg2" ////拉起小程序页面的可带参路径,不填默认拉起小程序首页,对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar"。 req.path =
req.miniprogramType = WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE // 可选打开 开发版,体验版和正式版 "/pages/loading?testApp1=mcg1&testApp2=mcg2" ////拉起小程序页面的可带参路径,不填默认拉起小程序首页,对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar"。
req.miniprogramType =
WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE // 可选打开 开发版,体验版和正式版
api.sendReq(req) api.sendReq(req)
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
......
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