From 718f31c92e2029d05260810435a2c70cef6e6ce5 Mon Sep 17 00:00:00 2001 From: lmw <125975490@qq.com> Date: 星期四, 24 四月 2025 10:45:55 +0800 Subject: [PATCH] save --- app/src/main/java/com/sinata/xqmuse/ui/mine/VipActivity.kt | 88 +++++++++++++++++++++++++++++++++++++++---- 1 files changed, 79 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/sinata/xqmuse/ui/mine/VipActivity.kt b/app/src/main/java/com/sinata/xqmuse/ui/mine/VipActivity.kt index d1d61a4..153629f 100644 --- a/app/src/main/java/com/sinata/xqmuse/ui/mine/VipActivity.kt +++ b/app/src/main/java/com/sinata/xqmuse/ui/mine/VipActivity.kt @@ -3,44 +3,70 @@ import android.webkit.WebChromeClient import android.webkit.WebSettings import android.webkit.WebViewClient +import androidx.core.os.bundleOf import androidx.recyclerview.widget.GridLayoutManager import cn.sinata.xldutils.gone +import cn.sinata.xldutils.utils.showAllowingStateLoss import com.sinata.xqmuse.R +import com.sinata.xqmuse.dialog.BuyRuleDialog +import com.sinata.xqmuse.dialog.PayDialog import com.sinata.xqmuse.network.HttpManager import com.sinata.xqmuse.network.request -import com.sinata.xqmuse.ui.H5Activity import com.sinata.xqmuse.ui.TransparentStatusBarActivity import com.sinata.xqmuse.ui.mine.adapter.VipPriceAdapter +import com.sinata.xqmuse.utils.Const +import com.sinata.xqmuse.utils.event.EmptyEvent +import com.sinata.xqmuse.utils.interfaces.StringCallback +import com.sinata.xqmuse.utils.pay.PayListener +import com.sinata.xqmuse.utils.pay.PayUtil import kotlinx.android.synthetic.main.activity_vip.* +import org.greenrobot.eventbus.EventBus import org.jetbrains.anko.backgroundResource -import org.jetbrains.anko.startActivityForResult +import org.jetbrains.anko.browse import org.jetbrains.anko.toast -class VipActivity : TransparentStatusBarActivity() { +class VipActivity : TransparentStatusBarActivity(), PayListener { override fun setContentView() = R.layout.activity_vip private val price = arrayListOf<Double>() private val adapter = VipPriceAdapter(price) + private var orderId = "" override fun initClick() { iv_back.setOnClickListener { finish() } - adapter.setOnItemClickListener { view, position -> + adapter.setOnItemClickListener { _, position -> adapter.checked = position adapter.notifyDataSetChanged() } tv_rule.setOnClickListener { HttpManager.getVipContent(2).request(this){ _, data-> - data?.let { - startActivityForResult<H5Activity>(1,"title" to "会员用户协议","url" to "","showClose" to true) + val buyRuleDialog = BuyRuleDialog() + buyRuleDialog.arguments = bundleOf("rule" to data,"title" to "会员用户协议") + buyRuleDialog.callback = object :StringCallback{ + override fun onResult(rst: String) { + cb_rule.isChecked = rst == "ok" + } } + buyRuleDialog.showAllowingStateLoss(supportFragmentManager,"rule") } } tv_action.setOnClickListener { if (cb_rule.isChecked){ - + PayDialog.show(supportFragmentManager,object :StringCallback{ + override fun onResult(rst: String) { + HttpManager.placeOrder(3,rst.toInt(),2,price[adapter.checked],null,null,adapter.checked+1 ) + .request(this@VipActivity){_,data-> + orderId = data?.orderId?:"" + if (rst == "1") + data?.jumpToWx(this@VipActivity) + else + browse(data?.qrcodeUrl?:"") + } + } + },enableBalance = false) }else - toast("请阅读并同意《》") + toast("请阅读并同意《会员用户协议》") } } @@ -60,6 +86,7 @@ settings.layoutAlgorithm = WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING webView.webChromeClient = object : WebChromeClient() {} webView.webViewClient = object : WebViewClient() {} + PayUtil.addPayListener(this) showVipInfo() getPrice() getH5() @@ -70,10 +97,12 @@ data?.apply { tv_vip.text = if (isVip == 2){ bg_vip.backgroundResource = R.mipmap.no_vip + tv_describe.text = "升级为会员,解锁会员专属体验" "你还未开通会员服务" } else{ bg_vip.backgroundResource = R.mipmap.bg_vip - "${vipExpireTime.substring(0,10)}到期" + tv_describe.text = "您将享受所有会员专享音频,尽情畅游泉疗愈世界" + "${vipExpireTime?.substring(0,10)}到期" } } } @@ -105,4 +134,45 @@ } } + private fun checkPayStatus(){ + if (!orderId.isNullOrEmpty()){ + HttpManager.queryPayment(orderId).request(this){_,data-> + when(data){ + "pending"->{ + toast("未查询到支付结果,如已付款请忽略") + } + "succeeded"->{ + toast("支付成功") + onPaySuccess() + } + "failed"->{ + toast("支付失败") + } + } + } + orderId = "" + } + } + + override fun onDestroy() { + super.onDestroy() + PayUtil.unregisterApp() + PayUtil.removePayListener(this) + } + + override fun onPaySuccess() { + showVipInfo() + EventBus.getDefault().post(EmptyEvent(Const.EventCode.USER_INFO_CHANGED)) + } + + override fun onPayCancel() { + } + + override fun onPayError(msg: String) { + } + + override fun onResume() { + super.onResume() + checkPayStatus() + } } -- Gitblit v1.7.1